Skip to content

Commit ed10eac

Browse files
committed
fix(desktop): support Linux distro protocol launchers
Distribution packages run T3 Code on a shared Electron, so the URL handler's Exec pointed at that bare Electron instead of the package's launcher. T3CODE_DESKTOP_LAUNCHER_PATH names the launcher, and both the early portal entry and the handler registration prefer it over APPIMAGE and process.execPath. Assisted-By: Claude Opus 5.5 <[email protected]>
1 parent 094fb23 commit ed10eac

6 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎apps/desktop/src/app/DesktopConfig.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const DesktopConfig = Config.all({
5555
otlpProtocol: Config.schema(OtlpProtocol, "T3CODE_OTLP_PROTOCOL").pipe(
5656
Config.withDefault("http/json"),
5757
),
58+
desktopLauncherPath: trimmedString("T3CODE_DESKTOP_LAUNCHER_PATH"),
5859
appImagePath: trimmedString("APPIMAGE"),
5960
disableAutoUpdate: optionalBoolean("T3CODE_DISABLE_AUTO_UPDATE"),
6061
mockUpdates: optionalBoolean("T3CODE_DESKTOP_MOCK_UPDATES"),

‎apps/desktop/src/app/DesktopEnvironment.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class DesktopEnvironment extends Context.Service<
8585
readonly linuxDesktopEntryName: string;
8686
readonly linuxWmClass: string;
8787
readonly linuxApplicationsDir: string;
88+
readonly desktopLauncherPath: Option.Option<string>;
8889
readonly appImagePath: Option.Option<string>;
8990
readonly userDataDirName: string;
9091
readonly legacyUserDataDirName: string;
@@ -245,6 +246,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
245246
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
246247
linuxWmClass: isDevelopment ? "t3code-dev" : "t3code",
247248
linuxApplicationsDir,
249+
desktopLauncherPath: config.desktopLauncherPath,
248250
appImagePath: config.appImagePath,
249251
userDataDirName,
250252
legacyUserDataDirName,

‎apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const makeEnvironment = (path: Path.Path, overrides: Record<string, unknown> = {
3232
linuxDesktopEntryName: "com.t3tools.T3Code.desktop",
3333
linuxWmClass: "t3code",
3434
linuxApplicationsDir: "/home/alice/.local/share/applications",
35+
desktopLauncherPath: Option.none(),
3536
appImagePath: Option.some("/home/alice/Applications/T3-Code.AppImage"),
3637
path,
3738
...overrides,
@@ -254,6 +255,18 @@ describe("DesktopLinuxUrlHandler", () => {
254255
});
255256
});
256257

258+
it.effect("launches a distribution package through its own launcher", () => {
259+
const recorded = emptyRecording();
260+
261+
return Effect.gen(function* () {
262+
yield* runRegister(recorded, {
263+
environment: { desktopLauncherPath: Option.some("/usr/bin/t3code") },
264+
});
265+
266+
assert.include(recorded.files[0]?.content, 'Exec="/usr/bin/t3code" %U');
267+
});
268+
});
269+
257270
it.effect("does not rewrite the pre-ready entry while the portal can be reading it", () => {
258271
const recorded = emptyRecording();
259272

‎apps/desktop/src/app/DesktopLinuxUrlHandler.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,14 @@ export const make = Effect.gen(function* () {
126126
const iconPath = environment.path.join(iconsDir, `${environment.linuxDesktopEntryName}.png`);
127127

128128
const writeDesktopEntry = Effect.gen(function* () {
129-
// Inside the mounted AppImage, process.execPath points at a transient
130-
// /tmp/.mount_* path — the handler must launch the AppImage itself.
131-
const execTarget = Option.getOrElse(environment.appImagePath, () => process.execPath);
129+
// Distribution packages run the app on a shared Electron, so process.execPath
130+
// is that Electron rather than their launcher. Inside the mounted AppImage,
131+
// process.execPath points at a transient /tmp/.mount_* path — the handler
132+
// must launch the AppImage itself.
133+
const execTarget = environment.desktopLauncherPath.pipe(
134+
Option.orElse(() => environment.appImagePath),
135+
Option.getOrElse(() => process.execPath),
136+
);
132137
const content = renderUrlHandlerDesktopEntry({
133138
displayName: environment.displayName,
134139
execTarget,

‎apps/desktop/src/app/DesktopPreReadyPlatform.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ describe("DesktopPreReadyPlatform", () => {
156156
}).pipe(Effect.provideService(HostProcessPlatform, "linux"));
157157
});
158158

159+
it.effect("points the early portal entry at a distribution launcher", () => {
160+
vi.stubEnv("T3CODE_DESKTOP_LAUNCHER_PATH", " /usr/bin/t3code ");
161+
getSwitchValueMock.mockReturnValue("");
162+
return Effect.gen(function* () {
163+
yield* DesktopPreReadyPlatform.make;
164+
assert.include(writeFileSyncMock.mock.calls[0]?.[1], 'Exec="/usr/bin/t3code" %U');
165+
}).pipe(
166+
Effect.provideService(HostProcessPlatform, "linux"),
167+
Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())),
168+
);
169+
});
170+
159171
it.effect(
160172
"acquires a synchronous pre-ready layer before an asynchronous Clerk-shaped layer",
161173
() =>

‎apps/desktop/src/app/DesktopPreReadyPlatform.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ export const make = Effect.gen(function* () {
9797
isDevelopment: linux.isDevelopment,
9898
appVersion: Electron.app.getVersion(),
9999
}).displayName,
100-
execTarget: process.env.APPIMAGE?.trim() || process.execPath,
100+
execTarget:
101+
process.env.T3CODE_DESKTOP_LAUNCHER_PATH?.trim() ||
102+
process.env.APPIMAGE?.trim() ||
103+
process.execPath,
101104
scheme: ElectronProtocol.getDesktopScheme(linux.isDevelopment),
102105
...(iconPath === undefined ? {} : { iconPath }),
103106
}),

0 commit comments

Comments
 (0)