Skip to content

linux: Open at login starts TwinDesk under systemd's XDG autostart generator - #202

Open
YashvanthSankar wants to merge 1 commit into
InukaAsith:mainfrom
YashvanthSankar:linux-open-at-login-starts-twindesk-unde-2026-11-11
Open

YashvanthSankar wants to merge 1 commit into
InukaAsith:mainfrom
YashvanthSankar:linux-open-at-login-starts-twindesk-unde-2026-11-11

Conversation

@YashvanthSankar

Copy link
Copy Markdown

Fixes: #189

What this changes:

With Open at login on, linux/autostart.js wrote this Exec line:

Exec=sh -c "exec \\"\\$0\\" \\"\\$@\\" >/dev/null 2>&1" /home/<user>/Applications/TwinDesk.AppImage --hidden

systemd-xdg-autostart-generator is how KDE Plasma 6 and other systemd sessions start XDG autostart entries. It keeps the backslash in \$, systemd logs Ignoring unknown escape sequences: "exec "\$0" "\$@" >/dev/null 2>&1", and sh gets exec "\$0" .... It then tries to run a command literally named $0 and 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:

Exec=sh -c "exec /home/<user>/Applications/TwinDesk.AppImage --hidden >/dev/null 2>&1"
Exec=sh -c "exec '/home/<user>/My Apps/TwinDesk.AppImage' --hidden >/dev/null 2>&1"

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 --hidden and that its output goes nowhere. It also checks that refresh() replaces an old-style entry and that set(false) removes the file.

How I tested it:

  • Ran the real systemd-xdg-autostart-generator from Debian's systemd 252 on the entries from before and after the change, then checked the resulting units with systemd-analyze --user verify. Before: the generated ExecStart has \$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.js fails on main ("Exec has a $ or a backslash") and passes with the change.
  • Every shared/test/*.js, run as CI does: 115/115 pass before, 116/116 after. node --check linux/autostart.js passes.

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.

…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
Copilot AI balanced review requested due to automatic review settings November 11, 2026 00:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants