aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/autostart/test_autostart.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-17 09:54:18 +0200
committerDanilo M. <danix@danix.xyz>2026-10-17 09:54:18 +0200
commit66049c965139d821747ea76960b1e91316f8110a (patch)
tree45ac7a387ea02c1cc8d26e104f6e69a96d3880ed /desktop/modules/autostart/test_autostart.js
parent4513a506fc575f880db80f05bb3a9cdf7dc100e0 (diff)
downloadquickshell-66049c965139d821747ea76960b1e91316f8110a.tar.gz
quickshell-66049c965139d821747ea76960b1e91316f8110a.zip
desktop: a settings window, and autostart as its first page
The drawer's tiles were turning into a full settings app. The drawer stays the quick area, live state and things toggled often; pages set once and left alone go to a settings window, a normal Hyprland toplevel listing them down the left. A module joins with settings: true, which also drops its tile. A gear tile and ipc call settings open|toggle reach it. Autostart edits hypr-theme's autostart.lua directly, line by line: an hl.exec_cmd line is an entry, behind -- it is disabled, everything else passes through. Edits refuse when their line moved since the parse, and writes are atomic because Hyprland reloads on every change. A wrong entry only shows at the next login, so adding is guided rather than a free text field: pick an installed app or type a command whose program must resolve on PATH before Add enables, then a workspace and silent, composed into a [workspace X silent] rule. Try runs the line through hyprctl dispatch so the rule applies as at login. Existing rows get no Try: they ran at login, and a second start stacks an instance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/autostart/test_autostart.js')
-rw-r--r--desktop/modules/autostart/test_autostart.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/desktop/modules/autostart/test_autostart.js b/desktop/modules/autostart/test_autostart.js
new file mode 100644
index 0000000..00ba6b2
--- /dev/null
+++ b/desktop/modules/autostart/test_autostart.js
@@ -0,0 +1,87 @@
+// 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.
+
+// Run: node desktop/modules/autostart/test_autostart.js
+// Autostart.js is a QML library, so its .pragma line is stripped before node
+// evaluates it.
+
+const fs = require("fs");
+const assert = require("assert");
+
+const src = fs.readFileSync(__dirname + "/Autostart.js", "utf8")
+ .replace(/^\.pragma library$/m, "");
+const A = new Function(src + "\nreturn { parse, toggle, remove, add, split, workspace, compose, program, fromExec };")();
+
+const file = [
+ 'hl.on("hyprland.start", function()',
+ ' hl.exec_cmd("playerctld daemon")',
+ ' -- hl.exec_cmd("[workspace special silent] kitty btop")',
+ ' hl.exec_cmd("app >> \\"$XDG_RUNTIME_DIR/x.log\\" 2>&1")',
+ ' hl.on("other", function() end)',
+ 'end)',
+ '',
+].join("\n");
+
+const e = A.parse(file);
+assert.deepStrictEqual(e.map(x => [x.index, x.cmd, x.enabled]), [
+ [1, "playerctld daemon", true],
+ [2, "[workspace special silent] kitty btop", false],
+ [3, 'app >> "$XDG_RUNTIME_DIR/x.log" 2>&1', true],
+]);
+
+// Toggle both ways; untouched lines survive byte for byte.
+const off = A.toggle(file, e[0]);
+assert.strictEqual(off.split("\n")[1], ' -- hl.exec_cmd("playerctld daemon")');
+assert.strictEqual(A.toggle(off, A.parse(off)[0]), file);
+assert.strictEqual(A.toggle(file, e[1]).split("\n")[2],
+ ' hl.exec_cmd("[workspace special silent] kitty btop")');
+// Quotes round-trip through unquote and quote.
+const q = A.toggle(file, e[2]);
+assert.strictEqual(A.toggle(q, A.parse(q)[2]), file);
+
+assert.strictEqual(A.remove(file, e[1]).split("\n").length, file.split("\n").length - 1);
+assert.ok(!A.remove(file, e[1]).includes("btop"));
+
+// Added before the hook's own `end)`, not the nested one, quotes escaped.
+const added = A.add(file, 'say "hi"').split("\n");
+assert.strictEqual(added[5], ' hl.exec_cmd("say \\"hi\\"")');
+assert.strictEqual(added[6], "end)");
+assert.strictEqual(A.add("nothing here", "x"), null);
+
+// A stale entry, its line changed since parse, refuses rather than edits.
+assert.strictEqual(A.toggle(off, e[0]), null);
+assert.strictEqual(A.remove(A.remove(file, e[0]), e[1]), null);
+
+// The rule prefix, and the workspace form the page edits.
+assert.deepStrictEqual(A.split("[workspace special:dash silent] conky -c x"),
+ { rule: "workspace special:dash silent", body: "conky -c x" });
+assert.deepStrictEqual(A.split("conky"), { rule: "", body: "conky" });
+assert.deepStrictEqual(A.workspace("workspace special:dash silent"), { ws: "special:dash", silent: true });
+assert.deepStrictEqual(A.workspace("workspace 3"), { ws: "3", silent: false });
+assert.deepStrictEqual(A.workspace(""), { ws: "", silent: false });
+assert.strictEqual(A.workspace("float; size 50% 50%"), null);
+assert.strictEqual(A.compose("special", true, "btop"), "[workspace special silent] btop");
+assert.strictEqual(A.compose("", true, "btop"), "btop");
+
+// The program behind each live shape of command.
+const H = "/home/you";
+assert.strictEqual(A.program("playerctld daemon", H), "playerctld");
+assert.strictEqual(A.program("[workspace special silent] kitty --class k btop", H), "kitty");
+assert.strictEqual(A.program("~/bin/cal-notif daemon >> \"$X/c.log\" 2>&1", H), "/home/you/bin/cal-notif");
+assert.strictEqual(A.program("bash -c 'eval $(gnome-keyring-daemon --start) && dbus-update'", H), "eval");
+assert.strictEqual(A.program("bash -c 'echo \"$D\" > /run/x'", H), "echo");
+assert.strictEqual(A.program("FOO=1 env BAR=2 exec /usr/libexec/agent", H), "/usr/libexec/agent");
+assert.strictEqual(A.program("", H), "");
+
+assert.strictEqual(A.fromExec("firefox %u"), "firefox");
+assert.strictEqual(A.fromExec("app --name=%%x %F --flag"), "app --name=%x --flag");
+
+console.log("test_autostart: ok");