Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(startup): point the Linux entry at the launcher wrapper, harden the probe

Gabriel Stein22f6e4bb9ae0
diff --git a/main.js b/main.js
index 107b017b7..1c8102f1b 100644
--- a/main.js
+++ b/main.js
@@ -393,6 +393,18 @@ function syncAutoStartEntry() {
}
}
+// Reading the login item touches the OS, and failing to answer "did the session
+// start us?" must not stop the app from starting at all. Falling back to false
+// just shows the window, which is what every launch did before.
+function wasLaunchedAtLoginHidden() {
+ try {
+ return autoStart.wasLaunchedAtLoginHidden();
+ } catch (error) {
+ if (debugLogger) debugLogger.warn("Failed to detect a login launch", { error: error?.message });
+ return false;
+ }
+}
+
function initializeCoreManagers() {
setupProductionPath();
@@ -960,7 +972,7 @@ async function startApp() {
// Create windows FIRST so the user sees UI as soon as possible.
// A login launch goes to the tray whatever the preference says: the user asked
// the OS to start us, not to put a window in front of them at every login.
- const launchedHidden = autoStart.wasLaunchedAtLoginHidden();
+ const launchedHidden = wasLaunchedAtLoginHidden();
const startMinimized = environmentManager.getStartMinimized() || launchedHidden;
if (debugLogger) debugLogger.info("Start minimized", { enabled: startMinimized, launchedHidden });
await windowManager.createMainWindow();
diff --git a/resources/nsis/installer.nsh b/resources/nsis/installer.nsh
index 45dadf21d..8b73f07c6 100644
--- a/resources/nsis/installer.nsh
+++ b/resources/nsis/installer.nsh
@@ -17,12 +17,12 @@
; production builds (keep in sync with BASE_WINDOWS_APP_ID and VALID_CHANNELS
; there). Disabling an item leaves a second value behind under StartupApproved,
; so both have to go.
-!define RUN_KEY "Software\Microsoft\Windows\CurrentVersion\Run"
-!define STARTUP_APPROVED_KEY "Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run"
+!define OW_RUN_KEY "Software\Microsoft\Windows\CurrentVersion\Run"
+!define OW_STARTUP_APPROVED_KEY "Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run"
!macro DeleteAutoStartEntry NAME
- DeleteRegValue HKCU "${RUN_KEY}" "${NAME}"
- DeleteRegValue HKCU "${STARTUP_APPROVED_KEY}" "${NAME}"
+ DeleteRegValue HKCU "${OW_RUN_KEY}" "${NAME}"
+ DeleteRegValue HKCU "${OW_STARTUP_APPROVED_KEY}" "${NAME}"
!macroend
!macro customInstall
diff --git a/src/helpers/autoStart.js b/src/helpers/autoStart.js
index 16d9d0bbd..ff6f78460 100644
--- a/src/helpers/autoStart.js
+++ b/src/helpers/autoStart.js
@@ -1,6 +1,6 @@
-// Single entry point for launch at login. Electron's setLoginItemSettings covers
-// macOS and Windows; Linux is handled by an XDG autostart entry (linuxAutostart).
-// Decisions live in autoStartPolicy so they can be tested without Electron.
+// Launch at login, for ipcHandlers.js and main.js. setLoginItemSettings covers
+// macOS and Windows; on Linux it does nothing, so an XDG autostart entry stands in
+// (linuxAutostart.js). Decisions live in autoStartPolicy.js.
const { app } = require("electron");
const linuxAutostart = require("./linuxAutostart");
@@ -24,8 +24,7 @@ function writeLoginItem(enabled) {
});
}
-// { enabled, requiresApproval } — requiresApproval is macOS-only and means the
-// item is registered but still waiting on the user in System Settings.
+// { enabled, requiresApproval } — requiresApproval is macOS-only.
function getAutoStartState() {
if (isLinux()) {
return { enabled: linuxAutostart.isAutostartEnabled(), requiresApproval: false };
@@ -53,19 +52,13 @@ function wasLaunchedAtLoginHidden() {
}
// Repairs an entry that still exists but no longer starts this executable, or
-// starts it without the flag that sends it to the tray. Returns true when
-// something was rewritten, so the caller can log it.
+// starts it without the flag that sends it to the tray. True when it rewrote one.
function syncAutoStartEntry() {
if (isLinux()) return linuxAutostart.syncAutostartEntry();
- if (
- !needsHiddenFlagMigration({
- platform: process.platform,
- loginItemSettings: readLoginItemSettings(),
- })
- ) {
- return false;
- }
+ const loginItemSettings = readLoginItemSettings();
+ if (!needsHiddenFlagMigration({ platform: process.platform, loginItemSettings })) return false;
+
writeLoginItem(true);
return true;
}
diff --git a/src/helpers/autoStartPolicy.js b/src/helpers/autoStartPolicy.js
index 8b5a0ab94..ef52cc880 100644
--- a/src/helpers/autoStartPolicy.js
+++ b/src/helpers/autoStartPolicy.js
@@ -1,55 +1,48 @@
// Launch-at-login decisions, kept free of Electron so they can be unit-tested.
//
-// Windows has no equivalent of macOS' openAsHidden (which is itself a no-op on
-// macOS 13 and up), so a login item that should come up in the tray has to say so
-// with a command-line flag we read back at startup. Linux rides the same flag on
-// the autostart entry's Exec line; macOS reports it through wasOpenedAtLogin.
+// A login launch should come up in the tray, and Windows has no way to ask for
+// that (macOS' openAsHidden is macOS-only and a no-op on macOS 13+). So the login
+// item carries a flag we read back at startup. Linux puts the same flag on the
+// autostart entry's Exec line; macOS reports it through wasOpenedAtLogin.
const HIDDEN_LAUNCH_FLAG = "--hidden";
-// The args a Windows login item is registered with. getLoginItemSettings compares
-// the registry value against `"exe" args` verbatim, so reads have to pass exactly
-// what writes did or openAtLogin always reports false.
+// getLoginItemSettings compares the registry value against `"exe" args` verbatim,
+// so reads have to pass exactly what writes did or openAtLogin is always false.
function getLoginItemArgs(platform) {
return platform === "win32" ? [HIDDEN_LAUNCH_FLAG] : [];
}
-// On Windows, openAtLogin only reports whether the Run entry matches this
-// executable and args. It ignores Explorer's StartupApproved key, which is what
-// Task Manager and Settings write when a user disables a startup app, so an app
-// the user switched off still reads as enabled. executableWillLaunchAtLogin is
-// the only field that accounts for both.
+// For the platforms setLoginItemSettings covers: win32 and darwin.
function resolveAutoStartState({ platform, loginItemSettings }) {
if (platform === "win32") {
- return {
- enabled: !!loginItemSettings.executableWillLaunchAtLogin,
- requiresApproval: false,
- };
+ // openAtLogin only checks whether the Run entry matches this executable and
+ // args; it ignores Explorer's StartupApproved key, which is what Task Manager
+ // writes when a user disables a startup app. Only this field covers both.
+ return { enabled: !!loginItemSettings.executableWillLaunchAtLogin, requiresApproval: false };
}
return {
enabled: !!loginItemSettings.openAtLogin,
// macOS 13+ routes login items through SMAppService, which can register an
- // item and still leave it awaiting the user's approval in System Settings.
- // Without surfacing that, the toggle just appears not to stick.
+ // item and still leave it awaiting approval in System Settings. Unsurfaced,
+ // that just looks like a toggle that will not stick.
requiresApproval: loginItemSettings.status === "requires-approval",
};
}
-// A login item written before this build carries no --hidden, so it no longer
-// matches what we now write and openAtLogin reads false while the stale entry
-// keeps launching the app with its window showing. Rewriting it uses the same
-// registry value name, so it re-points the entry instead of adding a second one.
+// An entry written before this build carries no flag, so it no longer matches what
+// we write and reads as disabled while still launching the app with its window
+// showing. Rewriting reuses the same registry value name, so it re-points that
+// entry rather than adding a second one.
function needsHiddenFlagMigration({ platform, loginItemSettings }) {
if (platform !== "win32") return false;
return !!loginItemSettings.executableWillLaunchAtLogin && !loginItemSettings.openAtLogin;
}
-// Whether this process was started by the login item rather than by the user, in
-// which case it should go straight to the tray. Checked instead of the user's
-// startMinimized preference so a login launch never overwrites it.
+// Whether the session started this process rather than the user.
function wasLaunchedHidden({ platform, argv, loginItemSettings }) {
- if (platform === "darwin") return !!loginItemSettings?.wasOpenedAtLogin;
- return !!argv?.includes(HIDDEN_LAUNCH_FLAG);
+ if (platform === "darwin") return !!loginItemSettings.wasOpenedAtLogin;
+ return argv.includes(HIDDEN_LAUNCH_FLAG);
}
module.exports = {
diff --git a/src/helpers/linuxAutostart.js b/src/helpers/linuxAutostart.js
index 50922fe1c..93a084f22 100644
--- a/src/helpers/linuxAutostart.js
+++ b/src/helpers/linuxAutostart.js
@@ -9,6 +9,7 @@ const DESKTOP_ENTRY_GROUP = "[Desktop Entry]";
// 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 WRAPPED_BINARY_SUFFIX = "-app";
const ICON_THEME_SUBPATH = path.join(
"icons",
"hicolor",
@@ -41,10 +42,20 @@ function isDevelopment() {
return process.env.NODE_ENV === "development";
}
-// electron.d.ts marks setLoginItemSettings' path override as win32-only; on Linux
-// process.execPath is the ephemeral AppImage FUSE mount, so we resolve it ourselves.
+// What the entry should launch, which is never plain process.execPath:
+// - On AppImage, execPath is the ephemeral FUSE mount, gone by the next boot.
+// - Elsewhere, scripts/afterPack.js renames the binary to <name>-app and leaves
+// a wrapper script under the original name, so execPath is the inner binary.
+// Launching it directly skips XWayland forcing, the --no-sandbox fallback and
+// the user's flags file (see scripts/lib/linux-launcher.js).
function resolveExecutablePath() {
- return process.env.APPIMAGE || process.execPath;
+ if (process.env.APPIMAGE) return process.env.APPIMAGE;
+
+ if (process.execPath.endsWith(WRAPPED_BINARY_SUFFIX)) {
+ const wrapperPath = process.execPath.slice(0, -WRAPPED_BINARY_SUFFIX.length);
+ if (fs.existsSync(wrapperPath)) return wrapperPath;
+ }
+ return process.execPath;
}
function findBundledIconSource() {
diff --git a/test/helpers/autoStartPolicy.test.js b/test/helpers/autoStartPolicy.test.js
index 7ffbad032..4cf910dae 100644
--- a/test/helpers/autoStartPolicy.test.js
+++ b/test/helpers/autoStartPolicy.test.js
@@ -49,12 +49,15 @@ test("Windows re-enables through executableWillLaunchAtLogin when only the args
assert.equal(state.enabled, true);
});
-test("macOS reports an item awaiting approval as enabled but unapproved", () => {
+// Electron derives openAtLogin on macOS 13+ from `status == "enabled"`, so an item
+// awaiting approval necessarily reads as off. Surfacing the reason is what turns
+// that from a toggle that silently will not stick into something explainable.
+test("an item awaiting approval reads as off, with the reason surfaced", () => {
const state = resolveAutoStartState({
platform: "darwin",
- loginItemSettings: { openAtLogin: true, status: "requires-approval" },
+ loginItemSettings: { openAtLogin: false, status: "requires-approval" },
});
- assert.deepEqual(state, { enabled: true, requiresApproval: true });
+ assert.deepEqual(state, { enabled: false, requiresApproval: true });
});
test("macOS reports an approved item without prompting for approval", () => {
diff --git a/test/helpers/linuxAutostart.test.js b/test/helpers/linuxAutostart.test.js
index 5fcef2e86..ba2d28a4c 100644
--- a/test/helpers/linuxAutostart.test.js
+++ b/test/helpers/linuxAutostart.test.js
@@ -39,6 +39,16 @@ function writeEntry(filePath, contents) {
fs.writeFileSync(filePath, contents);
}
+function withExecPath(execPath, fn) {
+ const saved = process.execPath;
+ Object.defineProperty(process, "execPath", { value: execPath, configurable: true });
+ try {
+ fn();
+ } finally {
+ Object.defineProperty(process, "execPath", { value: saved, configurable: true });
+ }
+}
+
test(
"prefers APPIMAGE over process.execPath, since execPath is the ephemeral mount",
withTmpXdgDirs(async () => {
@@ -50,7 +60,7 @@ test(
);
test(
- "falls back to process.execPath for deb/rpm/tar.gz installs (no APPIMAGE set)",
+ "falls back to process.execPath when there is no AppImage and no wrapper",
withTmpXdgDirs(async () => {
const { resolveExecutablePath } = await load();
@@ -58,6 +68,36 @@ test(
})
);
+// afterPack.js renames the binary to <name>-app and puts a wrapper script in its
+// place, so pointing the entry at execPath would skip XWayland forcing, the
+// --no-sandbox fallback and the user's flags file.
+test(
+ "points deb/rpm/tar.gz installs at the launcher wrapper, not the inner binary",
+ withTmpXdgDirs(async (root) => {
+ const { resolveExecutablePath } = await load();
+
+ const installDir = path.join(root, "opt");
+ fs.mkdirSync(installDir, { recursive: true });
+ fs.writeFileSync(path.join(installDir, "open-whispr"), "#!/bin/bash\n");
+ withExecPath(path.join(installDir, "open-whispr-app"), () => {
+ assert.equal(resolveExecutablePath(), path.join(installDir, "open-whispr"));
+ });
+ })
+);
+
+test(
+ "keeps the inner binary when no wrapper sits beside it",
+ withTmpXdgDirs(async (root) => {
+ const { resolveExecutablePath } = await load();
+
+ const orphan = path.join(root, "opt", "open-whispr-app");
+ fs.mkdirSync(path.dirname(orphan), { recursive: true });
+ withExecPath(orphan, () => {
+ assert.equal(resolveExecutablePath(), orphan);
+ });
+ })
+);
+
test(
"desktop file contents quote the exec path and reference the icon by theme name",
withTmpXdgDirs(async () => {