Skip to content

Build your personal knowledge base with Trilium Notes

fix: support TRILIUM_LAUNCH_EXEC for unbundled Electron packages on Linux

shuwen.wufaef1b4a8e1a
diff --git a/apps/desktop/src/services/auto_launch.spec.ts b/apps/desktop/src/services/auto_launch.spec.ts
index 3791ee9e9e..e4488d41e1 100644
--- a/apps/desktop/src/services/auto_launch.spec.ts
+++ b/apps/desktop/src/services/auto_launch.spec.ts
@@ -80,6 +80,7 @@ beforeEach(() => {
state.wasOpenedAtLogin = false;
state.ipcOn.clear();
delete process.env.APPIMAGE;
+ delete process.env.TRILIUM_LAUNCH_EXEC;
delete process.env.XDG_CONFIG_HOME;
});
@@ -87,6 +88,7 @@ afterEach(() => {
setPlatform(ORIGINAL_PLATFORM);
setExecPath(ORIGINAL_EXECPATH);
delete process.env.APPIMAGE;
+ delete process.env.TRILIUM_LAUNCH_EXEC;
delete process.env.XDG_CONFIG_HOME;
});
@@ -165,6 +167,22 @@ describe("auto_launch", () => {
expect(content).toContain('Exec="/home/user/Apps/Trilium.AppImage"');
});
+ it("prefers TRILIUM_LAUNCH_EXEC over both APPIMAGE and execPath for the Linux Exec line", () => {
+ setPlatform("linux");
+ setExecPath("/tmp/electron");
+ process.env.APPIMAGE = "/home/user/Apps/Trilium.AppImage";
+ process.env.TRILIUM_LAUNCH_EXEC = 'electron42 "/usr/lib/triliumnext/app.asar"';
+ state.launchOnStartup = true;
+ state.hideOnAutoStart = true;
+
+ applyLaunchOnStartup();
+
+ const [, content] = state.writeFileSync.mock.calls[0] as [string, string];
+ expect(content).toContain('Exec=electron42 "/usr/lib/triliumnext/app.asar" --start-hidden');
+ expect(content).not.toContain("/tmp/electron");
+ expect(content).not.toContain("/home/user/Apps/Trilium.AppImage");
+ });
+
it("honours $XDG_CONFIG_HOME for the Linux autostart directory", () => {
setPlatform("linux");
state.launchOnStartup = true;
diff --git a/apps/desktop/src/services/auto_launch.ts b/apps/desktop/src/services/auto_launch.ts
index d59fdb877a..21835f1c8e 100644
--- a/apps/desktop/src/services/auto_launch.ts
+++ b/apps/desktop/src/services/auto_launch.ts
@@ -83,10 +83,17 @@ function getLinuxAutostartDir() {
}
function buildLinuxDesktopEntry(hidden: boolean) {
- // When packaged as an AppImage, APPIMAGE points at the bundle to relaunch;
- // otherwise fall back to the running executable.
- const exec = process.env.APPIMAGE ?? process.execPath;
- const execLine = hidden ? `Exec="${exec}" ${START_HIDDEN_FLAG}` : `Exec="${exec}"`;
+ // When packaged as an AppImage, APPIMAGE points at the bundle to relaunch.
+ // TRILIUM_LAUNCH_EXEC allows unbundled-Electron packagers (e.g. system-Electron
+ // distributions on Arch) to specify the exact Exec line (packager handles quoting).
+ // Otherwise fall back to the running executable, quoted for paths with spaces.
+ let execLine: string;
+ if (process.env.TRILIUM_LAUNCH_EXEC) {
+ execLine = hidden ? `Exec=${process.env.TRILIUM_LAUNCH_EXEC} ${START_HIDDEN_FLAG}` : `Exec=${process.env.TRILIUM_LAUNCH_EXEC}`;
+ } else {
+ const exec = process.env.APPIMAGE ?? process.execPath;
+ execLine = hidden ? `Exec="${exec}" ${START_HIDDEN_FLAG}` : `Exec="${exec}"`;
+ }
return [
"[Desktop Entry]",
"Type=Application",