The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): make Linux URL handlers discoverable with the app icon (#8673)
Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>
André Lima committed
Sep 28, 2026 at 23:40 UTC
7733bc839e23e19467a70b11a0bcedf6ffe8f1a3
4 files changed
+311
-35
apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
+168
-30
@@ -1,23 +1,29 @@
1
import { assert, describe, it } from "@effect/vitest";
2
+import * as Deferred from "effect/Deferred";
3
import * as Effect from "effect/Effect";
4
+import * as Fiber from "effect/Fiber";
5
import * as FileSystem from "effect/FileSystem";
6
import * as Layer from "effect/Layer";
7
import * as Option from "effect/Option";
8
+import * as Path from "effect/Path";
9
import * as PlatformError from "effect/PlatformError";
10
import * as Sink from "effect/Sink";
11
import * as Stream from "effect/Stream";
12
+import * as TestClock from "effect/testing/TestClock";
13
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
14
15
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
16
+import * as DesktopAssets from "./DesktopAssets.ts";
17
import * as DesktopLinuxUrlHandler from "./DesktopLinuxUrlHandler.ts";
18
19
interface RecordedRegistration {
20
readonly directories: string[];
21
readonly files: Array<{ readonly path: string; readonly content: string }>;
22
readonly commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }>;
23
+ readonly copies: Array<{ readonly source: string; readonly destination: string }>;
24
}
25
20
-const makeEnvironment = (overrides: Record<string, unknown> = {}) =>
26
+const makeEnvironment = (path: Path.Path, overrides: Record<string, unknown> = {}) =>
27
DesktopEnvironment.DesktopEnvironment.of({
28
platform: "linux",
29
isPackaged: true,
@@ -27,14 +33,14 @@ const makeEnvironment = (overrides: Record<string, unknown> = {}) =>
33
linuxWmClass: "t3code",
34
linuxApplicationsDir: "/home/alice/.local/share/applications",
35
appImagePath: Option.some("/home/alice/Applications/T3-Code.AppImage"),
30
- path: { join: (...parts: ReadonlyArray<string>) => parts.join("/") },
36
+ path,
37
...overrides,
38
} as unknown as DesktopEnvironment.DesktopEnvironment["Service"]);
39
34
-const mockProcess = (exitCode: number) =>
40
+const mockProcess = (exitCode: number, stalled = false) =>
41
ChildProcessSpawner.makeHandle({
42
pid: ChildProcessSpawner.ProcessId(1),
37
- exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)),
43
+ exitCode: stalled ? Effect.never : Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)),
44
isRunning: Effect.succeed(false),
45
kill: () => Effect.void,
46
unref: Effect.succeed(Effect.void),
@@ -50,16 +56,41 @@ const makeHandlerLayer = (
56
recorded: RecordedRegistration,
57
input: {
58
readonly environment?: Record<string, unknown>;
59
+ readonly updateDesktopDatabaseExitCode?: number;
60
+ readonly updateDesktopDatabaseStalled?: boolean;
61
+ readonly updateDesktopDatabaseStarted?: Deferred.Deferred<void>;
62
readonly xdgMimeExitCode?: number;
63
readonly writeError?: PlatformError.PlatformError;
64
readonly existingEntry?: string;
65
+ readonly iconSource?: string;
66
+ readonly iconCopyError?: PlatformError.PlatformError;
67
} = {},
68
) =>
69
DesktopLinuxUrlHandler.layer.pipe(
70
Layer.provide(
71
Layer.mergeAll(
61
- Layer.succeed(DesktopEnvironment.DesktopEnvironment, makeEnvironment(input.environment)),
72
+ Layer.effect(
73
+ DesktopEnvironment.DesktopEnvironment,
74
+ Path.Path.pipe(
75
+ Effect.map((path) => makeEnvironment(path, input.environment)),
76
+ Effect.provide(Path.layer),
77
+ ),
78
+ ),
79
+ Layer.succeed(DesktopAssets.DesktopAssets, {
80
+ iconPaths: Effect.succeed({
81
+ png: Option.fromUndefinedOr(input.iconSource),
82
+ ico: Option.none(),
83
+ icns: Option.none(),
84
+ }),
85
+ resolveResourcePath: () => Effect.succeedNone,
86
+ }),
87
FileSystem.layerNoop({
88
+ copyFile: (source, destination) =>
89
+ input.iconCopyError
90
+ ? Effect.fail(input.iconCopyError)
91
+ : Effect.sync(() => {
92
+ recorded.copies.push({ source, destination });
93
+ }),
94
readFileString: () => Effect.succeed(input.existingEntry ?? ""),
95
makeDirectory: (path) =>
96
Effect.sync(() => {
@@ -79,11 +110,31 @@ const makeHandlerLayer = (
110
readonly command: string;
111
readonly args: ReadonlyArray<string>;
112
};
113
+ if (childProcess.command === "update-desktop-database") {
114
+ assert.isTrue(
115
+ recorded.files.length > 0 || input.existingEntry !== undefined,
116
+ "the desktop entry must exist before refreshing the MIME cache",
117
+ );
118
+ }
119
recorded.commands.push({
120
command: childProcess.command,
121
args: childProcess.args,
122
});
86
- return Effect.succeed(mockProcess(input.xdgMimeExitCode ?? 0));
123
+ const exitCode =
124
+ childProcess.command === "update-desktop-database"
125
+ ? (input.updateDesktopDatabaseExitCode ?? 0)
126
+ : (input.xdgMimeExitCode ?? 0);
127
+ const handle = mockProcess(
128
+ exitCode,
129
+ childProcess.command === "update-desktop-database" &&
130
+ input.updateDesktopDatabaseStalled === true,
131
+ );
132
+ return childProcess.command === "update-desktop-database" &&
133
+ input.updateDesktopDatabaseStarted
134
+ ? Deferred.succeed(input.updateDesktopDatabaseStarted, undefined).pipe(
135
+ Effect.as(handle),
136
+ )
137
+ : Effect.succeed(handle);
138
}),
139
),
140
),
@@ -103,6 +154,7 @@ const emptyRecording = (): RecordedRegistration => ({
154
directories: [],
155
files: [],
156
commands: [],
157
+ copies: [],
158
});
159
160
describe("DesktopLinuxUrlHandler", () => {
@@ -111,6 +163,7 @@ describe("DesktopLinuxUrlHandler", () => {
163
displayName: "T3 Code (Nightly)",
164
execTarget: '/home/al ice/Apps/T3 "100%" $HOME\\x.AppImage',
165
scheme: "t3code",
166
+ iconPath: "/home/al ice/icons/T3\\x.png",
167
});
168
169
assert.include(entry, "[Desktop Entry]");
@@ -125,6 +178,7 @@ describe("DesktopLinuxUrlHandler", () => {
178
assert.include(entry, "NoDisplay=true");
179
assert.notInclude(entry, "StartupWMClass=");
180
assert.include(entry, "MimeType=x-scheme-handler/t3code;");
181
+ assert.include(entry, "Icon=/home/al ice/icons/T3\\\\x.png");
182
});
183
184
it("carries structured context on registration errors", () => {
@@ -154,31 +208,38 @@ describe("DesktopLinuxUrlHandler", () => {
208
);
209
});
210
157
- it.effect("writes the handler entry and claims the scheme default via xdg-mime", () => {
158
- const recorded = emptyRecording();
211
+ it.effect(
212
+ "writes the handler entry, refreshes the MIME cache, and claims the scheme default",
213
+ () => {
214
+ const recorded = emptyRecording();
215
160
- return Effect.gen(function* () {
161
- yield* runRegister(recorded);
216
+ return Effect.gen(function* () {
217
+ yield* runRegister(recorded);
218
163
- assert.deepEqual(recorded.directories, ["/home/alice/.local/share/applications"]);
164
- assert.equal(recorded.files.length, 1);
165
- assert.equal(
166
- recorded.files[0]?.path,
167
- "/home/alice/.local/share/applications/com.t3tools.T3Code.desktop",
168
- );
169
- assert.include(
170
- recorded.files[0]?.content,
171
- 'Exec="/home/alice/Applications/T3-Code.AppImage" %U',
172
- );
173
- assert.include(recorded.files[0]?.content, "MimeType=x-scheme-handler/t3code;");
174
- assert.deepEqual(recorded.commands, [
175
- {
176
- command: "xdg-mime",
177
- args: ["default", "com.t3tools.T3Code.desktop", "x-scheme-handler/t3code"],
178
- },
179
- ]);
180
- });
181
- });
219
+ assert.deepEqual(recorded.directories, ["/home/alice/.local/share/applications"]);
220
+ assert.equal(recorded.files.length, 1);
221
+ assert.equal(
222
+ recorded.files[0]?.path,
223
+ "/home/alice/.local/share/applications/com.t3tools.T3Code.desktop",
224
+ );
225
+ assert.include(
226
+ recorded.files[0]?.content,
227
+ 'Exec="/home/alice/Applications/T3-Code.AppImage" %U',
228
+ );
229
+ assert.include(recorded.files[0]?.content, "MimeType=x-scheme-handler/t3code;");
230
+ assert.deepEqual(recorded.commands, [
231
+ {
232
+ command: "update-desktop-database",
233
+ args: ["/home/alice/.local/share/applications"],
234
+ },
235
+ {
236
+ command: "xdg-mime",
237
+ args: ["default", "com.t3tools.T3Code.desktop", "x-scheme-handler/t3code"],
238
+ },
239
+ ]);
240
+ });
241
+ },
242
+ );
243
244
it.effect("falls back to the process executable outside an AppImage", () => {
245
const recorded = emptyRecording();
@@ -202,12 +263,63 @@ describe("DesktopLinuxUrlHandler", () => {
263
displayName: "T3 Code (Alpha)",
264
execTarget: "/home/alice/Applications/T3-Code.AppImage",
265
scheme: "t3code",
266
+ iconPath: "/home/alice/.local/share/icons/com.t3tools.T3Code.desktop.png",
267
}),
268
});
269
270
assert.deepEqual(recorded.files, []);
271
assert.deepEqual(recorded.directories, []);
210
- assert.equal(recorded.commands.length, 1);
272
+ assert.deepEqual(recorded.commands, [
273
+ {
274
+ command: "update-desktop-database",
275
+ args: ["/home/alice/.local/share/applications"],
276
+ },
277
+ {
278
+ command: "xdg-mime",
279
+ args: ["default", "com.t3tools.T3Code.desktop", "x-scheme-handler/t3code"],
280
+ },
281
+ ]);
282
+ });
283
+ });
284
+
285
+ it.effect("installs a persistent icon even when the desktop entry is already current", () => {
286
+ const recorded = emptyRecording();
287
+ const iconPath = "/home/alice/.local/share/icons/com.t3tools.T3Code.desktop.png";
288
+ return Effect.gen(function* () {
289
+ yield* runRegister(recorded, {
290
+ iconSource: "/tmp/.mount_T3/resources/icon.png",
291
+ existingEntry: DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
292
+ displayName: "T3 Code (Alpha)",
293
+ execTarget: "/home/alice/Applications/T3-Code.AppImage",
294
+ scheme: "t3code",
295
+ iconPath,
296
+ }),
297
+ });
298
+ assert.deepEqual(recorded.files, []);
299
+ assert.deepEqual(recorded.copies, [
300
+ { source: "/tmp/.mount_T3/resources/icon.png", destination: iconPath },
301
+ ]);
302
+ assert.equal(recorded.commands.at(-1)?.command, "xdg-mime");
303
+ });
304
+ });
305
+
306
+ it.effect("still registers the handler when copying its icon fails", () => {
307
+ const recorded = emptyRecording();
308
+ return Effect.gen(function* () {
309
+ yield* runRegister(recorded, {
310
+ iconSource: "/tmp/.mount_T3/resources/icon.png",
311
+ iconCopyError: PlatformError.systemError({
312
+ _tag: "PermissionDenied",
313
+ module: "FileSystem",
314
+ method: "copyFile",
315
+ description: "read-only icon directory",
316
+ }),
317
+ });
318
+ assert.equal(recorded.files.length, 1);
319
+ assert.deepEqual(
320
+ recorded.commands.map(({ command }) => command),
321
+ ["update-desktop-database", "xdg-mime"],
322
+ );
323
});
324
});
325
@@ -234,10 +346,12 @@ describe("DesktopLinuxUrlHandler", () => {
346
});
347
348
it.effect("never fails startup when registration cannot complete", () => {
349
+ const desktopDatabaseFailed = emptyRecording();
350
const xdgMimeFailed = emptyRecording();
351
const writeFailed = emptyRecording();
352
353
return Effect.gen(function* () {
354
+ yield* runRegister(desktopDatabaseFailed, { updateDesktopDatabaseExitCode: 1 });
355
yield* runRegister(xdgMimeFailed, { xdgMimeExitCode: 1 });
356
yield* runRegister(writeFailed, {
357
writeError: PlatformError.systemError({
@@ -249,8 +363,32 @@ describe("DesktopLinuxUrlHandler", () => {
363
}),
364
});
365
366
+ assert.deepEqual(
367
+ desktopDatabaseFailed.commands.map(({ command }) => command),
368
+ ["update-desktop-database", "xdg-mime"],
369
+ );
370
assert.equal(xdgMimeFailed.files.length, 1);
371
assert.deepEqual(writeFailed.commands, []);
372
});
373
});
374
+
375
+ it.effect("continues to xdg-mime when the desktop MIME cache refresh stalls", () =>
376
+ Effect.gen(function* () {
377
+ const recorded = emptyRecording();
378
+ const started = yield* Deferred.make<void>();
379
+ const registration = yield* runRegister(recorded, {
380
+ updateDesktopDatabaseStalled: true,
381
+ updateDesktopDatabaseStarted: started,
382
+ }).pipe(Effect.forkChild);
383
+
384
+ yield* Deferred.await(started);
385
+ yield* TestClock.adjust("5 seconds");
386
+ yield* Fiber.join(registration);
387
+
388
+ assert.deepEqual(
389
+ recorded.commands.map(({ command }) => command),
390
+ ["update-desktop-database", "xdg-mime"],
391
+ );
392
+ }),
393
+ );
394
});
apps/desktop/src/app/DesktopLinuxUrlHandler.ts
+86
-4
@@ -8,6 +8,7 @@ import * as ChildProcess from "effect/unstable/process/ChildProcess";
8
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
9
10
import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
11
+import * as DesktopAssets from "./DesktopAssets.ts";
12
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
13
import { makeComponentLogger } from "./DesktopObservability.ts";
14
@@ -17,9 +18,9 @@ import { makeComponentLogger } from "./DesktopObservability.ts";
18
// Electron's app.setAsDefaultProtocolClient resolves the desktop id from
19
// setDesktopName, which cannot match those files — so the browser keeps
20
// prompting "Choose an application" for every OAuth callback. Instead, write
20
-// our own handler entry pointing at the current AppImage and claim the
21
-// scheme default via xdg-mime, exactly what the file manager's "set as
22
-// default" checkbox would record in mimeapps.list.
21
+// our own handler entry pointing at the current AppImage, refresh the desktop
22
+// MIME cache so desktop environments recognize that entry as a handler, and
23
+// use xdg-mime to record it as the scheme default in mimeapps.list.
24
const { logInfo, logWarning } = makeComponentLogger("desktop-linux-url-handler");
25
26
export class DesktopLinuxUrlHandlerRegistrationError extends Schema.TaggedError<DesktopLinuxUrlHandlerRegistrationError>()(
@@ -40,6 +41,23 @@ export class DesktopLinuxUrlHandlerRegistrationError extends Schema.TaggedError<
41
42
const isRegistrationError = Schema.is(DesktopLinuxUrlHandlerRegistrationError);
43
44
+export class DesktopLinuxUrlHandlerCacheRefreshError extends Schema.TaggedError<DesktopLinuxUrlHandlerCacheRefreshError>()(
45
+ "DesktopLinuxUrlHandlerCacheRefreshError",
46
+ {
47
+ applicationsDir: Schema.String,
48
+ exitCode: Schema.optionalKey(Schema.Number),
49
+ cause: Schema.optionalKey(Schema.Defect()),
50
+ },
51
+) {
52
+ override get message(): string {
53
+ const exitCode =
54
+ this.exitCode === undefined ? "" : `, update-desktop-database exit code ${this.exitCode}`;
55
+ return `Failed to refresh the desktop MIME cache at ${this.applicationsDir}${exitCode}.`;
56
+ }
57
+}
58
+
59
+const isCacheRefreshError = Schema.is(DesktopLinuxUrlHandlerCacheRefreshError);
60
+
61
const escapeDesktopEntryString = (value: string): string =>
62
value
63
.replaceAll("\\", "\\\\")
@@ -63,18 +81,20 @@ export function escapeDesktopEntryExecArgument(value: string): string {
81
return escapeDesktopEntryString(`"${quoted}"`);
82
}
83
66
-// The AppImage integration entry owns the window identity and icon. This
84
+// The AppImage integration entry owns the window identity. This
85
// hidden URL-only entry must not compete with it for StartupWMClass matching.
86
export function renderUrlHandlerDesktopEntry(input: {
87
readonly displayName: string;
88
readonly execTarget: string;
89
readonly scheme: string;
90
+ readonly iconPath?: string;
91
}): string {
92
return [
93
"[Desktop Entry]",
94
"Type=Application",
95
`Name=${escapeDesktopEntryString(input.displayName)}`,
96
`Exec=${escapeDesktopEntryExecArgument(input.execTarget)} %U`,
97
+ ...(input.iconPath === undefined ? [] : [`Icon=${escapeDesktopEntryString(input.iconPath)}`]),
98
"Terminal=false",
99
"NoDisplay=true",
100
"StartupNotify=false",
@@ -95,12 +115,15 @@ export const make = Effect.gen(function* () {
115
const environment = yield* DesktopEnvironment.DesktopEnvironment;
116
const fileSystem = yield* FileSystem.FileSystem;
117
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
118
+ const assets = yield* DesktopAssets.DesktopAssets;
119
120
const scheme = ElectronProtocol.getDesktopScheme(environment.isDevelopment);
121
const desktopEntryPath = environment.path.join(
122
environment.linuxApplicationsDir,
123
environment.linuxDesktopEntryName,
124
);
125
+ const iconsDir = environment.path.join(environment.linuxApplicationsDir, "..", "icons");
126
+ const iconPath = environment.path.join(iconsDir, `${environment.linuxDesktopEntryName}.png`);
127
128
const writeDesktopEntry = Effect.gen(function* () {
129
// Inside the mounted AppImage, process.execPath points at a transient
@@ -110,6 +133,7 @@ export const make = Effect.gen(function* () {
133
displayName: environment.displayName,
134
execTarget,
135
scheme,
136
+ ...(environment.isPackaged ? { iconPath } : {}),
137
});
138
// Pre-ready setup normally wrote this already. Avoid truncating a valid
139
// entry while the portal may be reading it during startup.
@@ -131,6 +155,37 @@ export const make = Effect.gen(function* () {
155
),
156
);
157
158
+ const updateDesktopDatabase = Effect.scoped(
159
+ Effect.gen(function* () {
160
+ const command = ChildProcess.make(
161
+ "update-desktop-database",
162
+ [environment.linuxApplicationsDir],
163
+ {
164
+ stdin: "ignore",
165
+ stdout: "ignore",
166
+ stderr: "ignore",
167
+ },
168
+ );
169
+ const handle = yield* spawner.spawn(command);
170
+ const exitCode = yield* handle.exitCode.pipe(Effect.timeout("5 seconds"));
171
+ if (exitCode !== 0) {
172
+ return yield* new DesktopLinuxUrlHandlerCacheRefreshError({
173
+ applicationsDir: environment.linuxApplicationsDir,
174
+ exitCode,
175
+ });
176
+ }
177
+ }),
178
+ ).pipe(
179
+ Effect.mapError((error) =>
180
+ isCacheRefreshError(error)
181
+ ? error
182
+ : new DesktopLinuxUrlHandlerCacheRefreshError({
183
+ applicationsDir: environment.linuxApplicationsDir,
184
+ cause: error,
185
+ }),
186
+ ),
187
+ );
188
+
189
const setDefaultHandler = Effect.scoped(
190
Effect.gen(function* () {
191
const command = ChildProcess.make(
@@ -170,6 +225,33 @@ export const make = Effect.gen(function* () {
225
}
226
yield* writeDesktopEntry;
227
if (!environment.isPackaged) return;
228
+
229
+ yield* Effect.gen(function* () {
230
+ const { png } = yield* assets.iconPaths;
231
+ if (Option.isNone(png)) return;
232
+ // The AppImage mount is temporary; the chooser needs the icon after exit.
233
+ yield* fileSystem.makeDirectory(iconsDir, { recursive: true });
234
+ yield* fileSystem.copyFile(png.value, iconPath);
235
+ }).pipe(
236
+ Effect.catch((error) =>
237
+ logWarning("URL handler icon copy failed", { iconPath, category: error.reason._tag }),
238
+ ),
239
+ );
240
+
241
+ yield* updateDesktopDatabase.pipe(
242
+ // Some MIME implementations, including GIO, use mimeinfo.cache to verify
243
+ // that a desktop entry is associated with a scheme. Cache refresh is
244
+ // independently best-effort so a missing update-desktop-database executable
245
+ // does not prevent xdg-mime from recording the requested default.
246
+ Effect.catch((error) =>
247
+ logWarning("desktop MIME cache refresh failed", {
248
+ applicationsDir: environment.linuxApplicationsDir,
249
+ message: error.message,
250
+ ...(error.exitCode === undefined ? {} : { exitCode: error.exitCode }),
251
+ }),
252
+ ),
253
+ );
254
+
255
yield* setDefaultHandler;
256
yield* logInfo("registered URL scheme handler", { scheme });
257
}).pipe(
apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
+34
-1
@@ -13,6 +13,7 @@ const {
13
setDesktopNameMock,
14
mkdirSyncMock,
15
writeFileSyncMock,
16
+ copyFileSyncMock,
17
} = vi.hoisted(() => ({
18
appendSwitchMock: vi.fn(),
19
getSwitchValueMock: vi.fn(),
@@ -21,12 +22,15 @@ const {
22
setDesktopNameMock: vi.fn(),
23
mkdirSyncMock: vi.fn(),
24
writeFileSyncMock: vi.fn(),
25
+ copyFileSyncMock: vi.fn(),
26
}));
27
28
vi.mock("electron", () => ({
29
app: {
30
setDesktopName: setDesktopNameMock,
31
getVersion: () => "0.0.37",
32
+ isPackaged: true,
33
+ getAppPath: () => "/tmp/.mount_T3/resources/app.asar",
34
commandLine: {
35
appendSwitch: appendSwitchMock,
36
getSwitchValue: getSwitchValueMock,
@@ -42,6 +46,7 @@ vi.mock("node:fs", () => ({
46
readFileSync: () => "{}",
47
mkdirSync: mkdirSyncMock,
48
writeFileSync: writeFileSyncMock,
49
+ copyFileSync: copyFileSyncMock,
50
}));
51
52
import * as DesktopPreReadyPlatform from "./DesktopPreReadyPlatform.ts";
@@ -55,6 +60,7 @@ describe("DesktopPreReadyPlatform", () => {
60
setDesktopNameMock.mockReset();
61
mkdirSyncMock.mockReset();
62
writeFileSyncMock.mockReset();
63
+ copyFileSyncMock.mockReset();
64
});
65
66
it.effect("preserves an explicit Linux password-store switch", () => {
@@ -85,6 +91,10 @@ describe("DesktopPreReadyPlatform", () => {
91
getSwitchValueMock.mockReturnValue("");
92
let desktopName = "t3code.desktop";
93
let desktopEntry = previousEntry;
94
+ let iconInstalled = false;
95
+ copyFileSyncMock.mockImplementation((_source: string, destination: string) => {
96
+ iconInstalled = destination === "/xdg/icons/com.t3tools.T3Code.desktop.png";
97
+ });
98
setDesktopNameMock.mockImplementation((name: string) => {
99
desktopName = name;
100
});
@@ -94,7 +104,11 @@ describe("DesktopPreReadyPlatform", () => {
104
105
return Effect.scoped(
106
Effect.gen(function* () {
97
- const portalIdentity = Promise.resolve().then(() => ({ desktopName, desktopEntry }));
107
+ const portalIdentity = Promise.resolve().then(() => ({
108
+ desktopName,
109
+ desktopEntry,
110
+ iconInstalled,
111
+ }));
112
yield* Layer.build(
113
DesktopPreReadyPlatform.layer.pipe(
114
Layer.provide(Layer.succeed(HostProcessPlatform, "linux")),
@@ -105,6 +119,11 @@ describe("DesktopPreReadyPlatform", () => {
119
assert.include(identity.desktopEntry ?? "", 'Exec="/Applications/current.AppImage" %U');
120
assert.include(identity.desktopEntry ?? "", "Name=T3 Code (Alpha)");
121
assert.include(identity.desktopEntry ?? "", "MimeType=x-scheme-handler/t3code;");
122
+ assert.include(
123
+ identity.desktopEntry ?? "",
124
+ "Icon=/xdg/icons/com.t3tools.T3Code.desktop.png",
125
+ );
126
+ assert.isTrue(identity.iconInstalled);
127
}),
128
).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())));
129
},
@@ -123,6 +142,20 @@ describe("DesktopPreReadyPlatform", () => {
142
);
143
});
144
145
+ it.effect("still prepares the portal entry when the bundled icon cannot be copied", () => {
146
+ getSwitchValueMock.mockReturnValue("");
147
+ copyFileSyncMock.mockImplementation(() => {
148
+ throw new Error("missing bundled icon");
149
+ });
150
+ return Effect.gen(function* () {
151
+ yield* DesktopPreReadyPlatform.make;
152
+ const contents = writeFileSyncMock.mock.calls[0]?.[1];
153
+ assert.include(contents, "MimeType=x-scheme-handler/t3code;");
154
+ assert.include(contents, "Icon=");
155
+ assert.equal(setDesktopNameMock.mock.calls.length, 1);
156
+ }).pipe(Effect.provideService(HostProcessPlatform, "linux"));
157
+ });
158
+
159
it.effect(
160
"acquires a synchronous pre-ready layer before an asynchronous Clerk-shaped layer",
161
() =>
apps/desktop/src/app/DesktopPreReadyPlatform.ts
+23
@@ -68,6 +68,28 @@ export const make = Effect.gen(function* () {
68
"applications",
69
);
70
NodeFS.mkdirSync(applicationsDir, { recursive: true });
71
+ const iconPath = Electron.app.isPackaged
72
+ ? NodePath.posix.join(
73
+ applicationsDir,
74
+ "..",
75
+ "icons",
76
+ `${linux.linuxDesktopEntryName}.png`,
77
+ )
78
+ : undefined;
79
+ if (iconPath !== undefined) {
80
+ try {
81
+ NodeFS.mkdirSync(NodePath.posix.dirname(iconPath), { recursive: true });
82
+ NodeFS.copyFileSync(
83
+ NodePath.posix.join(
84
+ Electron.app.getAppPath(),
85
+ "apps/desktop/prod-resources/icon.png",
86
+ ),
87
+ iconPath,
88
+ );
89
+ } catch {
90
+ // Icon installation is optional; registration retries after readiness.
91
+ }
92
+ }
93
NodeFS.writeFileSync(
94
NodePath.posix.join(applicationsDir, linux.linuxDesktopEntryName),
95
renderUrlHandlerDesktopEntry({
@@ -77,6 +99,7 @@ export const make = Effect.gen(function* () {
99
}).displayName,
100
execTarget: process.env.APPIMAGE?.trim() || process.execPath,
101
scheme: ElectronProtocol.getDesktopScheme(linux.isDevelopment),
102
+ ...(iconPath === undefined ? {} : { iconPath }),
103
}),
104
"utf8",
105
);