forked from Shinonome/dots-hyprland
Add network bandwidth tracker to sideright (wifinetworks) (#1112)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import App from 'resource:///com/github/Aylur/ags/app.js';
|
||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||
import Network from "resource:///com/github/Aylur/ags/service/network.js";
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||
@@ -56,6 +57,28 @@ const WifiNetwork = (accessPoint) => {
|
||||
})
|
||||
}
|
||||
|
||||
const NetResource = (icon, command) => {
|
||||
const resourceLabel = Label({
|
||||
className: `txt-smaller txt-subtext`,
|
||||
});
|
||||
const widget = Button({
|
||||
child: Box({
|
||||
hpack: 'start',
|
||||
className: `spacing-h-4`,
|
||||
children: [
|
||||
MaterialIcon(icon, 'very-small'),
|
||||
resourceLabel,
|
||||
],
|
||||
setup: (self) => self.poll(2000, () => execAsync(['bash', '-c', command])
|
||||
.then((output) => {
|
||||
resourceLabel.label = output;
|
||||
}).catch(print))
|
||||
,
|
||||
})
|
||||
});
|
||||
return widget;
|
||||
}
|
||||
|
||||
const CurrentNetwork = () => {
|
||||
let authLock = false;
|
||||
// console.log(Network.wifi);
|
||||
@@ -81,6 +104,16 @@ const CurrentNetwork = () => {
|
||||
}),
|
||||
]
|
||||
});
|
||||
const networkBandwidth = Box({
|
||||
vertical: true,
|
||||
hexpand: true,
|
||||
hpack: 'center',
|
||||
className: 'sidebar-wifinetworks-bandwidth',
|
||||
children: [
|
||||
NetResource('arrow_warm_up', `${App.configDir}/scripts/network_scripts/network_bandwidth.py sent`),
|
||||
NetResource('arrow_cool_down', `${App.configDir}/scripts/network_scripts/network_bandwidth.py recv`),
|
||||
]
|
||||
});
|
||||
const networkStatus = Box({
|
||||
children: [Label({
|
||||
vpack: 'center',
|
||||
@@ -136,6 +169,7 @@ const CurrentNetwork = () => {
|
||||
children: [
|
||||
MaterialIcon('language', 'hugerass'),
|
||||
networkName,
|
||||
networkBandwidth,
|
||||
networkStatus,
|
||||
|
||||
]
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env -S\_/bin/sh\_-xc\_"source\_\$(eval\_echo\_\$ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate&&exec\_python\_-E\_"\$0"\_"\$@""
|
||||
|
||||
|
||||
from time import sleep
|
||||
import sys
|
||||
import psutil
|
||||
|
||||
try:
|
||||
direction = sys.argv[1]
|
||||
except IndexError:
|
||||
direction = "recv"
|
||||
|
||||
init_bytes = final_bytes = 0
|
||||
|
||||
match direction:
|
||||
case "recv":
|
||||
init_bytes = psutil.net_io_counters().bytes_recv
|
||||
sleep(1)
|
||||
final_bytes = psutil.net_io_counters().bytes_recv
|
||||
|
||||
case "sent":
|
||||
init_bytes = psutil.net_io_counters().bytes_sent
|
||||
sleep(1)
|
||||
final_bytes = psutil.net_io_counters().bytes_sent
|
||||
|
||||
case _:
|
||||
print(f"wrong direction: {direction}")
|
||||
sys.exit()
|
||||
|
||||
i = 0
|
||||
divider = 1000
|
||||
bandwidth = int((final_bytes - init_bytes))
|
||||
units = ["B", "KB", "MB", "GB", "TB", "PB", "EB"]
|
||||
|
||||
while bandwidth >= divider:
|
||||
i += 1
|
||||
bandwidth = bandwidth / divider
|
||||
|
||||
print(f"{bandwidth:.1f}" + units[i] + "/s")
|
||||
|
||||
@@ -976,6 +976,11 @@ $waifu_image_overlay_transparency: 0.7;
|
||||
padding: 0.682rem;
|
||||
}
|
||||
|
||||
.sidebar-wifinetworks-bandwidth {
|
||||
min-width: 6.3rem;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
.sidebar-centermodules-bottombar-button {
|
||||
@include full-rounding;
|
||||
@include element_decel;
|
||||
@@ -996,4 +1001,4 @@ $waifu_image_overlay_transparency: 0.7;
|
||||
|
||||
.sidebar-centermodules-scrollgradient-bottom {
|
||||
background: linear-gradient(to top, $layer1 0%, transparentize($layer1, 1) 1.023rem);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user