Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/desktop/src/app/DesktopConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/app/DesktopEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 userDataDirName: string;
readonly legacyUserDataDirName: string;
Expand Down Expand Up @@ -245,6 +246,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
linuxWmClass: isDevelopment ? "t3code-dev" : "t3code",
linuxApplicationsDir,
desktopLauncherPath: config.desktopLauncherPath,
appImagePath: config.appImagePath,
userDataDirName,
legacyUserDataDirName,
Expand Down
13 changes: 13 additions & 0 deletions apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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,
Expand Down Expand Up @@ -254,6 +255,18 @@ describe("DesktopLinuxUrlHandler", () => {
});
});

it.effect("launches a distribution package through its own launcher", () => {
const recorded = emptyRecording();

return Effect.gen(function* () {
yield* runRegister(recorded, {
environment: { desktopLauncherPath: Option.some("/usr/bin/t3code") },
});

assert.include(recorded.files[0]?.content, 'Exec="/usr/bin/t3code" %U');
});
});

it.effect("does not rewrite the pre-ready entry while the portal can be reading it", () => {
const recorded = emptyRecording();

Expand Down
11 changes: 8 additions & 3 deletions apps/desktop/src/app/DesktopLinuxUrlHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ export const make = Effect.gen(function* () {
const iconPath = environment.path.join(iconsDir, `${environment.linuxDesktopEntryName}.png`);

const writeDesktopEntry = Effect.gen(function* () {
// 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);
// Distribution packages run the app on a shared Electron, so process.execPath
// is that Electron rather than their launcher. Inside the mounted AppImage,
// process.execPath points at a transient /tmp/.mount_* path — the handler
// must launch the AppImage itself.
const execTarget = environment.desktopLauncherPath.pipe(
Option.orElse(() => environment.appImagePath),
Option.getOrElse(() => process.execPath),
);
const content = renderUrlHandlerDesktopEntry({
displayName: environment.displayName,
execTarget,
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ describe("DesktopPreReadyPlatform", () => {
}).pipe(Effect.provideService(HostProcessPlatform, "linux"));
});

it.effect("points the early portal entry at a distribution launcher", () => {
vi.stubEnv("T3CODE_DESKTOP_LAUNCHER_PATH", " /usr/bin/t3code ");
getSwitchValueMock.mockReturnValue("");
return Effect.gen(function* () {
yield* DesktopPreReadyPlatform.make;
assert.include(writeFileSyncMock.mock.calls[0]?.[1], 'Exec="/usr/bin/t3code" %U');
}).pipe(
Effect.provideService(HostProcessPlatform, "linux"),
Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())),
);
});

it.effect(
"acquires a synchronous pre-ready layer before an asynchronous Clerk-shaped layer",
() =>
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/app/DesktopPreReadyPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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 }),
}),
Expand Down
Loading