Added the ability to enable dynamic network icons for netstat module. (#376)
This commit is contained in:
@@ -231,6 +231,12 @@ export const CustomModuleSettings = (): Scrollable<GtkWidget, Attribute> =>
|
||||
"Name of the network interface to poll.\nHINT: Get list of interfaces with 'cat /proc/net/dev'",
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.netstat.dynamicIcon,
|
||||
title: 'Use Network Icon',
|
||||
subtitle: 'If enabled, shows the current network icon indicators instead of the static icon',
|
||||
type: 'boolean',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.netstat.icon,
|
||||
title: 'Netstat Icon',
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { BarBoxChild, Module } from 'lib/types/bar';
|
||||
import { BarButtonStyles } from 'lib/types/options';
|
||||
import { Bind } from 'lib/types/variable';
|
||||
import { GtkWidget } from 'lib/types/widget';
|
||||
import options from 'options';
|
||||
import Gtk from 'types/@girs/gtk-3.0/gtk-3.0';
|
||||
@@ -12,6 +11,7 @@ const undefinedVar = Variable(undefined);
|
||||
export const module = ({
|
||||
icon,
|
||||
textIcon,
|
||||
useTextIcon = Variable(false).bind('value'),
|
||||
label,
|
||||
tooltipText,
|
||||
boxClass,
|
||||
@@ -21,19 +21,19 @@ export const module = ({
|
||||
labelHook,
|
||||
hook,
|
||||
}: Module): BarBoxChild => {
|
||||
const getIconWidget = (): GtkWidget | undefined => {
|
||||
const getIconWidget = (useTxtIcn: boolean): GtkWidget | undefined => {
|
||||
let iconWidget: Gtk.Widget | undefined;
|
||||
|
||||
if (icon !== undefined) {
|
||||
if (icon !== undefined && !useTxtIcn) {
|
||||
iconWidget = Widget.Icon({
|
||||
class_name: `txt-icon bar-button-icon module-icon ${boxClass}`,
|
||||
icon: icon,
|
||||
}) as unknown as Gtk.Widget;
|
||||
});
|
||||
} else if (textIcon !== undefined) {
|
||||
iconWidget = Widget.Label({
|
||||
class_name: `txt-icon bar-button-icon module-icon ${boxClass}`,
|
||||
label: textIcon,
|
||||
}) as unknown as Gtk.Widget;
|
||||
});
|
||||
}
|
||||
|
||||
return iconWidget;
|
||||
@@ -55,25 +55,25 @@ export const module = ({
|
||||
},
|
||||
),
|
||||
tooltip_text: tooltipText,
|
||||
children: Utils.merge([showLabelBinding], (showLabelBinding): Gtk.Widget[] => {
|
||||
children: Utils.merge([showLabelBinding, useTextIcon], (showLabel, forceTextIcon): Gtk.Widget[] => {
|
||||
const childrenArray: Gtk.Widget[] = [];
|
||||
const iconWidget = getIconWidget();
|
||||
const iconWidget = getIconWidget(forceTextIcon);
|
||||
|
||||
if (iconWidget !== undefined) {
|
||||
childrenArray.push(iconWidget);
|
||||
}
|
||||
|
||||
if (showLabelBinding) {
|
||||
if (showLabel) {
|
||||
childrenArray.push(
|
||||
Widget.Label({
|
||||
class_name: `bar-button-label module-label ${boxClass}`,
|
||||
label: label,
|
||||
setup: labelHook,
|
||||
}) as unknown as Gtk.Widget,
|
||||
}),
|
||||
);
|
||||
}
|
||||
return childrenArray;
|
||||
}) as Bind,
|
||||
}),
|
||||
setup: hook,
|
||||
}),
|
||||
tooltip_text: tooltipText,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const network = await Service.import('network');
|
||||
import options from 'options';
|
||||
import { module } from '../module';
|
||||
import { inputHandler } from 'customModules/utils';
|
||||
@@ -15,6 +16,7 @@ const {
|
||||
labelType,
|
||||
networkInterface,
|
||||
rateUnit,
|
||||
dynamicIcon,
|
||||
icon,
|
||||
round,
|
||||
leftClick,
|
||||
@@ -59,6 +61,13 @@ export const Netstat = (): BarBoxChild => {
|
||||
};
|
||||
|
||||
const netstatModule = module({
|
||||
useTextIcon: dynamicIcon.bind('value').as((useDynamicIcon) => !useDynamicIcon),
|
||||
icon: Utils.merge([network.bind('primary'), network.bind('wifi'), network.bind('wired')], (pmry, wfi, wrd) => {
|
||||
if (pmry === 'wired') {
|
||||
return wrd.icon_name;
|
||||
}
|
||||
return wfi.icon_name;
|
||||
}),
|
||||
textIcon: icon.bind('value'),
|
||||
label: Utils.merge(
|
||||
[networkUsage.bind('value'), labelType.bind('value')],
|
||||
|
||||
Reference in New Issue
Block a user