Skip to content
TypeScript

fix(desktop): support Linux distro protocol launchers (#24591)

Julius Marminge7fd2e09e381a
diff --git a/apps/desktop/src/app/DesktopConfig.ts b/apps/desktop/src/app/DesktopConfig.ts
index 773ea24509c..11f975a6b86 100644
--- a/apps/desktop/src/app/DesktopConfig.ts
+++ b/apps/desktop/src/app/DesktopConfig.ts
@@ -55,6 +55,7 @@ export const DesktopConfig = Config.all({
otlpProtocol: Config.schema(OtlpProtocol, "T3CODE_OTLP_PROTOCOL").pipe(
Config.withDefault("http/json"),
),
+ desktopLauncherPath: trimmedString("T3CODE_DESKTOP_LAUNCHER_PATH"),
appImagePath: trimmedString("APPIMAGE"),
disableAutoUpdate: optionalBoolean("T3CODE_DISABLE_AUTO_UPDATE"),
mockUpdates: optionalBoolean("T3CODE_DESKTOP_MOCK_UPDATES"),
diff --git a/apps/desktop/src/app/DesktopEnvironment.ts b/apps/desktop/src/app/DesktopEnvironment.ts
index ecf08255feb..1066198b8f6 100644
--- a/apps/desktop/src/app/DesktopEnvironment.ts
+++ b/apps/desktop/src/app/DesktopEnvironment.ts
@@ -77,6 +77,7 @@ export class DesktopEnvironment extends Context.Service<
readonly linuxDesktopEntryName: string;
readonly linuxWmClass: string;
readonly linuxApplicationsDir: string;
+ readonly desktopLauncherPath: Option.Option<string>;
readonly appImagePath: Option.Option<string>;
readonly defaultDesktopSettings: DesktopAppSettings.DesktopSettings;
readonly runtimeInfo: DesktopRuntimeInfo;
@@ -233,6 +234,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
linuxWmClass: isDevelopment ? "t3code-dev" : "t3code",
linuxApplicationsDir,
+ desktopLauncherPath: config.desktopLauncherPath,
appImagePath: config.appImagePath,
defaultDesktopSettings: DesktopAppSettings.resolveDefaultDesktopSettings(input.appVersion),
runtimeInfo: resolveDesktopRuntimeInfo({
diff --git a/apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts b/apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
index 854f43c5623..e9766c2174d 100644
--- a/apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
+++ b/apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
@@ -31,6 +31,7 @@ const makeEnvironment = (path: Path.Path, overrides: Record<string, unknown> = {
linuxDesktopEntryName: "com.t3tools.T3Code.desktop",
linuxWmClass: "t3code",
linuxApplicationsDir: "/home/alice/.local/share/applications",
+ desktopLauncherPath: Option.none(),
appImagePath: Option.some("/home/alice/Applications/T3-Code.AppImage"),
path,
...overrides,
@@ -228,6 +229,18 @@ describe("DesktopLinuxUrlHandler", () => {
});
});
+ it.effect("launches a distribution package through its configured launcher", () => {
+ const recorded = emptyRecording();
+
+ return Effect.gen(function* () {
+ yield* runRegister(recorded, {
+ environment: { desktopLauncherPath: Option.some("/opt/T3 Code/t3code") },
+ });
+
+ assert.include(recorded.files[0]?.content, 'Exec="/opt/T3 Code/t3code" %U');
+ });
+ });
+
it.effect("does not rewrite the pre-ready entry while the portal can be reading it", () => {
const recorded = emptyRecording();
diff --git a/apps/desktop/src/app/DesktopLinuxUrlHandler.ts b/apps/desktop/src/app/DesktopLinuxUrlHandler.ts
index e03418964e3..785dc4e0b90 100644
--- a/apps/desktop/src/app/DesktopLinuxUrlHandler.ts
+++ b/apps/desktop/src/app/DesktopLinuxUrlHandler.ts
@@ -141,9 +141,14 @@ export const make = Effect.gen(function* () {
const themeIconDir = environment.path.join(hicolorDir, LINUX_THEME_ICON_SIZE, "apps");
const writeDesktopEntry = Effect.gen(function* () {
+ // Distribution packages that run on a shared Electron set
+ // T3CODE_DESKTOP_LAUNCHER_PATH, because process.execPath is that Electron.
// Inside the mounted AppImage, process.execPath points at a transient
// /tmp/.mount_* path — the handler must launch the AppImage itself.
- const execTarget = Option.getOrElse(environment.appImagePath, () => process.execPath);
+ const execTarget = environment.desktopLauncherPath.pipe(
+ Option.orElse(() => environment.appImagePath),
+ Option.getOrElse(() => process.execPath),
+ );
const content = renderUrlHandlerDesktopEntry({
displayName: environment.displayName,
execTarget,
diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
index 143a6e5fd87..f2b176ee376 100644
--- a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
+++ b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
@@ -166,6 +166,28 @@ describe("DesktopPreReadyPlatform", () => {
).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())));
});
+ it.effect("points the early portal entry at a configured distribution launcher", () => {
+ vi.stubEnv("VITE_DEV_SERVER_URL", "");
+ vi.stubEnv("XDG_DATA_HOME", "/xdg");
+ vi.stubEnv("APPIMAGE", "/Applications/current.AppImage");
+ vi.stubEnv("T3CODE_DESKTOP_LAUNCHER_PATH", " /opt/T3 Code/t3code ");
+ getSwitchValueMock.mockReturnValue("");
+
+ return Effect.scoped(
+ Effect.gen(function* () {
+ yield* Layer.build(
+ DesktopPreReadyPlatform.layer.pipe(
+ Layer.provide(Layer.succeed(HostProcess.Platform, "linux")),
+ ),
+ );
+ const entry = writeFileSyncMock.mock.calls.find(
+ ([path]) => path === "/xdg/applications/com.t3tools.T3Code.desktop",
+ )?.[1];
+ assert.include(entry, 'Exec="/opt/T3 Code/t3code" %U');
+ }),
+ ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())));
+ });
+
it.effect(
"acquires a synchronous pre-ready layer before an asynchronous Clerk-shaped layer",
() =>
diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.ts
index 58670439a52..4179ec0636e 100644
--- a/apps/desktop/src/app/DesktopPreReadyPlatform.ts
+++ b/apps/desktop/src/app/DesktopPreReadyPlatform.ts
@@ -109,7 +109,10 @@ export const make = Effect.gen(function* () {
isDevelopment: linux.isDevelopment,
appVersion: Electron.app.getVersion(),
}).displayName,
- execTarget: process.env.APPIMAGE?.trim() || process.execPath,
+ execTarget:
+ process.env.T3CODE_DESKTOP_LAUNCHER_PATH?.trim() ||
+ process.env.APPIMAGE?.trim() ||
+ process.execPath,
scheme: ElectronProtocol.getDesktopScheme(linux.isDevelopment),
...(iconPath === undefined ? {} : { iconPath }),
}),