Skip to content

Commit cd40fc3

Browse files
fix(web): integrate main file-chip path resolution
2 parents 1a743ca + a71a6c3 commit cd40fc3

294 files changed

Lines changed: 9122 additions & 1967 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/DesktopLinuxUrlHandler.test.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,25 @@ describe("DesktopLinuxUrlHandler", () => {
179179
assert.include(entry, "Icon=/home/al ice/icons/T3\\\\x.png");
180180
});
181181

182+
it.each([
183+
{
184+
execTarget: "/opt/T3(beta)/t3code.AppImage",
185+
execLine: 'Exec="/opt/T3(beta)/t3code.AppImage" %U',
186+
},
187+
{
188+
execTarget: "/opt/t3%20code/t3code.AppImage",
189+
execLine: "Exec=/opt/t3%%20code/t3code.AppImage %U",
190+
},
191+
])("renders the handler Exec line for $execTarget", ({ execTarget, execLine }) => {
192+
const entry = DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
193+
displayName: "T3 Code",
194+
execTarget,
195+
scheme: "t3code",
196+
});
197+
198+
assert.include(entry.split("\n"), execLine);
199+
});
200+
182201
it("carries structured context on registration errors", () => {
183202
const writeError = new DesktopLinuxUrlHandler.DesktopLinuxUrlHandlerRegistrationError({
184203
step: "write-desktop-entry",
@@ -222,7 +241,7 @@ describe("DesktopLinuxUrlHandler", () => {
222241
);
223242
assert.include(
224243
recorded.files[0]?.content,
225-
'Exec="/home/alice/Applications/T3-Code.AppImage" %U',
244+
"Exec=/home/alice/Applications/T3-Code.AppImage %U",
226245
);
227246
assert.include(recorded.files[0]?.content, "MimeType=x-scheme-handler/t3code;");
228247
assert.deepEqual(recorded.commands, [
@@ -247,7 +266,12 @@ describe("DesktopLinuxUrlHandler", () => {
247266

248267
assert.include(
249268
recorded.files[0]?.content,
250-
`Exec=${DesktopLinuxUrlHandler.escapeDesktopEntryExecArgument(process.execPath)} %U`,
269+
DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
270+
displayName: "T3 Code (Alpha)",
271+
execTarget: process.execPath,
272+
scheme: "t3code",
273+
iconPath: "/home/alice/.local/share/icons/com.t3tools.T3Code.desktop.png",
274+
}),
251275
);
252276
});
253277
});

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export function escapeDesktopEntryExecArgument(value: string): string {
7575
return escapeDesktopEntryString(`"${quoted}"`);
7676
}
7777

78+
// Legacy xdg-open looks up the first Exec word without unquoting it.
79+
const escapeUrlHandlerExecTarget = (value: string): string =>
80+
/[ \t\n"'\\><~|&;$*?#()`]/.test(value)
81+
? escapeDesktopEntryExecArgument(value)
82+
: escapeDesktopEntryString(value.replaceAll("%", "%%"));
83+
7884
// The AppImage integration entry owns the window identity. This
7985
// hidden URL-only entry must not compete with it for StartupWMClass matching.
8086
export function renderUrlHandlerDesktopEntry(input: {
@@ -87,7 +93,7 @@ export function renderUrlHandlerDesktopEntry(input: {
8793
"[Desktop Entry]",
8894
"Type=Application",
8995
`Name=${escapeDesktopEntryString(input.displayName)}`,
90-
`Exec=${escapeDesktopEntryExecArgument(input.execTarget)} %U`,
96+
`Exec=${escapeUrlHandlerExecTarget(input.execTarget)} %U`,
9197
...(input.iconPath === undefined ? [] : [`Icon=${escapeDesktopEntryString(input.iconPath)}`]),
9298
"Terminal=false",
9399
"NoDisplay=true",

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

Lines changed: 64 additions & 2 deletions
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", () => {
@@ -174,7 +236,7 @@ describe("DesktopPreReadyPlatform", () => {
174236
);
175237
const identity = yield* Effect.promise(() => portalIdentity);
176238
assert.equal(identity.desktopName, "com.t3tools.T3Code.desktop");
177-
assert.include(identity.desktopEntry ?? "", 'Exec="/Applications/current.AppImage" %U');
239+
assert.include(identity.desktopEntry ?? "", "Exec=/Applications/current.AppImage %U");
178240
assert.include(identity.desktopEntry ?? "", "Name=T3 Code (Beta)");
179241
assert.include(identity.desktopEntry ?? "", "MimeType=x-scheme-handler/t3code;");
180242
assert.include(

‎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/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ describe("DesktopBackendConfiguration", () => {
551551
archiveHash: "b".repeat(64),
552552
wsl: () => ({
553553
prepareRuntime: () => ({ ok: false, reason: "archive is corrupt" }),
554+
invalidateRuntime: () => Effect.die("failed staging must not invalidate a runtime"),
554555
ensureNodePty: (_distro, root) => {
555556
observedNodePtyRoots.push(root);
556557
return { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
@@ -615,6 +616,35 @@ describe("DesktopBackendConfiguration", () => {
615616
);
616617
});
617618

619+
it.effect("resolveWsl preserves the staging error when the mounted fallback is fatal", () =>
620+
withPackagedWslHarness(
621+
{
622+
archiveHash: "b".repeat(64),
623+
wsl: () => ({
624+
prepareRuntime: () => ({
625+
ok: false,
626+
reason:
627+
"t3: error while loading shared libraries: libatomic.so.1: cannot open shared object file",
628+
}),
629+
ensureNodePty: () => ({
630+
ok: false,
631+
reason: "the packaged Linux node-pty binary was not included",
632+
fatal: true,
633+
}),
634+
}),
635+
},
636+
() =>
637+
Effect.gen(function* () {
638+
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
639+
const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
640+
const failure = Option.getOrThrow(config.preflightFailure);
641+
642+
assert.isTrue(failure.fatal);
643+
assert.include(failure.reason, "libatomic.so.1");
644+
}),
645+
),
646+
);
647+
618648
it.effect("resolveWsl keeps the staged runtime when the mounted tree fails too", () => {
619649
const stagedAppRoot = "/home/test/.t3/wsl-runtime/cache";
620650
const invalidatedRuntimeIds: string[] = [];

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
386386
: ({ ok: true, windowsEntryPath, linuxAppRoot: mountedAppRoot.value } as const);
387387
});
388388

389-
let stagedFailure: { readonly runtimeId: string; readonly reason: string } | undefined;
389+
let stagedFailure: { readonly runtimeId?: string; readonly reason: string } | undefined;
390390
const failedStaged = (failure: { readonly reason: string }) =>
391391
({
392392
_tag: "Failed",
@@ -417,6 +417,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
417417
);
418418
stagedFailure = { runtimeId: input.runtimeArchive.runtimeId, reason: stagedProbe.reason };
419419
} else {
420+
stagedFailure = { reason: runtime.reason };
420421
yield* Effect.logWarning(
421422
"Could not stage the WSL runtime; launching from the mounted server tree instead.",
422423
{ reason: runtime.reason },
@@ -446,7 +447,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
446447
: failedNodePty(nodePtyResult);
447448
}
448449

449-
if (stagedFailure) {
450+
if (stagedFailure?.runtimeId) {
450451
yield* wslEnv.invalidateRuntime(runningDistro, stagedFailure.runtimeId);
451452
}
452453

0 commit comments

Comments
 (0)