Skip to content

Commit 913f61f

Browse files
Merge remote-tracking branch 'origin/main' into fix/android-tablet-landscape-launch
2 parents 2fc09ed + 54983e3 commit 913f61f

96 files changed

Lines changed: 2704 additions & 354 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
!macro customInstall
2+
!ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
3+
${IfNot} ${FileExists} "$newStartMenuLink"
4+
!insertmacro createMenuDirectory
5+
CreateShortCut "$newStartMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
6+
ClearErrors
7+
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
8+
${EndIf}
9+
!endif
10+
!macroend

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as NodePath from "node:path";
33
import { assert, describe, it } from "@effect/vitest";
44

55
import {
6+
restoreEarlyLinuxDeviceScaleFactor,
67
resolveEarlyLinuxElectronOptions,
78
resolveEarlyLinuxPasswordStorePreference,
89
resolveLinuxDisableFeaturesSwitch,
@@ -269,3 +270,70 @@ describe("DesktopEarlyElectronStartup", () => {
269270
});
270271
});
271272
});
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‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,43 @@ export function resolveEarlyLinuxElectronOptions(
159159
}),
160160
};
161161
}
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‎

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const {
1515
writeFileSyncMock,
1616
copyFileSyncMock,
1717
execFileSyncMock,
18+
readFileSyncMock,
1819
} = vi.hoisted(() => ({
1920
appendSwitchMock: vi.fn(),
2021
getSwitchValueMock: vi.fn(),
@@ -25,6 +26,7 @@ const {
2526
writeFileSyncMock: vi.fn(),
2627
copyFileSyncMock: vi.fn(),
2728
execFileSyncMock: vi.fn(),
29+
readFileSyncMock: vi.fn(),
2830
}));
2931

3032
vi.mock("electron", () => ({
@@ -45,7 +47,7 @@ vi.mock("electron", () => ({
4547
}));
4648

4749
vi.mock("node:fs", () => ({
48-
readFileSync: () => "{}",
50+
readFileSync: readFileSyncMock,
4951
mkdirSync: mkdirSyncMock,
5052
writeFileSync: writeFileSyncMock,
5153
copyFileSync: copyFileSyncMock,
@@ -68,6 +70,66 @@ describe("DesktopPreReadyPlatform", () => {
6870
writeFileSyncMock.mockReset();
6971
copyFileSyncMock.mockReset();
7072
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));
71133
});
72134

73135
it.effect("preserves an explicit Linux password-store switch", () => {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ export const make = Effect.gen(function* () {
6262
platform === "linux" ? resolveEarlyLinuxElectronOptionsFromProcess(homeDirectory) : null;
6363

6464
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+
});
6576
// The portal also requires a valid desktop entry. An AppImage update may
6677
// have removed the executable referenced by the previous launch's entry.
6778
try {

‎apps/desktop/src/window/DesktopApplicationMenu.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ describe("DesktopApplicationMenu", () => {
247247
}),
248248
);
249249

250-
it.effect("routes View menu zoom to the main window instead of zoom roles", () =>
250+
it.effect("registers macOS command-plus once and routes it through main-window zoom", () =>
251251
Effect.gen(function* () {
252252
const selectedAction = yield* Deferred.make<string>();
253253
const applicationMenuTemplate =
254254
yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
255255

256-
yield* configureMenu(selectedAction, applicationMenuTemplate);
256+
yield* configureMenu(selectedAction, applicationMenuTemplate, { platform: "darwin" });
257257

258258
const template = yield* Deferred.await(applicationMenuTemplate);
259259
const viewMenu = template.find((item) => item.label === "View");
@@ -268,9 +268,17 @@ describe("DesktopApplicationMenu", () => {
268268
),
269269
);
270270

271-
const zoomIn = viewMenu.submenu.find((item) => item.label === "Zoom In");
271+
const shiftedEqual = viewMenu.submenu.filter(
272+
(item) => item.accelerator === "CmdOrCtrl+Shift+=",
273+
);
274+
assert.lengthOf(shiftedEqual, 1);
275+
assert.lengthOf(
276+
viewMenu.submenu.filter((item) => item.accelerator === "CmdOrCtrl+numadd"),
277+
1,
278+
);
279+
const zoomIn = shiftedEqual[0];
272280
assert.isDefined(zoomIn);
273-
assert.equal(zoomIn.accelerator, "CmdOrCtrl+=");
281+
assert.isFalse(zoomIn.visible);
274282
if (typeof zoomIn.click !== "function") {
275283
throw new Error("Expected Zoom In menu item to have a click handler.");
276284
}

‎apps/desktop/src/window/DesktopApplicationMenu.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ export const make = Effect.gen(function* () {
263263
visible: false,
264264
click: zoomClick("in"),
265265
},
266+
...(environment.platform === "darwin"
267+
? [
268+
{
269+
label: "Zoom In",
270+
accelerator: "CmdOrCtrl+Shift+=",
271+
visible: false,
272+
click: zoomClick("in"),
273+
},
274+
]
275+
: []),
266276
{ label: "Zoom Out", accelerator: "CmdOrCtrl+-", click: zoomClick("out") },
267277
// The numeric keypad sends its own key codes, so the number-row
268278
// accelerators above never match it.

‎apps/desktop/src/window/DesktopWindow.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,10 @@ describe("DesktopWindow", () => {
774774
// Chromium hands the main window's zoom level down to embedded preview
775775
// guests, so every app zoom has to put the preview browser back at its own
776776
// zoom or zooming the UI drags the previewed page with it.
777-
it.effect("restores the preview browser's own zoom after zooming the app", () =>
777+
it.effect("zooms main with a focused popup and reapplies preview zoom", () =>
778778
Effect.gen(function* () {
779779
const fakeWindow = makeFakeBrowserWindow();
780+
const popup = makeFakeBrowserWindow();
780781
const createCount = yield* Ref.make(0);
781782
const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
782783
const previewZoomReapplies: number[] = [];
@@ -785,6 +786,7 @@ describe("DesktopWindow", () => {
785786
createCount,
786787
mainWindow,
787788
previewZoomReapplies,
789+
focusedWindow: popup.window,
788790
});
789791

790792
yield* Effect.gen(function* () {
@@ -801,6 +803,7 @@ describe("DesktopWindow", () => {
801803
[-0.5, -1, -0.5, 0],
802804
);
803805
assert.deepEqual(previewZoomReapplies, [-0.5, -1, -0.5, 0]);
806+
assert.equal(popup.setZoomLevel.mock.calls.length, 0);
804807
}).pipe(Effect.provide(layer));
805808
}),
806809
);

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ export const make = Effect.gen(function* () {
10261026
}),
10271027
zoomMain: Effect.fn("desktop.window.zoomMain")(function* (direction) {
10281028
yield* Effect.annotateCurrentSpan({ direction });
1029-
const window = yield* focusedMainWindow;
1029+
const window = yield* electronWindow.main;
10301030
if (Option.isNone(window) || window.value.isDestroyed()) {
10311031
return;
10321032
}

‎apps/mobile/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"sync:pierre-icons": "node scripts/sync-pierre-file-icons.mjs",
4444
"measure-renders": "node scripts/measure-renders.mts",
4545
"generate": "node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON scripts/generate-uniwind-themes.mts",
46-
"test": "vp test run --config ../../vite.config.ts --dir .",
46+
"test": "vp test run --project unit --project react",
4747
"typecheck": "tsc-rs --noEmit"
4848
},
4949
"dependencies": {

0 commit comments

Comments
 (0)