Skip to content

Commit 1c3d7b3

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-28467
2 parents 322c824 + 2a4d128 commit 1c3d7b3

181 files changed

Lines changed: 5169 additions & 512 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/DesktopEarlyElectronStartup.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type EarlyLinuxElectronOptionsInput = EarlyDesktopSettingsInput;
2626

2727
export interface EarlyLinuxElectronOptions {
2828
readonly isDevelopment: boolean;
29-
readonly linuxWmClass: string;
3029
readonly linuxDesktopEntryName: string;
3130
readonly passwordStore: LinuxPasswordStoreSwitch | null;
3231
}
@@ -146,7 +145,6 @@ export function resolveEarlyLinuxElectronOptions(
146145
const isDevelopment = isDevelopmentEnvironment(input.env);
147146
return {
148147
isDevelopment,
149-
linuxWmClass: isDevelopment ? "t3code-dev" : "t3code",
150148
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
151149
passwordStore: resolveLinuxPasswordStoreSwitch({
152150
preference,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export class DesktopEnvironment extends Context.Service<
7575
readonly displayName: string;
7676
readonly appUserModelId: string;
7777
readonly linuxDesktopEntryName: string;
78-
readonly linuxWmClass: string;
7978
readonly linuxApplicationsDir: string;
8079
readonly desktopLauncherPath: Option.Option<string>;
8180
readonly appImagePath: Option.Option<string>;
@@ -232,7 +231,6 @@ const make = Effect.fn("desktop.environment.make")(function* (
232231
isDevelopment ? "com.t3tools.t3code.dev" : "com.t3tools.t3code",
233232
),
234233
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
235-
linuxWmClass: isDevelopment ? "t3code-dev" : "t3code",
236234
linuxApplicationsDir,
237235
desktopLauncherPath: config.desktopLauncherPath,
238236
appImagePath: config.appImagePath,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const makeEnvironment = (path: Path.Path, overrides: Record<string, unknown> = {
3535
isDevelopment: false,
3636
displayName: "T3 Code (Alpha)",
3737
linuxDesktopEntryName: "com.t3tools.T3Code.desktop",
38-
linuxWmClass: "t3code",
3938
linuxApplicationsDir: "/home/alice/.local/share/applications",
4039
desktopLauncherPath: Option.none(),
4140
appImagePath: Option.some("/home/alice/Applications/T3-Code.AppImage"),

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export const make = Effect.gen(function* () {
121121
} catch {}
122122
// Chromium caches portal identity; set it before any asynchronous initialization.
123123
Electron.app.setDesktopName(linux.linuxDesktopEntryName);
124-
Electron.app.commandLine.appendSwitch("class", linux.linuxWmClass);
125124
if (linux.passwordStore !== null && linuxPasswordStoreCommandLine === null) {
126125
Electron.app.commandLine.appendSwitch("password-store", linux.passwordStore);
127126
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,4 +631,42 @@ describe("DesktopBackendManager", () => {
631631
}).pipe(Effect.provide(TestClock.layer())),
632632
),
633633
);
634+
635+
it.effect("waits out a slow startup and reports one that never becomes ready", () =>
636+
Effect.scoped(
637+
Effect.gen(function* () {
638+
const reports = yield* Queue.unbounded<DesktopBackendManager.BackendStartupFailure>();
639+
const startInstance = (status: Ref.Ref<number>, onReady?: Effect.Effect<void>) =>
640+
makeTestInstance({
641+
spawnerLayer: Layer.succeed(
642+
ChildProcessSpawner.ChildProcessSpawner,
643+
ChildProcessSpawner.make(() =>
644+
Effect.succeed(makeProcess({ exitCode: Effect.never })),
645+
),
646+
),
647+
httpClientLayer: layerHttpClient((request) =>
648+
Ref.get(status).pipe(Effect.map((code) => responseForRequest(request, code))),
649+
),
650+
onStartupFailure: (failure) => Queue.offer(reports, failure).pipe(Effect.asVoid),
651+
...(onReady ? { onReady } : {}),
652+
}).pipe(Effect.tap((instance) => instance.start));
653+
654+
const slowStatus = yield* Ref.make(503);
655+
const ready = yield* Deferred.make<void>();
656+
yield* startInstance(slowStatus, Deferred.succeed(ready, undefined).pipe(Effect.asVoid));
657+
yield* TestClock.adjust(Duration.seconds(66));
658+
yield* Ref.set(slowStatus, 200);
659+
yield* TestClock.adjust(Duration.millis(100));
660+
yield* Deferred.await(ready);
661+
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
662+
663+
yield* startInstance(yield* Ref.make(503));
664+
yield* TestClock.adjust(Duration.seconds(179));
665+
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
666+
yield* TestClock.adjust(Duration.seconds(1));
667+
const failure = yield* Queue.take(reports);
668+
assert.equal(failure.reason, "The server started but did not become ready in time.");
669+
}).pipe(Effect.provide(TestClock.layer())),
670+
),
671+
);
634672
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts";
3434
const INITIAL_RESTART_DELAY = Duration.millis(500);
3535
const MAX_RESTART_DELAY = Duration.seconds(10);
3636
const MAX_PREFLIGHT_FAILURE_ATTEMPTS = 5;
37-
const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(1);
37+
// Large state databases can take over a minute to become ready.
38+
const DEFAULT_BACKEND_READINESS_TIMEOUT = Duration.minutes(3);
3839
const DEFAULT_BACKEND_READINESS_INTERVAL = Duration.millis(100);
3940
const DEFAULT_BACKEND_READINESS_REQUEST_TIMEOUT = Duration.seconds(1);
4041
// Match the service launcher's grace period so backends can stop provider sessions.

‎apps/desktop/src/preview/BrowserImport/ChromiumKeys.test.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ import {
1919
import { LinuxBrowserSecretPath } from "./LinuxBrowserSecret.ts";
2020
import { BROWSER_IMPORT_SOURCES } from "./Sources.ts";
2121

22-
const { getPassword } = vi.hoisted(() => ({ getPassword: vi.fn<() => string | null>() }));
22+
const { getPassword } = vi.hoisted(() => ({
23+
getPassword: vi.fn<() => Promise<string | undefined>>(),
24+
}));
2325

2426
vi.mock("@napi-rs/keyring", () => ({
2527
Entry: class {
28+
getPassword() {
29+
throw new Error("synchronous keychain read");
30+
}
31+
},
32+
AsyncEntry: class {
2633
getPassword = getPassword;
2734
},
2835
}));
@@ -91,18 +98,24 @@ describe("macOS Chromium secrets", () => {
9198

9299
it.effect("derives the cookie key from the keychain secret", () =>
93100
Effect.gen(function* () {
94-
getPassword.mockReturnValue("macos-secret");
101+
getPassword.mockResolvedValue("macos-secret");
95102
const keys = yield* resolveChromiumKeys(request);
96103
expect(keys.cbcV10?.toString("hex")).toBe("3df7306fb1eac353289565a2f6b64f74");
97104
}).pipe(Effect.provide(layerNoProcesses)),
98105
);
99106

107+
it.effect("reports a keychain entry the async read resolves as undefined", () =>
108+
Effect.gen(function* () {
109+
getPassword.mockResolvedValue(undefined);
110+
const error = yield* resolveChromiumKeys(request).pipe(Effect.flip);
111+
expect(error.reason).toBe("keychainItemMissing");
112+
}).pipe(Effect.provide(layerNoProcesses)),
113+
);
114+
100115
it.effect("preserves a denied keychain approval", () =>
101116
Effect.gen(function* () {
102117
const denied = new Error("User denied access");
103-
getPassword.mockImplementation(() => {
104-
throw denied;
105-
});
118+
getPassword.mockRejectedValue(denied);
106119
const error = yield* resolveChromiumKeys(request).pipe(Effect.flip);
107120
expect(error.reason).toBe("needsKeychainApproval");
108121
expect(error.cause).toBe(denied);

‎apps/desktop/src/preview/BrowserImport/ChromiumKeys.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ const readKeychainSecret = Effect.fn("ChromiumKeys.readKeychainSecret")(function
5959
try: () => import("@napi-rs/keyring"),
6060
catch: (cause) => new ChromiumKeyError({ reason: "keychainUnavailable", cause }),
6161
});
62-
const secret = yield* Effect.try({
63-
try: () => new Keyring.Entry(service, account).getPassword(),
62+
const secret = yield* Effect.tryPromise({
63+
try: () => new Keyring.AsyncEntry(service, account).getPassword(),
6464
catch: (cause) => {
6565
const message = String((cause as { message?: unknown } | undefined)?.message ?? "");
6666
const missing = /no (matching )?entry|not found/i.test(message);
@@ -70,7 +70,7 @@ const readKeychainSecret = Effect.fn("ChromiumKeys.readKeychainSecret")(function
7070
});
7171
},
7272
});
73-
if (secret === null || secret === "") {
73+
if (!secret) {
7474
return yield* new ChromiumKeyError({ reason: "keychainItemMissing" });
7575
}
7676
return secret;

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ describe("PreviewManager", () => {
619619
withManager((manager) =>
620620
Effect.gen(function* () {
621621
const send = vi.fn();
622-
const host = { isDestroyed: () => false, send };
622+
const focus = vi.fn();
623+
const host = { isDestroyed: () => false, send, focus };
623624
const older = makeFaviconWebContents({ id: 42 });
624625
const newer = makeFaviconWebContents({ id: 43 });
625626
for (const tab of [older, newer]) Object.assign(tab.webContents, { hostWebContents: host });
@@ -648,6 +649,22 @@ describe("PreviewManager", () => {
648649
expect(preventDefault).toHaveBeenCalledOnce();
649650
expect(send).toHaveBeenCalledExactlyOnceWith("desktop:menu-action", "view.reopenClosed");
650651

652+
yield* manager.setForwardedShortcuts([
653+
{ command: "preview.focusUrl", shortcut: parseKeybindingShortcut("mod+l")! },
654+
]);
655+
beforeInput({ preventDefault } as never, { ...key, key: "l", shift: false } as never);
656+
expect(focus).toHaveBeenCalledOnce();
657+
expect(send).toHaveBeenLastCalledWith("desktop:menu-action", "preview.focusUrl");
658+
expect(focus.mock.invocationCallOrder[0]).toBeLessThan(send.mock.invocationCallOrder[1]!);
659+
beforeInput(
660+
{ preventDefault } as never,
661+
{ ...key, key: "l", shift: false, isAutoRepeat: true } as never,
662+
);
663+
expect(focus).toHaveBeenCalledOnce();
664+
expect(send).toHaveBeenCalledTimes(2);
665+
send.mockClear();
666+
yield* manager.setForwardedShortcuts([{ command: "view.reopenClosed", shortcut }]);
667+
651668
Object.assign(newer.webContents, { focusedFrame: null });
652669
const agentInput = newer.listeners.get("before-input-event")!;
653670
const agentPreventDefault = vi.fn();
@@ -663,7 +680,7 @@ describe("PreviewManager", () => {
663680
{ ...key, key: "T", shift: true } as never,
664681
);
665682
expect(agentPreventDefault).not.toHaveBeenCalled();
666-
expect(send).toHaveBeenCalledOnce();
683+
expect(send).not.toHaveBeenCalled();
667684
}),
668685
),
669686
);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
14781478
if (!input.isAutoRepeat) {
14791479
if (
14801480
forwarded.command === "workspace.focusNext" ||
1481-
forwarded.command === "workspace.focusPrevious"
1481+
forwarded.command === "workspace.focusPrevious" ||
1482+
forwarded.command === "preview.focusUrl"
14821483
) {
14831484
// DOM focus in the renderer cannot by itself release the guest's native keyboard focus.
14841485
host.focus();

0 commit comments

Comments
 (0)