Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(linux): keep the autostart entry writable, named and escaped correctly
Gabriel Steinab4d0546fcd9
diff --git a/CLAUDE.md b/CLAUDE.mdindex 4719bbd94..ed895138b 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -96,7 +96,7 @@ OpenWhispr is an Electron-based desktop dictation application that uses whisper.- Only active on Linux + KDE desktop (detected via `XDG_CURRENT_DESKTOP`)- D-Bus transport: `@homebridge/dbus-native` (pure JavaScript, no native addons)- **linuxAutostart.js**: Launch-at-login on Linux via an XDG autostart entry- - `app.setLoginItemSettings()` is a no-op on Linux, so the entry is written directly to `$XDG_CONFIG_HOME/autostart/openwhispr.desktop`+ - `app.setLoginItemSettings()` is a no-op on Linux, so the entry is written directly to `$XDG_CONFIG_HOME/autostart/open-whispr.desktop`, matching the executable name electron-builder packages under- `Exec` resolves from `$APPIMAGE` first: `process.execPath` is the ephemeral AppImage FUSE mount- `isAutostartEnabled()` honors `X-GNOME-Autostart-enabled=false` and `Hidden=true`, which GNOME Tweaks and KDE's autostart editor write in place instead of deleting the file- `syncAutostartEntry()` runs from `initializeCoreManagers()` in `main.js` and re-points a stale `Exec` after the executable moves (renamed or auto-updated AppImage); it never re-enables an entry the user disabled, and no-ops in development@@ -775,7 +775,7 @@ const { t } = useTranslation();- No standardized URL scheme for system settings (user must open manually)- Privacy settings button hidden in UI (not applicable on Linux)- Recommend `pavucontrol` for audio device management-- **Launch at login**: XDG autostart entry at `~/.config/autostart/openwhispr.desktop` (see `linuxAutostart.js`), since Electron's `setLoginItemSettings()` does nothing on Linux+- **Launch at login**: XDG autostart entry at `~/.config/autostart/open-whispr.desktop` (see `linuxAutostart.js`), since Electron's `setLoginItemSettings()` does nothing on Linux- Disabling it from GNOME Tweaks or KDE's autostart editor is reflected in the Settings toggle- "Start minimized" is handled app-side by the `startMinimized` setting, not by the desktop entry- **Clipboard paste tools** (at least one required for auto-paste):diff --git a/src/helpers/linuxAutostart.js b/src/helpers/linuxAutostart.jsindex 8eefc0a18..e43891d76 100644--- a/src/helpers/linuxAutostart.js+++ b/src/helpers/linuxAutostart.js@@ -4,18 +4,36 @@ const os = require("os");const DESKTOP_ENTRY_GROUP = "[Desktop Entry]";+// electron-builder names the packaged desktop entry and icon after the Linux+// executable, which main.js also passes to app.setDesktopName(). Reusing it here+// keeps our entry and the packaged one referring to the same icon.+const LINUX_APP_NAME = "open-whispr";+const ICON_THEME_SUBPATH = path.join(+ "icons",+ "hicolor",+ "256x256",+ "apps",+ `${LINUX_APP_NAME}.png`+);+function getAutostartDir() {const xdgConfigHome = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");return path.join(xdgConfigHome, "autostart");}function getDesktopFilePath() {- return path.join(getAutostartDir(), "openwhispr.desktop");+ return path.join(getAutostartDir(), `${LINUX_APP_NAME}.desktop`);}-function getIconInstallPath() {+// Icon= is resolved against the theme search path, so deb/rpm installs already+// have one and only unpackaged layouts (AppImage, tar.gz) need a copy. The user+// directory comes first because that is the only one we may write to.+function getIconThemePaths() {const xdgDataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), ".local", "share");- return path.join(xdgDataHome, "icons", "hicolor", "256x256", "apps", "openwhispr.png");+ const systemDataDirs = (process.env.XDG_DATA_DIRS || "/usr/local/share:/usr/share")+ .split(":")+ .filter(Boolean);+ return [xdgDataHome, ...systemDataDirs].map((dir) => path.join(dir, ICON_THEME_SUBPATH));}function isDevelopment() {@@ -40,32 +58,42 @@ function findBundledIconSource() {return candidates.find((candidate) => fs.existsSync(candidate)) || null;}+// The icon is decoration; an unwritable data directory must not stop the entry+// itself from being written, which is the only thing the toggle promises.function ensureIconInstalled() {- const iconDest = getIconInstallPath();- if (fs.existsSync(iconDest)) return iconDest;+ try {+ const [userIconPath, ...systemIconPaths] = getIconThemePaths();+ if (fs.existsSync(userIconPath)) return true;+ if (systemIconPaths.some((iconPath) => fs.existsSync(iconPath))) return true;- const iconSource = findBundledIconSource();- if (!iconSource) return null;+ const iconSource = findBundledIconSource();+ if (!iconSource) return false;- fs.mkdirSync(path.dirname(iconDest), { recursive: true });- fs.copyFileSync(iconSource, iconDest);- return iconDest;+ fs.mkdirSync(path.dirname(userIconPath), { recursive: true });+ fs.copyFileSync(iconSource, userIconPath);+ return true;+ } catch {+ return false;+ }}-// Reserved characters inside a quoted Exec argument have to be backslash-escaped-// per the Desktop Entry spec, so a home directory containing one still resolves.+// Exec goes through two unescaping passes: the desktop-entry string rule runs+// first, then the argument-quoting rule. Reserved characters need a single+// backslash for the quoting rule, but a literal backslash needs four, since the+// string rule collapses each pair into one before quoting is applied.function quoteExecPath(execPath) {- return `"${execPath.replace(/(["`$\\])/g, "\\$1")}"`;+ const escaped = execPath.replace(/\\/g, "\\\\\\\\").replace(/(["`$])/g, "\\$1");+ return `"${escaped}"`;}-function buildDesktopFileContents(execPath, iconPath) {+function buildDesktopFileContents(execPath, iconName) {return [DESKTOP_ENTRY_GROUP,"Type=Application","Name=OpenWhispr","Comment=Voice dictation and AI agent",`Exec=${quoteExecPath(execPath)}`,- iconPath ? `Icon=${iconPath}` : null,+ iconName ? `Icon=${iconName}` : null,"Terminal=false","Categories=Utility;","X-GNOME-Autostart-enabled=true",@@ -116,17 +144,24 @@ function readBoolean(value) {// GNOME Tweaks and KDE's autostart editor disable an entry by rewriting these// keys in place rather than deleting the file, so existence alone is not enough.-function isAutostartEnabled() {- const entry = readDesktopEntry();+function isEntryEnabled(entry) {if (!entry) return false;if (readBoolean(entry.Hidden) === true) return false;return readBoolean(entry["X-GNOME-Autostart-enabled"]) !== false;}+function isAutostartEnabled() {+ return isEntryEnabled(readDesktopEntry());+}+function writeAutostartEntry() {fs.mkdirSync(getAutostartDir(), { recursive: true });- const contents = buildDesktopFileContents(resolveExecutablePath(), ensureIconInstalled());- fs.writeFileSync(getDesktopFilePath(), contents, { mode: 0o644 });+ const iconName = ensureIconInstalled() ? LINUX_APP_NAME : null;+ fs.writeFileSync(+ getDesktopFilePath(),+ buildDesktopFileContents(resolveExecutablePath(), iconName),+ { mode: 0o644 }+ );}function setAutostartEnabled(enabled) {@@ -143,9 +178,9 @@ function setAutostartEnabled(enabled) {// nothing. Skipped in development, where execPath is the local Electron binary.function syncAutostartEntry() {if (isDevelopment()) return false;- if (!isAutostartEnabled()) return false;const entry = readDesktopEntry();+ if (!isEntryEnabled(entry)) return false;if (entry.Exec === quoteExecPath(resolveExecutablePath())) return false;writeAutostartEntry();diff --git a/test/helpers/linuxAutostart.test.js b/test/helpers/linuxAutostart.test.jsindex ba4a10655..37ee5ade2 100644--- a/test/helpers/linuxAutostart.test.js+++ b/test/helpers/linuxAutostart.test.js@@ -8,7 +8,9 @@ const load = () => import("../../src/helpers/linuxAutostart.js");// Assigning undefined to process.env coerces to the string "undefined", which// would leak a bogus value into every later test in this file.-const MANAGED_ENV = ["XDG_CONFIG_HOME", "XDG_DATA_HOME", "APPIMAGE", "NODE_ENV"];+const MANAGED_ENV = ["XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_DATA_DIRS", "APPIMAGE", "NODE_ENV"];++const ICON_THEME_SUBPATH = path.join("icons", "hicolor", "256x256", "apps", "open-whispr.png");function setEnv(name, value) {if (value === undefined) delete process.env[name];@@ -22,6 +24,7 @@ function withTmpXdgDirs(fn) {MANAGED_ENV.forEach((name) => setEnv(name, undefined));process.env.XDG_CONFIG_HOME = path.join(root, "config");process.env.XDG_DATA_HOME = path.join(root, "data");+ process.env.XDG_DATA_DIRS = path.join(root, "system-data");try {await fn(root);} finally {@@ -56,13 +59,13 @@ test();test(- "desktop file contents quote the exec path and include the icon when present",+ "desktop file contents quote the exec path and reference the icon by theme name",withTmpXdgDirs(async () => {const { buildDesktopFileContents } = await load();- const contents = buildDesktopFileContents("/a/b/OpenWhispr.AppImage", "/a/b/icon.png");+ const contents = buildDesktopFileContents("/a/b/OpenWhispr.AppImage", "open-whispr");assert.match(contents, /^Exec="\/a\/b\/OpenWhispr\.AppImage"$/m);- assert.match(contents, /^Icon=\/a\/b\/icon\.png$/m);+ assert.match(contents, /^Icon=open-whispr$/m);assert.match(contents, /^X-GNOME-Autostart-enabled=true$/m);}));@@ -77,13 +80,43 @@ test(}));+// The desktop-entry string rule unescapes the value before the quoting rule+// splits it into arguments, so a literal backslash has to survive both passes.test("exec paths containing reserved characters are escaped, not written raw",withTmpXdgDirs(async () => {const { buildDesktopFileContents } = await load();const contents = buildDesktopFileContents('/home/o"neill/$HOME/`app`\\v/OpenWhispr', null);- assert.match(contents, /^Exec="\/home\/o\\"neill\/\\\$HOME\/\\`app\\`\\\\v\/OpenWhispr"$/m);+ assert.match(contents, /^Exec="\/home\/o\\"neill\/\\\$HOME\/\\`app\\`\\\\\\\\v\/OpenWhispr"$/m);+ })+);++test(+ "an icon the package already installed is referenced, not copied into the user theme",+ withTmpXdgDirs(async (root) => {+ const { setAutostartEnabled, getDesktopFilePath } = await load();++ writeEntry(path.join(root, "system-data", ICON_THEME_SUBPATH), "pretend png");++ setAutostartEnabled(true);+ assert.match(fs.readFileSync(getDesktopFilePath(), "utf8"), /^Icon=open-whispr$/m);+ assert.ok(!fs.existsSync(path.join(root, "data", ICON_THEME_SUBPATH)));+ })+);++test(+ "an unwritable icon directory still leaves launch at login enabled",+ withTmpXdgDirs(async (root) => {+ const { setAutostartEnabled, isAutostartEnabled, getDesktopFilePath } = await load();++ // A file where the icon tree has to go makes every mkdir below it fail with+ // ENOTDIR, standing in for a read-only or quota-exhausted home directory.+ fs.writeFileSync(path.join(root, "data"), "not a directory");++ assert.doesNotThrow(() => setAutostartEnabled(true));+ assert.equal(isAutostartEnabled(), true);+ assert.doesNotMatch(fs.readFileSync(getDesktopFilePath(), "utf8"), /^Icon=/m);}));