diff options
Diffstat (limited to 'desktop')
| -rw-r--r-- | desktop/modules/autostart/Autostart.js | 9 | ||||
| -rw-r--r-- | desktop/modules/autostart/test_autostart.js | 7 |
2 files changed, 13 insertions, 3 deletions
diff --git a/desktop/modules/autostart/Autostart.js b/desktop/modules/autostart/Autostart.js index 81510d7..8fea823 100644 --- a/desktop/modules/autostart/Autostart.js +++ b/desktop/modules/autostart/Autostart.js @@ -115,12 +115,15 @@ function remove(text, e) { return edit(text, e, a => a.splice(e.index, 1)); } -// A new enabled entry before the hook's closing `end)`, indented like the -// last entry. Null if there is no `end)` to put it before. +// A new enabled entry before the closing `end)` of the hyprland.start hook, +// indented like the last entry. Not the file's last `end)`: a +// hyprland.shutdown hook after it would run the entry at logout. Null if +// there is no start hook with an `end)` to put it before. function add(text, cmd) { const a = text.split("\n"); + const start = a.findIndex(l => /^hl\.on\(\s*"hyprland\.start"/.test(l)); let end = -1; - for (let i = a.length - 1; i >= 0; i--) + for (let i = start + 1; start >= 0 && i < a.length; i++) if (/^end\)\s*$/.test(a[i])) { end = i; break; } if (end < 0) return null; const last = parse(text).pop(); diff --git a/desktop/modules/autostart/test_autostart.js b/desktop/modules/autostart/test_autostart.js index 00ba6b2..e380032 100644 --- a/desktop/modules/autostart/test_autostart.js +++ b/desktop/modules/autostart/test_autostart.js @@ -55,6 +55,13 @@ 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); +// With a shutdown hook after it, still inside the start hook: the file's +// last end) once took a login command and ran it at logout. +const both = file + 'hl.on("hyprland.shutdown", function()\n hl.exec_cmd("bye")\nend)\n'; +const into = A.add(both, "x").split("\n"); +assert.strictEqual(into[5], ' hl.exec_cmd("x")'); +assert.strictEqual(into[6], "end)"); +assert.strictEqual(into[into.length - 2], "end)"); // A stale entry, its line changed since parse, refuses rather than edits. assert.strictEqual(A.toggle(off, e[0]), null); |
