46 lines
1.7 KiB
QML
46 lines
1.7 KiB
QML
pragma Singleton
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
|
|
Singleton {
|
|
id: root
|
|
property var profiles: []
|
|
property string error: ""
|
|
property bool busy: false
|
|
property string action: ""
|
|
property string target: ""
|
|
property string apn: ""
|
|
function refresh() { if (!busy && !probe.running) probe.running = true }
|
|
function perform(operation, value, accessPoint) {
|
|
if (busy || !["create", "activate", "deactivate", "delete"].includes(operation)) return;
|
|
action = operation; target = value; apn = accessPoint || "";
|
|
error = ""; busy = true; actionProcess.running = true;
|
|
}
|
|
Process {
|
|
id: probe
|
|
command: ["python3", Qt.resolvedUrl("../backend/mobile_connections.py").toString().replace(/^file:\/\//, ""), "list"]
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
try {
|
|
const result = JSON.parse(text);
|
|
root.profiles = result.profiles || [];
|
|
root.error = result.error || "";
|
|
} catch (e) { root.error = String(e) }
|
|
}
|
|
}
|
|
}
|
|
Process {
|
|
id: actionProcess
|
|
command: ["python3", Qt.resolvedUrl("../backend/mobile_connections.py").toString().replace(/^file:\/\//, ""), root.action, root.target].concat(root.action === "create" ? [root.apn] : [])
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
try { const result = JSON.parse(text); root.error = result.error || "" }
|
|
catch (e) { root.error = String(e) }
|
|
}
|
|
}
|
|
onExited: { root.busy = false; root.refresh() }
|
|
}
|
|
Timer { interval: 20000; repeat: true; running: true; triggeredOnStart: true; onTriggered: root.refresh() }
|
|
}
|