1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// 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/services/test_services.js
// Both files are QML libraries, so their .pragma lines are stripped first.
const fs = require("fs");
const assert = require("assert");
const lib = (f, names) => new Function(fs.readFileSync(f, "utf8").replace(/^\.pragma library$/m, "")
+ `\nreturn { ${names} };`)();
const A = lib(__dirname + "/../autostart/Autostart.js", "parse");
const S = lib(__dirname + "/Services.js", "daemons, DAEMONS");
const entries = A.parse([
'hl.on("hyprland.start", function()',
' hl.exec_cmd("[workspace special:dash silent] conky -c ~/.config/conky/conky.conf")',
' -- hl.exec_cmd("hypridle")',
' hl.exec_cmd("python3 -u ~/x/desktop-assistant/assistant.py >> \\"$XDG_RUNTIME_DIR/a.log\\" 2>&1")',
'end)',
].join("\n"));
const d = Object.fromEntries(S.daemons(entries).map(x => [x.label, x]));
assert.strictEqual(d.conky.start, "[workspace special:dash silent] conky -c ~/.config/conky/conky.conf");
assert.strictEqual(d["desktop-assistant"].start,
'python3 -u ~/x/desktop-assistant/assistant.py >> "$XDG_RUNTIME_DIR/a.log" 2>&1');
assert.strictEqual(d.hypridle.start, ""); // commented out
assert.strictEqual(d.notifyd.start, ""); // absent
assert.deepStrictEqual(d.hypridle.args, ["-x", "hypridle"]);
// Every -f pattern matches its line but not itself (the sh running pgrep).
for (const [label, piece, [flag, pat]] of S.DAEMONS) {
if (flag !== "-f") continue;
const re = new RegExp(pat);
assert.ok(!re.test(pat), label + " matches its own pattern");
assert.ok(re.test(piece) || re.test("wl-paste --watch " + piece), label + " misses its line");
}
console.log("services ok");
|