Skip to content

Commit 4643111

Browse files
Merge origin/main into tsconfig/test-diagnostics
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2 parents 02cde95 + fbe5df2 commit 4643111

171 files changed

Lines changed: 15402 additions & 5738 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/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,16 +979,20 @@ describe("DesktopBackendConfiguration", () => {
979979

980980
const previousWslEnv = process.env.WSLENV;
981981
const previousDisabled = process.env.OTEL_SDK_DISABLED;
982+
const previousTelemetry = process.env.T3CODE_TELEMETRY_ENABLED;
982983
try {
983984
delete process.env.WSLENV;
984985
process.env.OTEL_SDK_DISABLED = "true";
986+
process.env.T3CODE_TELEMETRY_ENABLED = "false";
985987

986988
yield* Effect.gen(function* () {
987989
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
988990
const config = yield* configuration.resolveWsl({ port: 5050, distro: null });
989991

990992
assert.equal(config.env.OTEL_SDK_DISABLED, "true");
991993
assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_SDK_DISABLED");
994+
assert.equal(config.env.T3CODE_TELEMETRY_ENABLED, "false");
995+
assert.include((config.env.WSLENV ?? "").split(":"), "T3CODE_TELEMETRY_ENABLED");
992996
}).pipe(
993997
Effect.provide(
994998
DesktopBackendConfiguration.layer.pipe(
@@ -1009,6 +1013,7 @@ describe("DesktopBackendConfiguration", () => {
10091013
} finally {
10101014
restoreEnv("WSLENV", previousWslEnv);
10111015
restoreEnv("OTEL_SDK_DISABLED", previousDisabled);
1016+
restoreEnv("T3CODE_TELEMETRY_ENABLED", previousTelemetry);
10121017
}
10131018
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
10141019
);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const DESKTOP_BACKEND_ENV_NAMES = [
101101
const WSL_FORWARDED_ENV_NAMES = [
102102
"OPENAI_API_KEY",
103103
"ANTHROPIC_API_KEY",
104+
"T3CODE_TELEMETRY_ENABLED",
104105
// Otherwise the WSL server keeps exporting to endpoints from the bootstrap.
105106
"T3CODE_OTEL_SDK_DISABLED",
106107
"OTEL_SDK_DISABLED",

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const SET_WSL_BACKEND_ENABLED_CHANNEL = "desktop:set-wsl-backend-enabled"
6868
export const SET_WSL_DISTRO_CHANNEL = "desktop:set-wsl-distro";
6969
export const SET_WSL_ONLY_CHANNEL = "desktop:set-wsl-only";
7070
export const SSH_PASSWORD_PROMPT_CANCELLED_RESULT = "ssh-password-prompt-cancelled";
71+
export const PREVIEW_SET_FORWARDED_SHORTCUTS_CHANNEL = "desktop:preview-set-forwarded-shortcuts";
7172
export const PREVIEW_CREATE_TAB_CHANNEL = "desktop:preview-create-tab";
7273
export const PREVIEW_CLOSE_TAB_CHANNEL = "desktop:preview-close-tab";
7374
export const PREVIEW_REGISTER_WEBVIEW_CHANNEL = "desktop:preview-register-webview";

‎apps/desktop/src/ipc/methods/preview.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
PreviewAnnotationSubmissionResultSchema,
2121
DEFAULT_BROWSER_PROFILE_ID,
2222
INCOGNITO_BROWSER_PROFILE_ID,
23+
PreviewForwardedShortcut,
24+
MAX_KEYBINDINGS_COUNT,
2325
} from "@t3tools/contracts";
2426
import * as Effect from "effect/Effect";
2527
import * as Schema from "effect/Schema";
@@ -53,6 +55,16 @@ export const installPreviewEventForwarding = Effect.fn(
5355
);
5456
});
5557

58+
export const setForwardedShortcuts = DesktopIpc.makeIpcMethod({
59+
channel: IpcChannels.PREVIEW_SET_FORWARDED_SHORTCUTS_CHANNEL,
60+
payload: Schema.Array(PreviewForwardedShortcut).check(Schema.isMaxLength(MAX_KEYBINDINGS_COUNT)),
61+
result: Schema.Void,
62+
handler: Effect.fn("desktop.ipc.preview.setForwardedShortcuts")(function* (shortcuts) {
63+
const manager = yield* PreviewManager.PreviewManager;
64+
yield* manager.setForwardedShortcuts(shortcuts);
65+
}),
66+
});
67+
5668
export const createTab = DesktopIpc.makeIpcMethod({
5769
channel: IpcChannels.PREVIEW_CREATE_TAB_CHANNEL,
5870
payload: DesktopPreviewCreateTabInputSchema,
@@ -406,6 +418,7 @@ export const saveRecording = DesktopIpc.makeIpcMethod({
406418
});
407419

408420
export const methods = [
421+
setForwardedShortcuts,
409422
createTab,
410423
closeTab,
411424
registerWebview,

‎apps/desktop/src/preload.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ contextBridge.exposeInMainWorld("desktopBridge", {
299299
},
300300
},
301301
preview: {
302+
setForwardedShortcuts: (shortcuts) =>
303+
ipcRenderer.invoke(IpcChannels.PREVIEW_SET_FORWARDED_SHORTCUTS_CHANNEL, shortcuts),
302304
createTab: (tabId, defaults) =>
303305
ipcRenderer.invoke(IpcChannels.PREVIEW_CREATE_TAB_CHANNEL, {
304306
tabId,

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

Lines changed: 124 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
DesktopPreviewRecordingInputEvent,
77
} from "@t3tools/contracts";
88
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
9+
import { parseKeybindingShortcut } from "@t3tools/shared/keybindings";
910
import * as Cause from "effect/Cause";
1011
import * as Deferred from "effect/Deferred";
1112
import * as Effect from "effect/Effect";
@@ -269,32 +270,34 @@ const layerFileSystem = FileSystem.layerNoop({
269270
}),
270271
});
271272

272-
const layer = PreviewManager.layer.pipe(
273-
Layer.provideMerge(
274-
Layer.succeed(DesktopRendererHistory.DesktopRendererHistory, {
275-
register: () => Effect.void,
276-
recordMetrics: () => Effect.void,
277-
shutdown: Effect.void,
278-
}),
279-
),
280-
Layer.provideMerge(DesktopBrowserHost.layer),
281-
Layer.provideMerge(layerBrowserSession),
282-
Layer.provideMerge(layerEnvironment),
283-
Layer.provideMerge(layerFileSystem),
284-
Layer.provideMerge(Path.layer),
285-
Layer.provideMerge(NodeCrypto.layer),
286-
Layer.provideMerge(Layer.succeed(HostProcessPlatform, "darwin")),
287-
);
273+
const managerLayer = (platform: NodeJS.Platform = "darwin") =>
274+
PreviewManager.layer.pipe(
275+
Layer.provideMerge(
276+
Layer.succeed(DesktopRendererHistory.DesktopRendererHistory, {
277+
register: () => Effect.void,
278+
recordMetrics: () => Effect.void,
279+
shutdown: Effect.void,
280+
}),
281+
),
282+
Layer.provideMerge(DesktopBrowserHost.layer),
283+
Layer.provideMerge(layerBrowserSession),
284+
Layer.provideMerge(layerEnvironment),
285+
Layer.provideMerge(layerFileSystem),
286+
Layer.provideMerge(Path.layer),
287+
Layer.provideMerge(NodeCrypto.layer),
288+
Layer.provideMerge(Layer.succeed(HostProcessPlatform, platform)),
289+
);
288290

289291
const withManager = <A>(
290292
use: (
291293
manager: PreviewManager.PreviewManager["Service"],
292294
) => Effect.Effect<A, PreviewManager.PreviewManagerError, Scope.Scope>,
295+
platform: NodeJS.Platform = "darwin",
293296
) =>
294297
Effect.gen(function* () {
295298
const manager = yield* PreviewManager.PreviewManager;
296299
return yield* use(manager);
297-
}).pipe(Effect.provide(layer), Effect.scoped);
300+
}).pipe(Effect.provide(managerLayer(platform)), Effect.scoped);
298301

299302
interface TestCapturedPreviewImage {
300303
readonly toJPEG: () => Buffer;
@@ -574,7 +577,7 @@ describe("PreviewManager", () => {
574577
Effect.gen(function* () {
575578
const preview = makeFaviconWebContents();
576579
const sendInputEvent = vi.fn();
577-
const hostWebContents = { sendInputEvent };
580+
const hostWebContents = { sendInputEvent, isDestroyed: () => false };
578581
Object.assign(preview.webContents, { hostWebContents });
579582
fromId.mockReturnValue(preview.webContents);
580583
getFocusedWebContents.mockReturnValue(preview.webContents as never);
@@ -628,6 +631,108 @@ describe("PreviewManager", () => {
628631
),
629632
);
630633

634+
effectIt.effect.each([
635+
["mod+shift+t", "view.reopenClosed"],
636+
["ctrl+alt+u", "sidebar.toggle"],
637+
] as const)(
638+
"forwards only the configured command from the focused guest: %s",
639+
([chord, command]) =>
640+
withManager((manager) =>
641+
Effect.gen(function* () {
642+
const preview = makeFaviconWebContents();
643+
const send = vi.fn();
644+
Object.assign(preview.webContents, {
645+
hostWebContents: { isDestroyed: () => false, send },
646+
});
647+
fromId.mockReturnValue(preview.webContents);
648+
getFocusedWebContents.mockReturnValue(preview.webContents as never);
649+
yield* manager.createTab("tab_reopen");
650+
yield* manager.registerWebview("tab_reopen", 42);
651+
const shortcut = parseKeybindingShortcut(chord)!;
652+
yield* manager.setForwardedShortcuts([{ command, shortcut }]);
653+
const beforeInput = preview.listeners.get("before-input-event")!;
654+
const input = {
655+
type: "keyDown",
656+
key: shortcut.key.toUpperCase(),
657+
meta: shortcut.metaKey || shortcut.modKey,
658+
control: shortcut.ctrlKey,
659+
shift: shortcut.shiftKey,
660+
alt: shortcut.altKey,
661+
};
662+
const preventDefault = vi.fn();
663+
beforeInput({ preventDefault } as never, input as never);
664+
expect(preventDefault).toHaveBeenCalledOnce();
665+
expect(send).toHaveBeenCalledExactlyOnceWith("desktop:menu-action", command);
666+
for (const overrides of [
667+
{ isAutoRepeat: true },
668+
{ type: "keyUp" },
669+
{ shift: !input.shift },
670+
{ key: "x" },
671+
]) {
672+
preventDefault.mockClear();
673+
beforeInput({ preventDefault } as never, { ...input, ...overrides } as never);
674+
expect(preventDefault).toHaveBeenCalledTimes("isAutoRepeat" in overrides ? 1 : 0);
675+
expect(send).toHaveBeenCalledOnce();
676+
}
677+
getFocusedWebContents.mockReturnValue(null);
678+
preventDefault.mockClear();
679+
beforeInput({ preventDefault } as never, input as never);
680+
expect(preventDefault).not.toHaveBeenCalled();
681+
expect(send).toHaveBeenCalledOnce();
682+
getFocusedWebContents.mockReturnValue(preview.webContents as never);
683+
yield* manager.setForwardedShortcuts([]);
684+
beforeInput({ preventDefault } as never, input as never);
685+
expect(preventDefault).not.toHaveBeenCalled();
686+
expect(send).toHaveBeenCalledOnce();
687+
}),
688+
),
689+
);
690+
691+
effectIt.effect.each([
692+
["linux", "ctrl+alt+[", "[", "BracketLeft", false],
693+
["win32", "ctrl+alt+8", "[", "Digit8", false],
694+
["win32", "ctrl+alt+k", "K", "KeyK", false],
695+
["linux", "ctrl+alt+`", "Dead", "Backquote", false],
696+
["darwin", "ctrl+alt+[", "[", "BracketLeft", true],
697+
["linux", "ctrl+alt+f7", "F7", "F7", true],
698+
] as const)(
699+
"handles ambiguous preview chords on %s: %s",
700+
([platform, chord, key, code, expected]) =>
701+
withManager(
702+
(manager) =>
703+
Effect.gen(function* () {
704+
const preview = makeFaviconWebContents();
705+
const send = vi.fn();
706+
Object.assign(preview.webContents, {
707+
hostWebContents: { isDestroyed: () => false, send },
708+
});
709+
fromId.mockReturnValue(preview.webContents);
710+
getFocusedWebContents.mockReturnValue(preview.webContents as never);
711+
yield* manager.createTab("tab_alt_graph");
712+
yield* manager.registerWebview("tab_alt_graph", 42);
713+
yield* manager.setForwardedShortcuts([
714+
{ command: "view.reopenClosed", shortcut: parseKeybindingShortcut(chord)! },
715+
]);
716+
const preventDefault = vi.fn();
717+
preview.listeners.get("before-input-event")!(
718+
{ preventDefault } as never,
719+
{
720+
type: "keyDown",
721+
key,
722+
code,
723+
meta: false,
724+
control: true,
725+
shift: false,
726+
alt: true,
727+
} as never,
728+
);
729+
expect(preventDefault).toHaveBeenCalledTimes(expected ? 1 : 0);
730+
expect(send).toHaveBeenCalledTimes(expected ? 1 : 0);
731+
}),
732+
platform,
733+
),
734+
);
735+
631736
effectIt.effect("preserves focused browser editing in tabs and sign-in popups", () =>
632737
withManager((manager) =>
633738
Effect.gen(function* () {
@@ -2716,7 +2821,7 @@ describe("PreviewManager", () => {
27162821
expect(yield* nextType).toBe("attached");
27172822
yield* manager.closeTab("tab_1");
27182823
expect(yield* nextType).toBe("detached");
2719-
}).pipe(Effect.provide(layer), Effect.scoped),
2824+
}).pipe(Effect.provide(managerLayer()), Effect.scoped),
27202825
);
27212826

27222827
effectIt.effect("stops capture retries when the tab swaps during the retry delay", () =>

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import type {
2222
DesktopPreviewRecordingInputEvent,
2323
DesktopPreviewScreenshotArtifact,
2424
DesktopPreviewTabDefaults,
25+
PreviewForwardedShortcut,
2526
} from "@t3tools/contracts";
2627
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
28+
import { matchesKeybindingShortcut } from "@t3tools/shared/keybindings";
2729
import { normalizePreviewUrl } from "@t3tools/shared/preview";
2830
import {
2931
BrowserWindow,
@@ -58,7 +60,7 @@ import * as SynchronizedRef from "effect/SynchronizedRef";
5860

5961
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
6062
import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts";
61-
import { PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "../ipc/channels.ts";
63+
import { MENU_ACTION_CHANNEL, PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "../ipc/channels.ts";
6264
import * as DesktopBrowserHost from "./DesktopBrowserHost.ts";
6365
import * as BrowserSession from "./BrowserSession.ts";
6466
import {
@@ -555,6 +557,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
555557
const runFork = Effect.runForkWith(context);
556558
const resolvedArtifactDirectory = path.resolve(artifactDirectory);
557559

560+
let forwardedShortcuts: ReadonlyArray<PreviewForwardedShortcut> = [];
558561
const annotationThemeRef = yield* Ref.make(DEFAULT_ANNOTATION_THEME);
559562
const mainWindowRef = yield* Ref.make<Option.Option<BrowserWindow>>(Option.none());
560563
const tabsRef = yield* SynchronizedRef.make<ReadonlyMap<string, PreviewTabState>>(new Map());
@@ -1520,6 +1523,38 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
15201523
};
15211524
const beforeInput = (event: Electron.Event, input: Electron.Input): void => {
15221525
syncMenuShortcuts(wc, input);
1526+
const host = wc.hostWebContents;
1527+
const forwarded =
1528+
input.type === "keyDown" &&
1529+
!input.isComposing &&
1530+
host &&
1531+
!host.isDestroyed() &&
1532+
webContents.getFocusedWebContents() === wc &&
1533+
!(
1534+
hostPlatform !== "darwin" &&
1535+
input.control &&
1536+
input.alt &&
1537+
/^(?:[^a-zA-Z0-9]|Dead)$/u.test(input.key)
1538+
) &&
1539+
forwardedShortcuts.find(({ shortcut }) =>
1540+
matchesKeybindingShortcut(
1541+
{
1542+
key: input.key,
1543+
code: input.code,
1544+
metaKey: input.meta,
1545+
ctrlKey: input.control,
1546+
shiftKey: input.shift,
1547+
altKey: input.alt,
1548+
},
1549+
shortcut,
1550+
hostPlatform === "darwin" ? "MacIntel" : hostPlatform,
1551+
),
1552+
);
1553+
if (forwarded && host) {
1554+
event.preventDefault();
1555+
if (!input.isAutoRepeat) host.send(MENU_ACTION_CHANNEL, forwarded.command);
1556+
return;
1557+
}
15231558
if (isPreviewRefreshShortcut(input)) {
15241559
event.preventDefault();
15251560
runFork(
@@ -3324,6 +3359,10 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
33243359
setAudioMuted,
33253360
setColorScheme,
33263361
setMainWindow,
3362+
setForwardedShortcuts: (shortcuts: ReadonlyArray<PreviewForwardedShortcut>) =>
3363+
Effect.sync(() => {
3364+
forwardedShortcuts = shortcuts;
3365+
}),
33273366
startRecording,
33283367
closePictureInPicture,
33293368
stopRecording,
@@ -3484,6 +3523,9 @@ export class PreviewManager extends Context.Service<
34843523
PreviewManager,
34853524
{
34863525
readonly setMainWindow: (window: BrowserWindow) => Effect.Effect<void, PreviewManagerError>;
3526+
readonly setForwardedShortcuts: (
3527+
shortcuts: ReadonlyArray<PreviewForwardedShortcut>,
3528+
) => Effect.Effect<void>;
34873529
readonly getBrowserSession: (
34883530
scope?: string,
34893531
persistent?: boolean,
@@ -3595,6 +3637,7 @@ export const make = Effect.gen(function* PreviewManagerMake() {
35953637

35963638
return PreviewManager.of({
35973639
setMainWindow: operations.setMainWindow,
3640+
setForwardedShortcuts: operations.setForwardedShortcuts,
35983641
getBrowserSession: Effect.fn("PreviewManager.getBrowserSession")(
35993642
function* (scope, persistent, namespace) {
36003643
const session = yield* browserSession

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,13 @@ describe("DesktopShellEnvironment", () => {
268268
envOutput({
269269
PATH: "/home/linuxbrew/.linuxbrew/bin:/usr/bin",
270270
SSH_AUTH_SOCK: "/tmp/secretive.sock",
271+
T3CODE_TELEMETRY_ENABLED: "false",
271272
}),
272273
});
273274

274275
assert.equal(env.PATH, "/home/linuxbrew/.linuxbrew/bin:/usr/bin");
275276
assert.equal(env.SSH_AUTH_SOCK, "/tmp/secretive.sock");
277+
assert.equal(env.T3CODE_TELEMETRY_ENABLED, "false");
276278
}),
277279
);
278280

0 commit comments

Comments
 (0)