pragma Singleton import QtQuick import Quickshell import "../core" Singleton { id: root property string helper: "helpers/system.py" property var state: ({}) property string error: "" readonly property bool busy: job.running // A user action is in flight. Controls lock on this, not on busy: locking // them for every background status poll flickered them every five seconds. readonly property bool acting: (job.running && job.request.op === "action") || queued !== null property var queued: null readonly property var features: { if (!ConfigService.ready) return []; if (ShellState.controlCenterOpen || ShellState.notchOpen) return ConfigService.data.controlCenter.modules.filter(m => m.enabled && ["brightness", "nightLight", "dnd", "profiles", "power"].includes(m.id)).map(m => m.id); if (ShellState.dashboardOpen) return ["power"]; if (!ShellState.settingsOpen) return []; if (ShellState.settingsPage === "displays") return ["brightness", "nightLight"]; if (ShellState.settingsPage === "notifications") return ["dnd"]; if (ShellState.settingsPage === "power") return ["power", "profiles"]; return []; } readonly property bool observed: features.length > 0 onFeaturesChanged: if (observed) refresh() onObservedChanged: if (observed) refresh() function refresh() { if (ConfigService.ready && !busy) job.start({ op: "status", features: features, options: ConfigService.data.system }); } function action(kind, value, confirmed) { if (acting || !ConfigService.ready) return false; error = ""; const request = { op: "action", action: kind, value: value, confirmed: confirmed === true, options: ConfigService.data.system }; // A status poll is running: run the action as soon as it finishes. if (busy) { queued = request; return true; } return job.start(request); } ProviderJob { id: job helper: root.helper onFinished: (request, result) => { if (result.ok) { root.state = Object.assign({}, root.state, result.state); if (request.op === "action") root.error = ""; } else root.error = result.error || "System request failed"; if (root.queued) { const next = root.queued; root.queued = null; job.start(next); } } } Timer { interval: 5000 repeat: true running: root.observed onTriggered: root.refresh() } }