aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/services/ServicesModule.qml
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-18 17:04:57 +0100
committerDanilo M. <danix@danix.xyz>2026-11-18 17:04:57 +0100
commite55c1f32b383c53d12dc7c2b3c5e2e6ccb146cdc (patch)
treefee3f3ced727f01c7bc630418a6e0b47d347df40 /desktop/modules/services/ServicesModule.qml
parent44f947c642fe842fae80c7407399265aa47e9909 (diff)
downloadquickshell-e55c1f32b383c53d12dc7c2b3c5e2e6ccb146cdc.tar.gz
quickshell-e55c1f32b383c53d12dc7c2b3c5e2e6ccb146cdc.zip
feat(services): one drawer page to start, stop and restart services
Running things is a runtime operation, so it belongs in the drawer, not the settings window. The drawer's deck-it tile and keystone's Shells page become one Services tile: every quickshell shell, deck-it, and the desktop's long-running daemons (desktop-assistant, cal-notif, tv-mpris, mail-watcher, mail-notify, hypridle, hyprsunset, the polkit agent, notifyd, playerctld, conky and cliphist's watcher), each with Start, Stop and Restart. A daemon's start command is its enabled autostart.lua line, run through hyprctl dispatch hl.dsp.exec_cmd as Autostart's Try does, so conky keeps its workspace rule and no command is copied out of autostart.lua. Services.js holds only the label, the piece of the line that finds it and the pgrep/pkill arguments. Stop waits up to 5s for the process to exit, which hyprsunset needs to free Hyprland's CTM manager. -f patterns bracket a letter so pgrep and pkill never match the sh that runs them. Checked: test_services.js; the pgrep list reports all twelve daemons running; a playerctld restart through the same command came back under a new pid. QML's JS engine has no Array.flatMap, hence the concat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/services/ServicesModule.qml')
-rw-r--r--desktop/modules/services/ServicesModule.qml135
1 files changed, 135 insertions, 0 deletions
diff --git a/desktop/modules/services/ServicesModule.qml b/desktop/modules/services/ServicesModule.qml
new file mode 100644
index 0000000..ffc25fd
--- /dev/null
+++ b/desktop/modules/services/ServicesModule.qml
@@ -0,0 +1,135 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+import Quickshell
+import Quickshell.Io
+import QtQuick
+import "../.."
+import "../deckit"
+import "../autostart/Autostart.js" as A
+import "Services.js" as S
+
+// The drawer's Services: every quickshell shell, deck-it and the desktop's
+// daemons, each with Start, Stop and Restart. Their state is read every 2s
+// while the page is open. Started detached, so an action outlives the qs that
+// started it: restarting the desktop shell from its own drawer works, the
+// drawer just closes until the new process is up.
+Module {
+ id: sm
+ name: "services"
+ label: "Services"
+ // nf-fa-refresh, present in Inconsolata Nerd Font.
+ icon: ""
+ keywords: ["services", "restart", "reload", "start", "stop", "quickshell", "qs", "shells",
+ "daemon", "deck-it", "process"]
+
+ readonly property string root: Quickshell.shellDir + "/.."
+ // [{name, running}], one per directory holding a shell.qml.
+ property var shells: []
+ // [{label, args, start, running}], Services.js's daemons.
+ property var daemons: []
+ property int watchers: 0
+
+ // An empty name restarts every shell the page lists. A stopped shell
+ // restarts into a start: reload.sh only starts what is not running.
+ function restartShell(name) {
+ Quickshell.execDetached(["sh", Quickshell.shellDir + "/modules/services/restart.sh", sm.root]
+ .concat(name ? [name] : sm.shells.map(s => s.name)));
+ repoll.restart();
+ }
+
+ function stopShell(name) {
+ Quickshell.execDetached(["qs", "kill", "-p", sm.root + "/" + name]);
+ repoll.restart();
+ }
+
+ // Stop is pkill, then up to 5s for the process to go: hyprsunset holds
+ // Hyprland's CTM manager until it exits, and a second one dies. Start runs
+ // the autostart.lua line through Hyprland, so its [workspace] rule
+ // applies as at login.
+ function daemon(d, op) {
+ const start = op === "stop" || !d.start ? "" : 'hl.dsp.exec_cmd("' + A.quote(d.start) + '")';
+ Quickshell.execDetached(["sh", "-c",
+ 'start=$1; kill=$2; shift 2; '
+ + 'if [ "$kill" = 1 ]; then pkill "$@"; '
+ + 'for i in $(seq 50); do pgrep "$@" >/dev/null || break; sleep 0.1; done; fi; '
+ + '[ -z "$start" ] || hyprctl dispatch "$start"',
+ "sh", start, op === "start" ? "0" : "1"].concat(d.args));
+ repoll.restart();
+ }
+
+ function refresh() {
+ shellProc.rows = [];
+ shellProc.running = false;
+ shellProc.running = true;
+ if (!daemonProc.running) daemonProc.running = true;
+ }
+
+ // reload.sh waits a second before it returns; read again after that.
+ property Timer repoll: Timer {
+ interval: 2000
+ onTriggered: sm.refresh()
+ }
+ property Timer poll: Timer {
+ interval: 2000
+ repeat: true
+ running: sm.watchers > 0
+ onTriggered: sm.refresh()
+ }
+
+ property FileView autostart: FileView {
+ path: DeckIt.autostartFile
+ watchChanges: true
+ printErrors: false
+ onFileChanged: reload()
+ onLoaded: sm.refresh()
+ }
+
+ // A shell is running when qs lists an instance on its config path.
+ property Process shellProc: Process {
+ property var rows: []
+ command: ["sh", "-c", 'cd "$1" || exit 1; up=$(qs list --all 2>/dev/null); '
+ + 'for f in */shell.qml; do case "$up" in '
+ + '*"Config path: $PWD/$f"*) s=running ;; *) s=stopped ;; esac; '
+ + 'printf "%s\\t%s\\n" "${f%/shell.qml}" "$s"; done', "sh", sm.root]
+ stdout: SplitParser {
+ onRead: line => {
+ const f = line.split("\t");
+ if (f.length === 2) shellProc.rows.push({ name: f[0], running: f[1] === "running" });
+ }
+ }
+ onExited: {
+ sm.shells = shellProc.rows;
+ sm.searchItems = shellProc.rows.map(s => ({ text: s.name, key: "shell:" + s.name }))
+ .concat(S.DAEMONS.map(x => ({ text: x[0], key: "daemon:" + x[0] })));
+ }
+ }
+
+ // One 1 or 0 per daemon, in Services.js's order; every daemon has a
+ // flag and a pattern.
+ property Process daemonProc: Process {
+ command: ["sh", "-c", 'while [ $# -gt 1 ]; do pgrep "$1" "$2" >/dev/null && echo 1 || echo 0; shift 2; done',
+ "sh"].concat([].concat(...S.DAEMONS.map(x => x[2])))
+ stdout: StdioCollector { id: daemonOut }
+ onExited: {
+ const up = daemonOut.text.split("\n");
+ sm.daemons = S.daemons(A.parse(sm.autostart.text()))
+ .map((d, i) => Object.assign(d, { running: up[i] === "1" }));
+ }
+ }
+
+ page: Component {
+ Page {
+ title: "Services"
+ ServicesPage { width: parent.width; services: sm }
+ }
+ }
+}