diff options
Diffstat (limited to 'desktop/modules/network/NetworkModule.qml')
| -rw-r--r-- | desktop/modules/network/NetworkModule.qml | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/desktop/modules/network/NetworkModule.qml b/desktop/modules/network/NetworkModule.qml index 6ff98b5..0310475 100644 --- a/desktop/modules/network/NetworkModule.qml +++ b/desktop/modules/network/NetworkModule.qml @@ -45,6 +45,17 @@ Module { return d ? d.name : ""; } + // Local IPs, keyed by interface. The Networking API exposes only the MAC + // (NetworkDevice.address), so this is the module's one shell-out. It is + // refreshed when a link comes up and on a slow timer while one is up, to + // catch a DHCP renew. `ip -j` is JSON, so no text parsing. + property var ipByIface: ({}) + function ipFor(iface) { return ipByIface[iface] ?? ""; } + function refreshIps() { + ipProc.running = false; + ipProc.running = true; + } + // Connected first, then known, then strongest. Kept here so both the // tile and the page read the same order. readonly property var wifiNetworksSorted: { @@ -56,9 +67,9 @@ Module { return arr; } - // The icon follows the active link, live, with no contract change: the - // drawer reads this property like any other. - icon: mod.wiredUp ? "\uf796" : (mod.wifiUp ? "\uf1eb" : "\uf05e") + // The tile is a globe: the wired/wifi distinction belongs to the page's + // section headers, not the tile. + icon: "\uf0ac" // Active while any link is up. active: mod.wiredUp || mod.wifiUp @@ -93,6 +104,30 @@ Module { property Process notifyProc: Process {} + property Process ipProc: Process { + command: ["ip", "-j", "-4", "addr", "show"] + stdout: StdioCollector { + onStreamFinished: { + const map = {}; + try { + for (const iface of JSON.parse(text)) { + const a = (iface.addr_info ?? []).find(x => x.family === "inet"); + if (a) map[iface.ifname] = a.local; + } + } catch (e) {} + mod.ipByIface = map; + } + } + } + + // Only poll while something is actually up. + property Timer ipTimer: Timer { + interval: 15000 + repeat: true + running: mod.wiredUp || mod.wifiUp + onTriggered: mod.refreshIps() + } + property Connections conn: Connections { target: mod.pendingNetwork function onConnectionFailed(reason) { @@ -106,6 +141,10 @@ Module { } } + onWiredUpChanged: mod.refreshIps() + onWifiUpChanged: mod.refreshIps() + Component.onCompleted: mod.refreshIps() + tileContent: Component { NetworkTile { net: mod } } page: Component { |
