The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): preserve Linux device scale across updates (#14421)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
jkramer5103 committed
Oct 19, 2026 at 23:18 UTC
f7ad7f2dca98fd6fcd54c0a66ca59367b68cc370
4 files changed
+182
-1
apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts
+68
@@ -3,6 +3,7 @@ import * as NodePath from "node:path";
3
import { assert, describe, it } from "@effect/vitest";
4
5
import {
6
+ restoreEarlyLinuxDeviceScaleFactor,
7
resolveEarlyLinuxElectronOptions,
8
resolveEarlyLinuxPasswordStorePreference,
9
resolveLinuxDisableFeaturesSwitch,
@@ -269,3 +270,70 @@ describe("DesktopEarlyElectronStartup", () => {
270
});
271
});
272
});
273
+
274
+describe("Linux device scale persistence failures", () => {
275
+ const input = {
276
+ env: { T3CODE_HOME: "/isolated" },
277
+ homeDirectory: "/home/user",
278
+ joinPath: NodePath.posix.join,
279
+ };
280
+
281
+ it.each(["0", "Infinity", "garbage"])("ignores invalid persisted scale %j", (value) => {
282
+ const applied: Array<[string, string]> = [];
283
+ const writes: Array<string> = [];
284
+ restoreEarlyLinuxDeviceScaleFactor({
285
+ ...input,
286
+ commandLine: {
287
+ hasSwitch: () => false,
288
+ getSwitchValue: () => "",
289
+ appendSwitch: (name, scale) => applied.push([name, scale]),
290
+ },
291
+ readFileString: () => value,
292
+ writeFileString: (_path, contents) => writes.push(contents),
293
+ });
294
+ assert.deepEqual(applied, []);
295
+ assert.deepEqual(writes, []);
296
+ });
297
+
298
+ it("keeps startup available with default scaling when saved state cannot be read", () => {
299
+ const applied: Array<[string, string]> = [];
300
+ restoreEarlyLinuxDeviceScaleFactor({
301
+ ...input,
302
+ commandLine: {
303
+ hasSwitch: () => false,
304
+ getSwitchValue: () => "",
305
+ appendSwitch: (name, value) => applied.push([name, value]),
306
+ },
307
+ readFileString: () => {
308
+ throw new Error("ENOENT");
309
+ },
310
+ writeFileString: () => {},
311
+ });
312
+ assert.deepEqual(applied, []);
313
+ });
314
+
315
+ it("keeps an explicit scale when saving it fails, without falling back to saved state", () => {
316
+ const applied: Array<[string, string]> = [];
317
+ const reads: Array<string> = [];
318
+ const writes: Array<string> = [];
319
+ restoreEarlyLinuxDeviceScaleFactor({
320
+ ...input,
321
+ commandLine: {
322
+ hasSwitch: () => true,
323
+ getSwitchValue: () => "1",
324
+ appendSwitch: (name, value) => applied.push([name, value]),
325
+ },
326
+ readFileString: (path) => {
327
+ reads.push(path);
328
+ return "1.75";
329
+ },
330
+ writeFileString: (_path, value) => {
331
+ writes.push(value);
332
+ throw new Error("EACCES");
333
+ },
334
+ });
335
+ assert.deepEqual(writes, ["1"]);
336
+ assert.deepEqual(reads, []);
337
+ assert.deepEqual(applied, []);
338
+ });
339
+});
apps/desktop/src/app/DesktopEarlyElectronStartup.ts
+40
@@ -159,3 +159,43 @@ export function resolveEarlyLinuxElectronOptions(
159
}),
160
};
161
}
162
+
163
+/** Remember the explicit Chromium scale across AppImage updates, which drop launch arguments. */
164
+export function restoreEarlyLinuxDeviceScaleFactor(
165
+ input: EarlyDesktopSettingsInput & {
166
+ readonly commandLine: {
167
+ readonly hasSwitch: (name: string) => boolean;
168
+ readonly getSwitchValue: (name: string) => string;
169
+ readonly appendSwitch: (name: string, value: string) => void;
170
+ };
171
+ readonly writeFileString: (path: string, value: string) => void;
172
+ },
173
+): void {
174
+ // Keep this separate from desktop-settings.json: the settings service rewrites
175
+ // that document, and Chromium needs the value before that service is available.
176
+ const path = input.joinPath(
177
+ resolveEarlyDesktopSettingsPath(input),
178
+ "..",
179
+ "linux-device-scale-factor",
180
+ );
181
+ const switchName = "force-device-scale-factor";
182
+ const isValid = (value: string) =>
183
+ value.trim().length > 0 && Number.isFinite(Number(value)) && Number(value) > 0;
184
+ if (input.commandLine.hasSwitch(switchName)) {
185
+ const value = input.commandLine.getSwitchValue(switchName);
186
+ if (isValid(value)) {
187
+ try {
188
+ input.writeFileString(path, value);
189
+ } catch {
190
+ // A read-only state directory must not prevent startup with the explicit switch.
191
+ }
192
+ }
193
+ return;
194
+ }
195
+ try {
196
+ const value = input.readFileString(path).trim();
197
+ if (isValid(value)) input.commandLine.appendSwitch(switchName, value);
198
+ } catch {
199
+ // First launch, missing state, or unreadable state: keep Chromium's default.
200
+ }
201
+}
apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
+63
-1
@@ -15,6 +15,7 @@ const {
15
writeFileSyncMock,
16
copyFileSyncMock,
17
execFileSyncMock,
18
+ readFileSyncMock,
19
} = vi.hoisted(() => ({
20
appendSwitchMock: vi.fn(),
21
getSwitchValueMock: vi.fn(),
@@ -25,6 +26,7 @@ const {
26
writeFileSyncMock: vi.fn(),
27
copyFileSyncMock: vi.fn(),
28
execFileSyncMock: vi.fn(),
29
+ readFileSyncMock: vi.fn(),
30
}));
31
32
vi.mock("electron", () => ({
@@ -45,7 +47,7 @@ vi.mock("electron", () => ({
47
}));
48
49
vi.mock("node:fs", () => ({
48
- readFileSync: () => "{}",
50
+ readFileSync: readFileSyncMock,
51
mkdirSync: mkdirSyncMock,
52
writeFileSync: writeFileSyncMock,
53
copyFileSync: copyFileSyncMock,
@@ -68,6 +70,66 @@ describe("DesktopPreReadyPlatform", () => {
70
writeFileSyncMock.mockReset();
71
copyFileSyncMock.mockReset();
72
execFileSyncMock.mockReset();
73
+ readFileSyncMock.mockReset().mockReturnValue("{}");
74
+ });
75
+
76
+ it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => {
77
+ vi.stubEnv("T3CODE_HOME", "/isolated");
78
+ vi.stubEnv("VITE_DEV_SERVER_URL", "");
79
+ const settingsPath = "/isolated/userdata/desktop-settings.json";
80
+ const files = new Map([[settingsPath, "{}"]]);
81
+ const commandLine = new Map<string, string>();
82
+ readFileSyncMock.mockImplementation((path: string) => {
83
+ const contents = files.get(path);
84
+ if (contents === undefined) throw new Error("ENOENT");
85
+ return contents;
86
+ });
87
+ writeFileSyncMock.mockImplementation((path: string, contents: string) => {
88
+ files.set(path, contents);
89
+ });
90
+ hasSwitchMock.mockImplementation((name: string) => commandLine.has(name));
91
+ getSwitchValueMock.mockImplementation((name: string) => commandLine.get(name) ?? "");
92
+ appendSwitchMock.mockImplementation((name: string, value: string) => {
93
+ commandLine.set(name, value);
94
+ });
95
+ const launch = Effect.gen(function* () {
96
+ const startup = Promise.resolve().then(() => commandLine.get("force-device-scale-factor"));
97
+ yield* DesktopPreReadyPlatform.make;
98
+ return yield* Effect.promise(() => startup);
99
+ });
100
+
101
+ return Effect.gen(function* () {
102
+ for (const explicitScale of ["1.75", "1"]) {
103
+ commandLine.clear();
104
+ commandLine.set("force-device-scale-factor", explicitScale);
105
+ appendSwitchMock.mockClear();
106
+ assert.equal(yield* launch, explicitScale);
107
+ assert.isFalse(
108
+ appendSwitchMock.mock.calls.some(([name]) => name === "force-device-scale-factor"),
109
+ );
110
+
111
+ // The settings service discards fields it does not own when rewriting its document.
112
+ files.set(settingsPath, JSON.stringify({ linuxPasswordStore: "basic" }));
113
+ commandLine.clear();
114
+ assert.equal(yield* launch, explicitScale);
115
+ }
116
+ }).pipe(
117
+ Effect.provideService(HostProcess.Platform, "linux"),
118
+ Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())),
119
+ );
120
+ });
121
+
122
+ it.effect.each(["darwin", "win32"] as const)("leaves device scaling alone on %s", (platform) => {
123
+ readFileSyncMock.mockReturnValue("1.75");
124
+ hasSwitchMock.mockImplementation((name: string) => name === "force-device-scale-factor");
125
+ getSwitchValueMock.mockReturnValue("2");
126
+
127
+ return Effect.gen(function* () {
128
+ yield* DesktopPreReadyPlatform.make;
129
+ assert.deepEqual(readFileSyncMock.mock.calls, []);
130
+ assert.deepEqual(writeFileSyncMock.mock.calls, []);
131
+ assert.deepEqual(appendSwitchMock.mock.calls, []);
132
+ }).pipe(Effect.provideService(HostProcess.Platform, platform));
133
});
134
135
it.effect("preserves an explicit Linux password-store switch", () => {
apps/desktop/src/app/DesktopPreReadyPlatform.ts
+11
@@ -62,6 +62,17 @@ export const make = Effect.gen(function* () {
62
platform === "linux" ? resolveEarlyLinuxElectronOptionsFromProcess(homeDirectory) : null;
63
64
if (linux !== null) {
65
+ DesktopEarlyElectronStartup.restoreEarlyLinuxDeviceScaleFactor({
66
+ env: process.env,
67
+ homeDirectory,
68
+ joinPath: NodePath.posix.join,
69
+ commandLine: Electron.app.commandLine,
70
+ readFileString: (path) => NodeFS.readFileSync(path, "utf8"),
71
+ writeFileString: (path, value) => {
72
+ NodeFS.mkdirSync(NodePath.posix.dirname(path), { recursive: true });
73
+ NodeFS.writeFileSync(path, value, "utf8");
74
+ },
75
+ });
76
// The portal also requires a valid desktop entry. An AppImage update may
77
// have removed the executable referenced by the previous launch's entry.
78
try {