Merge branch 'master' into nix/update

This commit is contained in:
orangc
2024-10-30 08:41:08 +03:00
committed by GitHub
4 changed files with 87 additions and 27 deletions

View File

@@ -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) : '',
});
},
),

View File

@@ -178,7 +178,43 @@ const renderWAPs = (
Widget.Revealer({
vpack: 'start',
reveal_child: ap.bssid !== connecting.value && ap.active,
child: Widget.Button({
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 disconnecting "${ap.ssid}": Connection ID not found`,
);
return;
}
Utils.execAsync(
`nmcli connection down ${connectionId} "${ap.ssid}"`,
)
.then(() => (connecting.value = ''))
.catch((err) => {
connecting.value = '';
console.error(
`Error while disconnecting "${ap.ssid}": ${err}`,
);
});
});
});
},
}),
Widget.Button({
tooltip_text: 'Delete/Forget Network',
class_name: 'menu-icon-button network disconnect',
on_primary_click: () => {
@@ -194,11 +230,15 @@ const renderWAPs = (
return;
}
Utils.execAsync(`nmcli connection delete ${connectionId} "${ap.ssid}"`)
Utils.execAsync(
`nmcli connection delete ${connectionId} "${ap.ssid}"`,
)
.then(() => (connecting.value = ''))
.catch((err) => {
connecting.value = '';
console.error(`Error while forgetting "${ap.ssid}": ${err}`);
console.error(
`Error while forgetting "${ap.ssid}": ${err}`,
);
});
});
});
@@ -208,6 +248,8 @@ const renderWAPs = (
label: '󰚃',
}),
}),
],
}),
}),
],
});

View File

@@ -897,6 +897,7 @@ const options = mkOptions(OPTIONS, {
},
network: {
truncation: opt(true),
showWifiInfo: opt(false),
truncation_size: opt(7),
label: opt(true),
rightClick: opt(''),

View File

@@ -497,6 +497,11 @@ export const BarSettings = (): Scrollable<Gtk.Widget, Gtk.Widget> => {
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',