mirror of
https://github.com/danbulant/dots-hyprland
synced 2026-05-19 04:08:48 +00:00
Netwok bandwidth tracker
This commit is contained in:
parent
b4533d1dea
commit
cedf9ee93a
3 changed files with 79 additions and 1 deletions
|
|
@ -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: 'network-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,
|
||||
|
||||
]
|
||||
|
|
|
|||
39
.config/ags/scripts/network_scripts/network_bandwidth.py
Executable file
39
.config/ags/scripts/network_scripts/network_bandwidth.py
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/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 = 1024
|
||||
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")
|
||||
|
||||
|
|
@ -19,11 +19,16 @@ $sidebar_chat_textboxareaColor: mix($onSurfaceVariant, $surfaceVariant, 40%);
|
|||
@include elevation-border;
|
||||
@include elevation2;
|
||||
border-radius: $rounding_large - $elevation_margin + 0.068rem;
|
||||
min-width: 27.818rem;
|
||||
min-width: 57.818rem;
|
||||
background-color: $background;
|
||||
padding: 1.023rem;
|
||||
}
|
||||
|
||||
.network-bandwidth {
|
||||
min-width: 6.300rem;
|
||||
padding-left: 1.000rem;
|
||||
}
|
||||
|
||||
.sidebar-group {
|
||||
@include normal-rounding;
|
||||
@include group-padding;
|
||||
|
|
|
|||
Loading…
Reference in a new issue