extract NetworkService singleton from NetworkModule and NetworkMenu
This commit is contained in:
parent
a7eca009e4
commit
d646d9b0fe
4 changed files with 194 additions and 183 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import "." as M
|
||||
import "../services" as S
|
||||
|
||||
|
|
@ -9,73 +8,7 @@ M.BarSection {
|
|||
spacing: S.Theme.moduleSpacing
|
||||
tooltip: ""
|
||||
|
||||
property string ifname: ""
|
||||
property string essid: ""
|
||||
property string state: "disconnected"
|
||||
property string ipAddr: ""
|
||||
property string signal: ""
|
||||
|
||||
Process {
|
||||
id: proc
|
||||
running: S.Modules.network.enable
|
||||
command: ["sh", "-c", "line=$(nmcli -t -f NAME,TYPE,DEVICE connection show --active 2>/dev/null | head -1); if [ -z \"$line\" ]; then dev=$(nmcli -t -f DEVICE,STATE device 2>/dev/null | grep ':connected' | grep -v ':unmanaged\\|:unavailable\\|:disconnected\\|:connecting' | head -1 | cut -d: -f1); [ -n \"$dev\" ] && line=\"linked:linked:$dev\"; fi; [ -z \"$line\" ] && exit 0; echo \"$line\"; dev=$(echo \"$line\" | cut -d: -f3); ip=$(nmcli -t -f IP4.ADDRESS device show \"$dev\" 2>/dev/null | head -1 | cut -d: -f2); echo \"ip:${ip:-}\"; sig=$(nmcli -t -f GENERAL.SIGNAL device show \"$dev\" 2>/dev/null | head -1 | cut -d: -f2); echo \"sig:${sig:-}\""]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const lines = text.trim().split("\n");
|
||||
if (!lines[0]) {
|
||||
root.state = "disconnected";
|
||||
root.essid = "";
|
||||
root.ifname = "";
|
||||
root.ipAddr = "";
|
||||
root.signal = "";
|
||||
return;
|
||||
}
|
||||
const parts = lines[0].split(":");
|
||||
root.essid = parts[0] || "";
|
||||
root.ifname = parts[2] || "";
|
||||
if ((parts[1] || "").includes("wireless"))
|
||||
root.state = "wifi";
|
||||
else if (parts[0] === "linked")
|
||||
root.state = "linked";
|
||||
else
|
||||
root.state = "eth";
|
||||
// Parse extra info lines
|
||||
root.ipAddr = "";
|
||||
root.signal = "";
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
if (lines[i].startsWith("ip:"))
|
||||
root.ipAddr = lines[i].slice(3);
|
||||
else if (lines[i].startsWith("sig:"))
|
||||
root.signal = lines[i].slice(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Event-driven: re-poll on any network change
|
||||
Process {
|
||||
id: monitor
|
||||
running: S.Modules.network.enable
|
||||
command: ["nmcli", "monitor"]
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: _debounce.restart()
|
||||
}
|
||||
}
|
||||
Timer {
|
||||
id: _debounce
|
||||
interval: 300
|
||||
onTriggered: {
|
||||
proc.running = true;
|
||||
networkMenu.triggerRefresh();
|
||||
}
|
||||
}
|
||||
// Fallback poll
|
||||
Timer {
|
||||
interval: 60000
|
||||
running: S.Modules.network.enable
|
||||
repeat: true
|
||||
onTriggered: proc.running = true
|
||||
}
|
||||
readonly property string state: S.NetworkService.state
|
||||
|
||||
M.BarIcon {
|
||||
icon: {
|
||||
|
|
@ -92,7 +25,7 @@ M.BarSection {
|
|||
}
|
||||
M.BarLabel {
|
||||
visible: root.state === "wifi"
|
||||
label: root.essid
|
||||
label: S.NetworkService.essid
|
||||
color: root.state === "disconnected" ? S.Theme.base08 : root.accentColor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue