Repository navigation
linux: Open at login starts TwinDesk under systemd's XDG autostart generator - #202
Open
YashvanthSankar wants to merge 1 commit into
Conversation
…nerator The autostart entry ran the app through sh -c 'exec "$0" "$@" >/dev/null 2>&1', so its Exec line held \$ escapes. systemd-xdg-autostart-generator (how KDE Plasma 6 and other systemd sessions start autostart entries) keeps the backslash of \$, systemd warns "Ignoring unknown escape sequences", and sh runs a command literally named $0, which exits 127: TwinDesk never started at login. The command now goes into sh's script itself, each word as is or in single quotes, so for an ordinary path the Exec line has no $ and no backslash. stdout and stderr still go to /dev/null (InukaAsith#162), and refresh() rewrites an entry an older version wrote the next time TwinDesk starts. Fixes InukaAsith#189
There was a problem hiding this comment.
🟡 Changes recommended
The Linux autostart test fails on Windows because path.join() produces backslashes that its assertions reject before the win32 guard can skip the test.
1 open issue
What changed in this PR
Fixes Linux “Open at login” startup under systemd’s XDG autostart generator by embedding the launch command directly in the shell script, while preserving output redirection to prevent the logging failure described in #162.
Changes:
- Replaces shell positional parameters with shell-quoted command words to address #189.
- Adds regression tests for path quoting, hidden startup, output suppression, entry refresh, and removal.
| File | Description |
|---|---|
shared/test/linux-autostart.js |
Adds autostart serialization, execution, and lifecycle tests. |
linux/autostart.js |
Embeds the quoted launch command in the shell script to avoid the generator’s positional-parameter escaping issue. |
Review effort: Balanced
| const { spawnSync } = require('child_process'); | ||
| const Module = require('module'); | ||
|
|
||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'twindesk-autostart-')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes: #189
What this changes:
With Open at login on,
linux/autostart.jswrote thisExecline:systemd-xdg-autostart-generatoris how KDE Plasma 6 and other systemd sessions start XDG autostart entries. It keeps the backslash in\$, systemd logsIgnoring unknown escape sequences: "exec "\$0" "\$@" >/dev/null 2>&1", andshgetsexec "\$0" .... It then tries to run a command literally named$0and exits 127, so TwinDesk never starts at login.The fix moves the command into
sh's script. Each word is written as is, or in single quotes if it isn't a plain word, so for an ordinary path the line has no$and no backslash:stdout and stderr still go to
/dev/null(#162).refresh()already rewrites an entry whose text differs, so an entry written by an older version is fixed the next time TwinDesk starts.I added
shared/test/linux-autostart.js. For an ordinary path and a path with a space, it checks that the Exec line has no$or backslash. It then reads the line the way the Desktop Entry spec does (also for a path with',",$and%) and runs it against a stand-in AppImage, checking that the AppImage gets--hiddenand that its output goes nowhere. It also checks thatrefresh()replaces an old-style entry and thatset(false)removes the file.How I tested it:
systemd-xdg-autostart-generatorfrom Debian's systemd 252 on the entries from before and after the change, then checked the resulting units withsystemd-analyze --user verify. Before: the generatedExecStarthas\$0, systemd prints the same "Ignoring unknown escape sequences" warning as in the issue, and the argument it passes (sh -c 'exec "\$0" "\$@" ...' <AppImage> --hidden) exits 127 without starting the app. After:ExecStart=:/usr/bin/sh -c "exec /home/u/Applications/TwinDesk.AppImage --hidden >/dev/null 2>&1", no warning, and the command starts the app with--hidden.node shared/test/linux-autostart.jsfails onmain("Exec has a $ or a backslash") and passes with the change.shared/test/*.js, run as CI does: 115/115 pass before, 116/116 after.node --check linux/autostart.jspasses.I didn't test on a KDE Plasma desktop itself.
One limit: if the AppImage path itself contains a
$, the Exec quoting has to write it as\$, and systemd's generator still mishandles that. Other paths (spaces,',",%) come through the generator correctly.