Skip to content

Commit 9c1a3ce

Browse files
committed
Merge remote-tracking branch 'origin/main' into gitlab-diffs-page-size
2 parents 231451b + eb06520 commit 9c1a3ce

92 files changed

Lines changed: 3769 additions & 409 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.

‎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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe("DesktopPreReadyPlatform", () => {
174174
);
175175
const identity = yield* Effect.promise(() => portalIdentity);
176176
assert.equal(identity.desktopName, "com.t3tools.T3Code.desktop");
177-
assert.include(identity.desktopEntry ?? "", 'Exec="/Applications/current.AppImage" %U');
177+
assert.include(identity.desktopEntry ?? "", "Exec=/Applications/current.AppImage %U");
178178
assert.include(identity.desktopEntry ?? "", "Name=T3 Code (Beta)");
179179
assert.include(identity.desktopEntry ?? "", "MimeType=x-scheme-handler/t3code;");
180180
assert.include(

‎apps/desktop/src/backend/DesktopBackendManager.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,30 @@ describe("DesktopBackendManager", () => {
431431
}),
432432
);
433433

434+
it.effect("reports a SIGKILL exit without an exit code", () =>
435+
Effect.gen(function* () {
436+
const exitCause = PlatformError.systemError({
437+
_tag: "Unknown",
438+
module: "ChildProcess",
439+
method: "exitCode",
440+
cause: new Error("Process interrupted due to receipt of signal: 'SIGKILL'"),
441+
});
442+
const layerSpawner = Layer.succeed(
443+
ChildProcessSpawner.ChildProcessSpawner,
444+
ChildProcessSpawner.make(() =>
445+
Effect.succeed(makeProcess({ exitCode: Effect.fail(exitCause) })),
446+
),
447+
);
448+
449+
const exit = yield* DesktopBackendManager.runBackendProcess({
450+
...baseConfig,
451+
desktopTelemetryStream: Stream.empty,
452+
}).pipe(Effect.scoped, Effect.provide(Layer.merge(layerSpawner, layerHealthyHttpClient)));
453+
454+
assert.deepEqual(exit, { code: Option.none(), reason: "killed by SIGKILL" });
455+
}),
456+
);
457+
434458
it.effect("reports output stream failures with process and stream context", () =>
435459
Effect.gen(function* () {
436460
const outputCause = PlatformError.systemError({

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,22 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
568568
yield* probeReadiness().pipe(Effect.repeat({ while: (ready) => !ready }), Effect.forkScoped);
569569

570570
const exit = yield* handle.exitCode.pipe(
571-
Effect.mapError(
572-
(cause) =>
571+
Effect.map((exitCode) => ({
572+
code: Option.some(exitCode),
573+
reason: `code=${exitCode}`,
574+
})),
575+
Effect.catch((cause) => {
576+
// Effect's Node spawner exposes signal exits only through this cause message.
577+
const signal =
578+
cause.cause instanceof Error
579+
? /^Process interrupted due to receipt of signal: '(SIG[A-Z0-9]+)'$/.exec(
580+
cause.cause.message,
581+
)?.[1]
582+
: undefined;
583+
if (signal !== undefined) {
584+
return Effect.succeed({ code: Option.none(), reason: `killed by ${signal}` });
585+
}
586+
return Effect.fail(
573587
new BackendProcessExitStatusError({
574588
executablePath: options.executablePath,
575589
entryPath: options.entryPath,
@@ -578,7 +592,8 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
578592
pid: Number(handle.pid),
579593
cause,
580594
}),
581-
),
595+
);
596+
}),
582597
Effect.exit,
583598
);
584599
yield* options.onExitObserved?.() ?? Effect.void;
@@ -592,11 +607,7 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
592607
if (Exit.isFailure(exit)) {
593608
return yield* Effect.failCause(exit.cause);
594609
}
595-
const exitCode = exit.value;
596-
return {
597-
code: Option.some(exitCode),
598-
reason: `code=${exitCode}`,
599-
} satisfies BackendProcessExit;
610+
return exit.value;
600611
});
601612

602613
export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,6 +2791,77 @@ describe("PreviewManager", () => {
27912791
),
27922792
);
27932793

2794+
effectIt.effect("keeps frame capture closed when a replacement is destroyed during cleanup", () =>
2795+
withManager((manager) =>
2796+
Effect.gen(function* () {
2797+
const windowEvents = new Map<string, () => void>();
2798+
const host = makeTestHostWebContents();
2799+
const capturePage = vi.fn(async () => ({
2800+
toJPEG: () => Buffer.from("recording-frame"),
2801+
getSize: () => ({ width: 1280, height: 720 }),
2802+
}));
2803+
const guest = makeTestPreviewWebContents(capturePage, 42, host);
2804+
fromId.mockReturnValue(guest);
2805+
yield* manager.createTab("tab_shutdown");
2806+
yield* manager.registerWebview("tab_shutdown", 42);
2807+
yield* manager.setMainWindow({
2808+
isDestroyed: () => false,
2809+
once: (event: string, listener: () => void) => windowEvents.set(event, listener),
2810+
webContents: { setBackgroundThrottling: vi.fn() },
2811+
} as never);
2812+
yield* manager.startRecording("tab_shutdown");
2813+
const pip = makeTestPictureInPictureWindow();
2814+
browserWindowConstructor.mockImplementation(function () {
2815+
return pip.pictureInPictureWindow;
2816+
});
2817+
yield* manager.openPictureInPicture("tab_shutdown");
2818+
const capturesBeforeClose = capturePage.mock.calls.length;
2819+
const cleanupStarted = yield* Deferred.make<void>();
2820+
const releaseCleanup = yield* Deferred.make<void>();
2821+
yield* manager.subscribeStateChanges((_tabId, state) =>
2822+
state.pictureInPicture
2823+
? Effect.void
2824+
: Deferred.succeed(cleanupStarted, undefined).pipe(
2825+
Effect.andThen(Deferred.await(releaseCleanup)),
2826+
),
2827+
);
2828+
2829+
windowEvents.get("closed")!();
2830+
yield* Deferred.await(cleanupStarted);
2831+
let destroyed = false;
2832+
const replacement = yield* manager
2833+
.setMainWindow({
2834+
isDestroyed: () => destroyed,
2835+
once: vi.fn(),
2836+
webContents: { setBackgroundThrottling: vi.fn() },
2837+
} as never)
2838+
.pipe(Effect.forkChild({ startImmediately: true }));
2839+
try {
2840+
expect(replacement.pollUnsafe()).toBeUndefined();
2841+
destroyed = true;
2842+
} finally {
2843+
yield* Deferred.succeed(releaseCleanup, undefined);
2844+
}
2845+
yield* Fiber.join(replacement);
2846+
2847+
const restart = yield* Effect.exit(manager.startRecording("tab_shutdown"));
2848+
expect(Exit.isFailure(restart)).toBe(true);
2849+
if (Exit.isFailure(restart)) {
2850+
expect(Option.getOrThrow(Cause.findErrorOption(restart.cause))).toMatchObject({
2851+
_tag: "PreviewMainWindowClosedError",
2852+
tabId: "tab_shutdown",
2853+
});
2854+
}
2855+
expect(capturePage).toHaveBeenCalledTimes(capturesBeforeClose);
2856+
expect(pip.pictureInPictureWindow.isDestroyed()).toBe(true);
2857+
expect(guest.setBackgroundThrottling.mock.calls).toEqual([[false], [true]]);
2858+
const grants: Array<{ video?: unknown }> = [];
2859+
host.displayMediaHandler()?.({ frame: host.mainFrame }, (value) => grants.push(value));
2860+
expect(grants).toEqual([{}]);
2861+
}),
2862+
),
2863+
);
2864+
27942865
effectIt.effect("ignores close events from replaced main windows", () =>
27952866
withManager((manager) =>
27962867
Effect.gen(function* () {

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
16641664
}
16651665
yield* SynchronizedRef.modifyEffect(frameCaptureSessionsRef, (sessions) =>
16661666
Effect.gen(function* () {
1667+
// Cleanup or lock acquisition can outlive the replacement window.
1668+
if (window.isDestroyed()) return [undefined, sessions] as const;
16671669
if (sessions.size > 0) {
16681670
yield* setWindowBackgroundThrottling(window, false);
16691671
}

0 commit comments

Comments
 (0)