Files
dotfiles/quickshell/services/Modems.qml
T
2026-11-17 18:15:16 +07:00

60 lines
2.2 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
Singleton {
id: root
property string backend: "unknown"
property var devices: []
property string error: ""
readonly property bool present: devices.length > 0
property bool busy: false
property bool actionBusy: false
property string actionError: ""
property string pendingId: ""
property string pendingAction: ""
function setEnabled(modemId, enabled) {
if (actionBusy || !/^[0-9]{1,5}$/.test(String(modemId))) return;
pendingId = String(modemId);
pendingAction = enabled ? "enable" : "disable";
actionError = "";
actionBusy = true;
actionProcess.running = true;
}
Process {
id: actionProcess
command: ["python3", Qt.resolvedUrl("../backend/modem_control.py").toString().replace(/^file:\/\//, ""), root.pendingId, root.pendingAction]
stdout: StdioCollector {
onStreamFinished: {
try {
const response = JSON.parse(text);
root.actionError = response.ok ? "" : response.error;
} catch (e) { root.actionError = String(e); }
}
}
onExited: { root.actionBusy = false; root.refresh(); }
}
function refresh() {
if (!busy) { busy = true; probe.running = true; }
}
Process {
id: probe
command: ["python3", Qt.resolvedUrl("../backend/modems.py").toString().replace(/^file:\/\//, "")]
stdout: StdioCollector {
onStreamFinished: {
try {
const result = JSON.parse(text);
root.backend = result.backend;
root.devices = result.modems || [];
root.error = result.error || "";
} catch (e) { root.backend = "error"; root.error = String(e); }
}
}
onExited: root.busy = false
}
// ModemManager can appear after boot or USB hotplug. A modest interval
// avoids a permanent high-frequency poll on battery-powered devices.
Timer { interval: 15000; repeat: true; running: true; triggeredOnStart: true; onTriggered: root.refresh() }
}