diff options
Diffstat (limited to 'desktop/modules/deckit/DeckIt.qml')
| -rw-r--r-- | desktop/modules/deckit/DeckIt.qml | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/desktop/modules/deckit/DeckIt.qml b/desktop/modules/deckit/DeckIt.qml index 632285f..f39ad8c 100644 --- a/desktop/modules/deckit/DeckIt.qml +++ b/desktop/modules/deckit/DeckIt.qml @@ -58,9 +58,12 @@ Singleton { // waiting, tablet, extend}; null until the first answer. property var status: null property int watchers: 0 - // A pending Restart, 0 when none; its outcome goes to the window's snackbar. - property real restartAt: 0 - readonly property int restartTimeout: 30000 + // A Start, Stop or Restart from the drawer while it takes effect, "" when + // none. It clears once `deck-it status` shows the result, or after busyTimeout. + property string busy: "" + property real busyAt: 0 + readonly property int busyTimeout: 30000 + readonly property bool running: !!root.status && (root.status.server || root.status.waiting) // One line for the page. readonly property string summary: { @@ -75,24 +78,26 @@ Singleton { readonly property bool healthy: !!root.status && root.status.server && root.status.tablet !== "" && (!root.status.extend || root.status.display) - // Stops it and starts it again the way login does, so a saved config applies. - function restart() { - Quickshell.execDetached(["sh", "-c", "deck-it stop; exec deck-it wifi --wait"]); - Snack.wait("Restarting deck-it…"); - root.restartAt = Date.now(); - // Let stop run first, or the first poll still sees the old instance. + // Start and Restart start it the way login does, so a saved config applies. + readonly property var commands: ({ + start: "exec deck-it wifi --wait", + stop: "deck-it stop", + restart: "deck-it stop; exec deck-it wifi --wait" + }) + + function control(op) { + Quickshell.execDetached(["sh", "-c", root.commands[op]]); + root.busy = op; + root.busyAt = Date.now(); poll.restart(); } - function checkRestart() { - if (root.restartAt === 0) return; - if (root.healthy) { - Snack.ok("deck-it restarted"); - root.restartAt = 0; - } else if (Date.now() - root.restartAt > root.restartTimeout) { - Snack.error("deck-it not back after " + root.restartTimeout / 1000 + "s: " + root.summary); - root.restartAt = 0; - } + function checkBusy() { + if (!root.busy) return; + const age = Date.now() - root.busyAt; + // ponytail: 2s before believing a Restart, so the old instance's last answer does not count. + const done = root.busy === "stop" ? !!root.status && !root.running : root.running && age > 2000; + if (done || age > root.busyTimeout) root.busy = ""; } Timer { @@ -109,7 +114,7 @@ Singleton { stdout: StdioCollector { id: statOut } onExited: { try { root.status = JSON.parse(statOut.text); } catch (e) { root.status = null; } - root.checkRestart(); + root.checkBusy(); } } |
