diff options
Diffstat (limited to 'desktop')
| -rw-r--r-- | desktop/modules/network/NetworkModule.qml | 110 | ||||
| -rw-r--r-- | desktop/modules/network/NetworkPage.qml | 66 | ||||
| -rw-r--r-- | desktop/modules/network/NetworkTile.qml | 50 | ||||
| -rw-r--r-- | desktop/shell.qml | 2 |
4 files changed, 228 insertions, 0 deletions
diff --git a/desktop/modules/network/NetworkModule.qml b/desktop/modules/network/NetworkModule.qml new file mode 100644 index 0000000..d14853f --- /dev/null +++ b/desktop/modules/network/NetworkModule.qml @@ -0,0 +1,110 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import Quickshell +import Quickshell.Networking +import Quickshell.Io +import QtQuick +import "../.." + +// Always active: the backends push and there is no poll to gate, so the +// state the tile shows is live from launch. Referencing Networking here is +// also what instantiates the singleton at shell start. +Module { + id: mod + + name: "network" + label: "Network" + alwaysActive: true + + // .values on the device ObjectModel; empty until the backend is ready, + // roughly two seconds in. Bindings repaint when it arrives. + readonly property var devices: Networking.devices ? Networking.devices.values : [] + readonly property var wiredDevices: devices.filter(d => d.type === DeviceType.Wired) + readonly property var wifiDevice: devices.find(d => d.type === DeviceType.Wifi) ?? null + + readonly property bool wiredUp: wiredDevices.some(d => d.connected) + readonly property bool wifiUp: wifiDevice ? wifiDevice.connected : false + readonly property bool wifiOn: Networking.wifiEnabled + readonly property var wifiNetworks: wifiDevice && wifiDevice.networks ? wifiDevice.networks.values : [] + + readonly property string wifiSsid: { + const n = wifiNetworks.find(x => x.connected); + return n ? n.name : ""; + } + readonly property string wiredName: { + const d = wiredDevices.find(x => x.connected); + return d ? d.name : ""; + } + + // Connected first, then known, then strongest. Kept here so both the + // tile and the page read the same order. + readonly property var wifiNetworksSorted: { + const arr = wifiNetworks.slice(); + arr.sort((a, b) => + ((b.connected ? 1 : 0) - (a.connected ? 1 : 0)) || + ((b.known ? 1 : 0) - (a.known ? 1 : 0)) || + ((b.signalStrength ?? 0) - (a.signalStrength ?? 0))); + 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 network a connect is pending on, so connectionFailed can be caught. + property var pendingNetwork: null + property string error: "" + + function connect(net) { + mod.pendingNetwork = net; + mod.error = ""; + net.connect(); + } + + function connectWithPsk(net, psk) { + mod.pendingNetwork = net; + mod.error = ""; + net.connectWithPsk(psk); + } + + function disconnectNetwork(net) { if (net) net.disconnect(); } + function forget(net) { if (net) net.forget(); } + + // A failure after the drawer closed would otherwise go unseen, so it also + // raises a notification. Same cached-Process shape as VmModule. + function notify(title, body) { + notifyProc.command = ["notify-send", "--app-name=network", + "--urgency=critical", "--icon=error", title, body]; + notifyProc.running = false; + notifyProc.running = true; + } + + property Process notifyProc: Process {} + + property Connections conn: Connections { + target: mod.pendingNetwork + function onConnectionFailed(reason) { + mod.error = "Connection failed: " + reason; + mod.notify("Network", mod.error); + mod.pendingNetwork = null; + } + } + + tileContent: Component { NetworkTile { net: mod } } + + page: Component { + Page { + title: "Network" + NetworkPage { width: parent.width; net: mod } + } + } +} diff --git a/desktop/modules/network/NetworkPage.qml b/desktop/modules/network/NetworkPage.qml new file mode 100644 index 0000000..0c79ef6 --- /dev/null +++ b/desktop/modules/network/NetworkPage.qml @@ -0,0 +1,66 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import Quickshell.Networking +import QtQuick +import "../.." + +// The wired half. Sibling of NetworkPage's wifi half, added in Task 2. +Column { + id: page + + required property var net + signal back + + spacing: 14 + + function stateLabel(s) { + return s === ConnectionState.Connected ? "connected" + : s === ConnectionState.Connecting ? "connecting" + : s === ConnectionState.Disconnecting ? "disconnecting" + : "disconnected"; + } + + Text { + visible: page.net.wiredDevices.length > 0 + text: "Wired" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true } + color: Theme.subtext + } + + Repeater { + model: page.net.wiredDevices + + Rectangle { + required property var modelData + + width: page.width + implicitHeight: wiredText.implicitHeight + 16 + radius: 8 + color: Qt.alpha(Theme.surface, 0.35) + + Text { + id: wiredText + anchors { left: parent.left; leftMargin: 10; verticalCenter: parent.verticalCenter } + text: modelData.name + " " + page.stateLabel(modelData.state) + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 } + color: modelData.connected ? Theme.text : Theme.subtext + } + + Button { + anchors { right: parent.right; rightMargin: 8; verticalCenter: parent.verticalCenter } + visible: modelData.connected + text: "Disconnect" + onClicked: page.net.disconnectNetwork(modelData) + } + } + } +} diff --git a/desktop/modules/network/NetworkTile.qml b/desktop/modules/network/NetworkTile.qml new file mode 100644 index 0000000..a9e5dd0 --- /dev/null +++ b/desktop/modules/network/NetworkTile.qml @@ -0,0 +1,50 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +import QtQuick +import "../.." + +// The state line under the tile label. One line per active link: the API +// exposes no route metric, so when both wired and wifi are up the tile shows +// both rather than guessing which one carries traffic. +Column { + required property var net + + width: parent ? parent.width : implicitWidth + spacing: 2 + + Text { + width: parent.width + elide: Text.ElideRight + visible: net.wiredUp + text: net.wiredName + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } + color: Theme.text + } + + Text { + width: parent.width + elide: Text.ElideRight + visible: net.wifiUp + text: net.wifiSsid + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } + color: Theme.text + } + + Text { + width: parent.width + elide: Text.ElideRight + visible: !net.wiredUp && !net.wifiUp + text: net.wifiOn ? "Disconnected" : "Off" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } + color: Theme.subtext + } +} diff --git a/desktop/shell.qml b/desktop/shell.qml index 74c1ec2..5f9640d 100644 --- a/desktop/shell.qml +++ b/desktop/shell.qml @@ -14,6 +14,7 @@ import Quickshell.Io import Quickshell.Wayland import "modules/appearance" import "modules/mail" +import "modules/network" import "modules/sound" import "modules/vm" @@ -34,6 +35,7 @@ ShellRoot { id: drawer modules: [ SoundModule {}, + NetworkModule {}, MailModule {}, AppearanceModule {}, VmModule {}, |
