diff --git a/modules/bar/network/index.ts b/modules/bar/network/index.ts index 056f455..a6176f4 100644 --- a/modules/bar/network/index.ts +++ b/modules/bar/network/index.ts @@ -6,6 +6,15 @@ import { BarBoxChild } from 'lib/types/bar.js'; import Button from 'types/widgets/button.js'; import { Attribute, Child } from 'lib/types/widget.js'; import { runAsyncCommand, throttledScrollHandler } from 'customModules/utils.js'; +import { Wifi } from 'types/service/network.js'; + +const formatFrequency = (frequency: number): string => { + return `${(frequency / 1000).toFixed(2)}MHz`; +}; + +const formatWifiInfo = (wifi: Wifi): string => { + return `Network: ${wifi.ssid === '' ? 'None' : wifi.ssid} \nSignal Strength: ${wifi.strength >= 0 ? wifi.strength : '--'}% \nFrequency: ${wifi.frequency >= 0 ? formatFrequency(wifi.frequency) : '--'}`; +}; const { label: networkLabel, @@ -15,6 +24,7 @@ const { middleClick, scrollDown, scrollUp, + showWifiInfo, } = options.bar.network; const Network = (): BarBoxChild => { @@ -55,8 +65,9 @@ const Network = (): BarBoxChild => { networkLabel.bind('value'), truncation.bind('value'), truncation_size.bind('value'), + showWifiInfo.bind('value'), ], - (pmry, wfi, showLbl, trunc, tSize) => { + (pmry, wfi, showLbl, trunc, tSize, showWfiInfo) => { if (!showLbl) { return Widget.Box(); } @@ -69,6 +80,7 @@ const Network = (): BarBoxChild => { return Widget.Label({ class_name: 'bar-button-label network-label', label: wfi.ssid ? `${trunc ? wfi.ssid.substring(0, tSize) : wfi.ssid}` : '--', + tooltipText: showWfiInfo ? formatWifiInfo(wfi) : '', }); }, ), diff --git a/modules/menus/network/wifi/WirelessAPs.ts b/modules/menus/network/wifi/WirelessAPs.ts index fac891d..20a3f89 100644 --- a/modules/menus/network/wifi/WirelessAPs.ts +++ b/modules/menus/network/wifi/WirelessAPs.ts @@ -178,35 +178,77 @@ const renderWAPs = ( Widget.Revealer({ vpack: 'start', reveal_child: ap.bssid !== connecting.value && ap.active, - child: Widget.Button({ - tooltip_text: 'Delete/Forget Network', - class_name: 'menu-icon-button network disconnect', - on_primary_click: () => { - connecting.value = ap.bssid || ''; - Utils.execAsync('nmcli connection show --active').then(() => { - Utils.execAsync('nmcli connection show --active').then((res) => { - const connectionId = getIdBySsid(ap.ssid || '', res); + child: Widget.Box({ + children: [ + Widget.Button({ + class_name: 'menu-icon-button network disconnect', + child: Widget.Label({ + tooltip_text: 'Disconnect', + class_name: 'menu-icon-button disconnect-network txt-icon', + label: '󱘖', + }), + on_primary_click: () => { + connecting.value = ap.bssid || ''; + Utils.execAsync('nmcli connection show --active').then(() => { + Utils.execAsync('nmcli connection show --active').then((res) => { + const connectionId = getIdBySsid(ap.ssid || '', res); - if (connectionId === undefined) { - console.error( - `Error while forgetting "${ap.ssid}": Connection ID not found`, - ); - return; - } + if (connectionId === undefined) { + console.error( + `Error while disconnecting "${ap.ssid}": Connection ID not found`, + ); + return; + } - Utils.execAsync(`nmcli connection delete ${connectionId} "${ap.ssid}"`) - .then(() => (connecting.value = '')) - .catch((err) => { - connecting.value = ''; - console.error(`Error while forgetting "${ap.ssid}": ${err}`); + Utils.execAsync( + `nmcli connection down ${connectionId} "${ap.ssid}"`, + ) + .then(() => (connecting.value = '')) + .catch((err) => { + connecting.value = ''; + console.error( + `Error while disconnecting "${ap.ssid}": ${err}`, + ); + }); }); - }); - }); - }, - child: Widget.Label({ - class_name: 'txt-icon delete-network', - label: '󰚃', - }), + }); + }, + }), + Widget.Button({ + tooltip_text: 'Delete/Forget Network', + class_name: 'menu-icon-button network disconnect', + on_primary_click: () => { + connecting.value = ap.bssid || ''; + Utils.execAsync('nmcli connection show --active').then(() => { + Utils.execAsync('nmcli connection show --active').then((res) => { + const connectionId = getIdBySsid(ap.ssid || '', res); + + if (connectionId === undefined) { + console.error( + `Error while forgetting "${ap.ssid}": Connection ID not found`, + ); + return; + } + + Utils.execAsync( + `nmcli connection delete ${connectionId} "${ap.ssid}"`, + ) + .then(() => (connecting.value = '')) + .catch((err) => { + connecting.value = ''; + console.error( + `Error while forgetting "${ap.ssid}": ${err}`, + ); + }); + }); + }); + }, + child: Widget.Label({ + class_name: 'txt-icon delete-network', + label: '󰚃', + }), + }), + ], }), }), ], diff --git a/options.ts b/options.ts index f7f1b7d..5f04810 100644 --- a/options.ts +++ b/options.ts @@ -897,6 +897,7 @@ const options = mkOptions(OPTIONS, { }, network: { truncation: opt(true), + showWifiInfo: opt(false), truncation_size: opt(7), label: opt(true), rightClick: opt(''), diff --git a/widget/settings/pages/config/bar/index.ts b/widget/settings/pages/config/bar/index.ts index 0165cda..25e67fc 100644 --- a/widget/settings/pages/config/bar/index.ts +++ b/widget/settings/pages/config/bar/index.ts @@ -497,6 +497,11 @@ export const BarSettings = (): Scrollable => { title: 'Show Network Name', type: 'boolean', }), + Option({ + opt: options.bar.network.showWifiInfo, + title: 'Show Wifi Info On Hover', + type: 'boolean', + }), Option({ opt: options.bar.network.truncation, title: 'Truncate Network Name',