- Scaling 16px base pour ultrawide 3440x1440 - Bar: CPU/RAM/GPU visible, media single player (skip playerctld), network tooltip LAN/WAN IPv4 - Volume: class module pour sizing cohérent - Battery: désactivé (PC fixe) - Clock: tooltip calendrier + uptime - BrainPower: panel enrichi (focus, session, intentions, todos, repos git, derniers commits) - App: BrainPower sur moniteur principal uniquement - Heartbeat: Layer.TOP pour compatibilité COSMIC
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import AstalNetwork from "gi://AstalNetwork"
|
|
import { createBinding } from "ags"
|
|
import { exec } from "ags/process"
|
|
|
|
function getIPs(): string {
|
|
try {
|
|
const lan = exec("bash -c \"hostname -I | awk '{print $1}'\"").trim()
|
|
const wan = exec("bash -c \"curl -4 -s --max-time 2 ifconfig.me\"").trim()
|
|
return `LAN: ${lan || "?"}\nWAN: ${wan || "?"}`
|
|
} catch {
|
|
return "IPs unavailable"
|
|
}
|
|
}
|
|
|
|
export default function Network() {
|
|
const net = AstalNetwork.get_default()
|
|
|
|
const text = createBinding(net, "primary")((type: AstalNetwork.Primary) => {
|
|
if (type === AstalNetwork.Primary.WIFI) {
|
|
const wifi = net.wifi
|
|
if (!wifi) return " offline"
|
|
const ssid = wifi.ssid || "wifi"
|
|
const strength = wifi.strength
|
|
let icon = ""
|
|
if (strength > 80) icon = ""
|
|
else if (strength > 60) icon = ""
|
|
else if (strength > 40) icon = ""
|
|
else if (strength > 20) icon = ""
|
|
return `${icon} ${ssid}`
|
|
}
|
|
if (type === AstalNetwork.Primary.WIRED) return " wired"
|
|
return " offline"
|
|
})
|
|
|
|
const cls = createBinding(net, "primary")((type: AstalNetwork.Primary) => {
|
|
if (type === AstalNetwork.Primary.WIFI) return "network module wifi"
|
|
if (type === AstalNetwork.Primary.WIRED) return "network module wired"
|
|
return "network module disconnected"
|
|
})
|
|
|
|
return (
|
|
<eventbox
|
|
onHover={(self) => {
|
|
self.tooltipText = getIPs()
|
|
}}
|
|
>
|
|
<label class={cls} label={text} hasTooltip />
|
|
</eventbox>
|
|
)
|
|
}
|