@devries-cameron20 / t3code-1 / commits / 115e405453
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): avoid temporary icon copies on Linux launches (#19589)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor Vogel committed Oct 20, 2026 at 00:35 UTC 115e40545385b58b1482ed1b9873063b1503dde2
4 files changed +183 -46
apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
+91 -27
@@ -22,8 +22,31 @@ interface RecordedRegistration {
22 readonly files: Array<{ readonly path: string; readonly content: string }>;
23 readonly commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }>;
24 readonly copies: Array<{ readonly source: string; readonly destination: string }>;
25 + readonly binaryReads: string[];
26 + readonly binaryWrites: Array<{
27 + readonly path: string;
28 + readonly bytes: Uint8Array;
29 + readonly mode: number | undefined;
30 + }>;
31 }
32
33 +const iconSource = "/tmp/.mount_T3/resources/app.asar/apps/desktop/prod-resources/icon.png";
34 +const iconPath = "/home/alice/.local/share/icons/com.t3tools.T3Code.desktop.png";
35 +const iconBytes = new Uint8Array([0x89, 0x50, 0x00, 0xff, 0x80, 0x0a]);
36 +const currentDesktopEntry = DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
37 + displayName: "T3 Code (Alpha)",
38 + execTarget: "/home/alice/Applications/T3-Code.AppImage",
39 + scheme: "t3code",
40 + iconPath,
41 +});
42 +const registrationCommands = [
43 + { command: "update-desktop-database", args: ["/home/alice/.local/share/applications"] },
44 + {
45 + command: "xdg-mime",
46 + args: ["default", "com.t3tools.T3Code.desktop", "x-scheme-handler/t3code"],
47 + },
48 +];
49 +
50 const makeEnvironment = (path: Path.Path, overrides: Record<string, unknown> = {}) =>
51 DesktopEnvironment.DesktopEnvironment.of({
52 platform: "linux",
@@ -64,7 +87,8 @@ const layerHandler = (
87 readonly writeError?: PlatformError.PlatformError;
88 readonly existingEntry?: string;
89 readonly iconSource?: string;
67 - readonly iconCopyError?: PlatformError.PlatformError;
90 + readonly existingIcon?: Uint8Array;
91 + readonly iconReadError?: PlatformError.PlatformError;
92 } = {},
93 ) =>
94 DesktopLinuxUrlHandler.layer.pipe(
@@ -87,11 +111,34 @@ const layerHandler = (
111 }),
112 FileSystem.layerNoop({
113 copyFile: (source, destination) =>
90 - input.iconCopyError
91 - ? Effect.fail(input.iconCopyError)
92 - : Effect.sync(() => {
93 - recorded.copies.push({ source, destination });
94 - }),
114 + Effect.sync(() => {
115 + recorded.copies.push({ source, destination });
116 + }),
117 + readFile: (path) =>
118 + Effect.gen(function* () {
119 + recorded.binaryReads.push(path);
120 + if (path === input.iconSource) {
121 + if (input.iconReadError) return yield* input.iconReadError;
122 + return new Uint8Array(iconBytes);
123 + }
124 + if (path === iconPath && input.existingIcon !== undefined) {
125 + return input.existingIcon;
126 + }
127 + return yield* PlatformError.systemError({
128 + _tag: "NotFound",
129 + module: "FileSystem",
130 + method: "readFile",
131 + pathOrDescriptor: path,
132 + });
133 + }),
134 + writeFile: (path, bytes, options) =>
135 + Effect.sync(() => {
136 + recorded.binaryWrites.push({
137 + path,
138 + bytes: new Uint8Array(bytes),
139 + mode: options?.mode,
140 + });
141 + }),
142 readFileString: () => Effect.succeed(input.existingEntry ?? ""),
143 makeDirectory: (path) =>
144 Effect.sync(() => {
@@ -156,6 +203,8 @@ const emptyRecording = (): RecordedRegistration => ({
203 files: [],
204 commands: [],
205 copies: [],
206 + binaryReads: [],
207 + binaryWrites: [],
208 });
209
210 describe("DesktopLinuxUrlHandler", () => {
@@ -306,42 +355,57 @@ describe("DesktopLinuxUrlHandler", () => {
355
356 it.effect("installs a persistent icon even when the desktop entry is already current", () => {
357 const recorded = emptyRecording();
309 - const iconPath = "/home/alice/.local/share/icons/com.t3tools.T3Code.desktop.png";
358 return Effect.gen(function* () {
359 yield* runRegister(recorded, {
312 - iconSource: "/tmp/.mount_T3/resources/icon.png",
313 - existingEntry: DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
314 - displayName: "T3 Code (Alpha)",
315 - execTarget: "/home/alice/Applications/T3-Code.AppImage",
316 - scheme: "t3code",
317 - iconPath,
318 - }),
360 + iconSource,
361 + existingEntry: currentDesktopEntry,
362 });
363 assert.deepEqual(recorded.files, []);
321 - assert.deepEqual(recorded.copies, [
322 - { source: "/tmp/.mount_T3/resources/icon.png", destination: iconPath },
323 - ]);
324 - assert.equal(recorded.commands.at(-1)?.command, "xdg-mime");
364 + assert.deepEqual(recorded.copies, []);
365 + assert.deepEqual(recorded.binaryReads, [iconSource, iconPath]);
366 + assert.deepEqual(recorded.binaryWrites, [{ path: iconPath, bytes: iconBytes, mode: 0o600 }]);
367 + assert.deepEqual(recorded.commands, registrationCommands);
368 });
369 });
370
328 - it.effect("still registers the handler when copying its icon fails", () => {
371 + it.effect("refreshes a stale icon and skips equal bytes on the next registration", () => {
372 const recorded = emptyRecording();
373 return Effect.gen(function* () {
374 yield* runRegister(recorded, {
332 - iconSource: "/tmp/.mount_T3/resources/icon.png",
333 - iconCopyError: PlatformError.systemError({
375 + iconSource,
376 + existingEntry: currentDesktopEntry,
377 + existingIcon: new Uint8Array([0x89, 0x50, 0x00, 0xfe, 0x80, 0x0a]),
378 + });
379 + assert.deepEqual(recorded.binaryWrites, [{ path: iconPath, bytes: iconBytes, mode: 0o600 }]);
380 + yield* runRegister(recorded, {
381 + iconSource,
382 + existingEntry: currentDesktopEntry,
383 + existingIcon: new Uint8Array(recorded.binaryWrites[0]!.bytes),
384 + });
385 + assert.equal(recorded.binaryWrites.length, 1);
386 + assert.deepEqual(recorded.copies, []);
387 + assert.deepEqual(recorded.files, []);
388 + assert.deepEqual(recorded.commands, [...registrationCommands, ...registrationCommands]);
389 + });
390 + });
391 +
392 + it.effect("still registers the handler when reading its icon fails", () => {
393 + const recorded = emptyRecording();
394 + return Effect.gen(function* () {
395 + yield* runRegister(recorded, {
396 + iconSource,
397 + iconReadError: PlatformError.systemError({
398 _tag: "PermissionDenied",
399 module: "FileSystem",
336 - method: "copyFile",
337 - description: "read-only icon directory",
400 + method: "readFile",
401 + description: "unreadable bundled icon",
402 }),
403 });
404 + assert.deepEqual(recorded.binaryReads, [iconSource]);
405 + assert.deepEqual(recorded.binaryWrites, []);
406 + assert.deepEqual(recorded.copies, []);
407 assert.equal(recorded.files.length, 1);
341 - assert.deepEqual(
342 - recorded.commands.map(({ command }) => command),
343 - ["update-desktop-database", "xdg-mime"],
344 - );
408 + assert.deepEqual(recorded.commands, registrationCommands);
409 });
410 });
411
apps/desktop/src/app/DesktopLinuxUrlHandler.ts
+6 -2
@@ -301,12 +301,16 @@ export const make = Effect.gen(function* () {
301 yield* Effect.gen(function* () {
302 const { png } = yield* assets.iconPaths;
303 if (Option.isNone(png)) return;
304 + // Electron's copyFile extracts ASAR entries to temporary files it never removes.
305 + const icon = yield* fileSystem.readFile(png.value);
306 + const current = yield* fileSystem.readFile(iconPath).pipe(Effect.option);
307 + if (Option.isSome(current) && sameBytes(current.value, icon)) return;
308 // The AppImage mount is temporary; the chooser needs the icon after exit.
309 yield* fileSystem.makeDirectory(iconsDir, { recursive: true });
306 - yield* fileSystem.copyFile(png.value, iconPath);
310 + yield* fileSystem.writeFile(iconPath, icon, { mode: 0o600 });
311 }).pipe(
312 Effect.catch((error) =>
309 - logWarning("URL handler icon copy failed", { iconPath, category: error.reason._tag }),
313 + logWarning("URL handler icon install failed", { iconPath, category: error.reason._tag }),
314 ),
315 );
316
apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
+76 -14
@@ -14,10 +14,10 @@ const {
14 setNameMock,
15 appState,
16 mkdirSyncMock,
17 + readFileSyncMock,
18 writeFileSyncMock,
19 copyFileSyncMock,
20 execFileSyncMock,
20 - readFileSyncMock,
21 } = vi.hoisted(() => ({
22 appendSwitchMock: vi.fn(),
23 getSwitchValueMock: vi.fn(),
@@ -27,10 +27,10 @@ const {
27 setNameMock: vi.fn(),
28 appState: { version: "0.0.37", isPackaged: true },
29 mkdirSyncMock: vi.fn(),
30 + readFileSyncMock: vi.fn(),
31 writeFileSyncMock: vi.fn(),
32 copyFileSyncMock: vi.fn(),
33 execFileSyncMock: vi.fn(),
33 - readFileSyncMock: vi.fn(),
34 }));
35
36 vi.mock("electron", () => ({
@@ -66,6 +66,11 @@ vi.mock("node:child_process", () => ({
66
67 import * as DesktopPreReadyPlatform from "./DesktopPreReadyPlatform.ts";
68
69 +const iconSource = "/tmp/.mount_T3/resources/app.asar/apps/desktop/prod-resources/icon.png";
70 +const iconPath = "/xdg/icons/com.t3tools.T3Code.desktop.png";
71 +const desktopEntryPath = "/xdg/applications/com.t3tools.T3Code.desktop";
72 +const iconBytes = Buffer.from([0x89, 0x50, 0x00, 0xff, 0x80, 0x0a]);
73 +
74 describe("DesktopPreReadyPlatform", () => {
75 beforeEach(() => {
76 appendSwitchMock.mockReset();
@@ -77,10 +82,15 @@ describe("DesktopPreReadyPlatform", () => {
82 appState.version = "0.0.37";
83 appState.isPackaged = true;
84 mkdirSyncMock.mockReset();
85 + readFileSyncMock.mockReset();
86 writeFileSyncMock.mockReset();
87 copyFileSyncMock.mockReset();
88 execFileSyncMock.mockReset();
83 - readFileSyncMock.mockReset().mockReturnValue("{}");
89 + readFileSyncMock.mockReset().mockImplementation((path: string) => {
90 + if (path.endsWith("/desktop-settings.json")) return "{}";
91 + if (path === iconSource) return Buffer.from(iconBytes);
92 + throw new Error(`missing file: ${path}`);
93 + });
94 });
95
96 it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => {
@@ -222,14 +232,13 @@ describe("DesktopPreReadyPlatform", () => {
232 let desktopName = "t3code.desktop";
233 let desktopEntry = previousEntry;
234 let iconInstalled = false;
225 - copyFileSyncMock.mockImplementation((_source: string, destination: string) => {
226 - iconInstalled = destination === "/xdg/icons/com.t3tools.T3Code.desktop.png";
227 - });
235 setDesktopNameMock.mockImplementation((name: string) => {
236 desktopName = name;
237 });
231 - writeFileSyncMock.mockImplementation((path: string, contents: string) => {
232 - if (path === "/xdg/applications/com.t3tools.T3Code.desktop") desktopEntry = contents;
238 + writeFileSyncMock.mockImplementation((path: string, contents: string | Buffer) => {
239 + if (path === iconPath)
240 + iconInstalled = Buffer.isBuffer(contents) && contents.equals(iconBytes);
241 + if (path === desktopEntryPath && typeof contents === "string") desktopEntry = contents;
242 });
243
244 return Effect.scoped(
@@ -254,6 +263,15 @@ describe("DesktopPreReadyPlatform", () => {
263 "Icon=/xdg/icons/com.t3tools.T3Code.desktop.png",
264 );
265 assert.isTrue(identity.iconInstalled);
266 + assert.deepEqual(
267 + readFileSyncMock.mock.calls.filter(([path]) => path === iconSource),
268 + [[iconSource]],
269 + );
270 + assert.deepEqual(
271 + writeFileSyncMock.mock.calls.filter(([path]) => path === iconPath),
272 + [[iconPath, iconBytes, { mode: 0o600 }]],
273 + );
274 + assert.equal(copyFileSyncMock.mock.calls.length, 0);
275 }),
276 ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())));
277 });
@@ -301,18 +319,62 @@ describe("DesktopPreReadyPlatform", () => {
319 );
320 });
321
304 - it.effect("still prepares the portal entry when the bundled icon cannot be copied", () => {
322 + it.effect("refreshes a stale icon once across repeated launches", () => {
323 + vi.stubEnv("VITE_DEV_SERVER_URL", "");
324 + vi.stubEnv("XDG_DATA_HOME", "/xdg");
325 getSwitchValueMock.mockReturnValue("");
306 - copyFileSyncMock.mockImplementation(() => {
307 - throw new Error("missing bundled icon");
326 + let installedIcon = Buffer.from([0x89, 0x50, 0x00, 0xfe, 0x80, 0x0a]);
327 + readFileSyncMock.mockImplementation((path: string) => {
328 + if (path === iconSource) return Buffer.from(iconBytes);
329 + if (path === iconPath) return Buffer.from(installedIcon);
330 + return "{}";
331 + });
332 + writeFileSyncMock.mockImplementation((path: string, contents: Buffer) => {
333 + if (path === iconPath) installedIcon = Buffer.from(contents);
334 });
335 +
336 return Effect.gen(function* () {
337 yield* DesktopPreReadyPlatform.make;
311 - const contents = writeFileSyncMock.mock.calls[0]?.[1];
338 + assert.deepEqual(installedIcon, iconBytes);
339 + yield* DesktopPreReadyPlatform.make;
340 + assert.deepEqual(
341 + writeFileSyncMock.mock.calls.filter(([path]) => path === iconPath),
342 + [[iconPath, iconBytes, { mode: 0o600 }]],
343 + );
344 + assert.equal(copyFileSyncMock.mock.calls.length, 0);
345 + assert.equal(
346 + writeFileSyncMock.mock.calls.filter(([path]) => path === desktopEntryPath).length,
347 + 2,
348 + );
349 + assert.equal(setDesktopNameMock.mock.calls.length, 2);
350 + }).pipe(
351 + Effect.provideService(HostProcess.Platform, "linux"),
352 + Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())),
353 + );
354 + });
355 +
356 + it.effect("still prepares the portal entry when the bundled icon cannot be read", () => {
357 + vi.stubEnv("VITE_DEV_SERVER_URL", "");
358 + vi.stubEnv("XDG_DATA_HOME", "/xdg");
359 + getSwitchValueMock.mockReturnValue("");
360 + readFileSyncMock.mockImplementation((path: string) => {
361 + if (path === iconSource) throw new Error("unreadable bundled icon");
362 + return "{}";
363 + });
364 + return Effect.gen(function* () {
365 + yield* DesktopPreReadyPlatform.make;
366 + assert.isTrue(readFileSyncMock.mock.calls.some(([path]) => path === iconSource));
367 + assert.equal(copyFileSyncMock.mock.calls.length, 0);
368 + assert.equal(writeFileSyncMock.mock.calls.length, 1);
369 + const [path, contents] = writeFileSyncMock.mock.calls[0]!;
370 + assert.equal(path, desktopEntryPath);
371 assert.include(contents, "MimeType=x-scheme-handler/t3code;");
313 - assert.include(contents, "Icon=");
372 + assert.include(contents, `Icon=${iconPath}`);
373 assert.equal(setDesktopNameMock.mock.calls.length, 1);
315 - }).pipe(Effect.provideService(HostProcess.Platform, "linux"));
374 + }).pipe(
375 + Effect.provideService(HostProcess.Platform, "linux"),
376 + Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())),
377 + );
378 });
379
380 it.effect(
apps/desktop/src/app/DesktopPreReadyPlatform.ts
+10 -3
@@ -97,14 +97,21 @@ export const make = Effect.gen(function* () {
97 : undefined;
98 if (iconPath !== undefined) {
99 try {
100 - NodeFS.mkdirSync(NodePath.posix.dirname(iconPath), { recursive: true });
101 - NodeFS.copyFileSync(
100 + // Electron's copyFile extracts ASAR entries to temporary files it never removes.
101 + const icon = NodeFS.readFileSync(
102 NodePath.posix.join(
103 Electron.app.getAppPath(),
104 "apps/desktop/prod-resources/icon.png",
105 ),
106 - iconPath,
106 );
107 + let current: Buffer | null = null;
108 + try {
109 + current = NodeFS.readFileSync(iconPath);
110 + } catch {}
111 + if (current === null || !current.equals(icon)) {
112 + NodeFS.mkdirSync(NodePath.posix.dirname(iconPath), { recursive: true });
113 + NodeFS.writeFileSync(iconPath, icon, { mode: 0o600 });
114 + }
115 } catch {}
116 }
117 NodeFS.writeFileSync(