Skip to content

Commit ed6c013

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-31707
2 parents 97b3ab3 + fab95f3 commit ed6c013

588 files changed

Lines changed: 30111 additions & 7015 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.

‎.macroscope/ignore.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,7 @@ native/libghostty-vt/include/**
279279
# it needs. Regenerated by apps/mobile/scripts/generate-highlights.mts; review
280280
# that script and cpp/t3_highlights.c instead.
281281
apps/mobile/modules/t3-highlights/Vendor/**
282+
283+
# Nitro bindings for T3Highlights. Regenerated by `vp run generate:nitro` in
284+
# apps/mobile from modules/t3-highlights/src/T3Highlights.nitro.ts.
285+
apps/mobile/modules/t3-highlights/nitrogen/generated/**

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export const CHECK_SYSTEM_PERMISSION_CHANNEL = "desktop:check-system-permission"
121121

122122
export const PREVIEW_RECORDING_INPUT_CHANNEL = "desktop:preview-recording-input";
123123

124+
export const PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL = "desktop:preview-annotation-voice-event";
125+
export const PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL = "desktop:preview-annotation-voice-state";
126+
124127
export const RECEIVE_PROVIDER_AUTH_CALLBACK_CHANNEL = "desktop:receive-provider-auth-callback";
125128
export const CANCEL_PROVIDER_AUTH_CALLBACK_CHANNEL = "desktop:cancel-provider-auth-callback";
126129
export const TAKE_LEGACY_LOCAL_STORAGE_CHANNEL = "desktop:take-legacy-local-storage";

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
DesktopPreviewAnnotationSendEnabledInputSchema,
33
DesktopPreviewAnnotationThemeInputSchema,
4+
DesktopPreviewAnnotationVoiceStateSchema,
5+
DesktopPreviewPickElementInputSchema,
46
DesktopPreviewArtifactInputSchema,
57
DesktopPreviewConfigInputSchema,
68
DesktopPreviewNavigateInputSchema,
@@ -363,11 +365,21 @@ const setAnnotationTheme = DesktopIpc.makeIpcMethod({
363365

364366
const pickElement = DesktopIpc.makeIpcMethod({
365367
channel: IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL,
366-
payload: DesktopPreviewTabInputSchema,
368+
payload: DesktopPreviewPickElementInputSchema,
367369
result: Schema.NullOr(PreviewAnnotationSubmissionResultSchema),
368-
handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId }) {
370+
handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId, voice }) {
371+
const manager = yield* PreviewManager.PreviewManager;
372+
return yield* manager.pickElement(tabId, voice);
373+
}),
374+
});
375+
376+
const updateAnnotationVoice = DesktopIpc.makeIpcMethod({
377+
channel: IpcChannels.PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL,
378+
payload: DesktopPreviewAnnotationVoiceStateSchema,
379+
result: Schema.Void,
380+
handler: Effect.fn("desktop.ipc.preview.updateAnnotationVoice")(function* (state) {
369381
const manager = yield* PreviewManager.PreviewManager;
370-
return yield* manager.pickElement(tabId);
382+
yield* manager.updateAnnotationVoice(state);
371383
}),
372384
});
373385

@@ -428,6 +440,7 @@ const saveRecording = DesktopIpc.makeIpcMethod({
428440

429441
export const methods = [
430442
setForwardedShortcuts,
443+
updateAnnotationVoice,
431444
createTab,
432445
closeTab,
433446
registerWebview,

‎apps/desktop/src/preload.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
DesktopBridge,
3+
DesktopPreviewAnnotationVoiceEvent,
34
DesktopPreviewOpenLinkEvent,
45
DesktopPreviewPointerEvent,
56
DesktopPreviewRecordingInputEvent,
@@ -368,7 +369,20 @@ contextBridge.exposeInMainWorld("desktopBridge", {
368369
tabId,
369370
enabled,
370371
}),
371-
pickElement: (tabId) => ipcRenderer.invoke(IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL, { tabId }),
372+
annotationVoice: {
373+
onEvent: (listener) => {
374+
const onEvent = (_event: Electron.IpcRendererEvent, tabId: string, value: unknown) => {
375+
if (typeof tabId !== "string" || typeof value !== "object" || value === null) return;
376+
listener(tabId, value as DesktopPreviewAnnotationVoiceEvent);
377+
};
378+
ipcRenderer.on(IpcChannels.PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL, onEvent);
379+
return () => ipcRenderer.off(IpcChannels.PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL, onEvent);
380+
},
381+
update: (state) =>
382+
ipcRenderer.invoke(IpcChannels.PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL, state),
383+
},
384+
pickElement: (tabId, voice) =>
385+
ipcRenderer.invoke(IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL, { tabId, voice }),
372386
cancelPickElement: (tabId) =>
373387
ipcRenderer.invoke(IpcChannels.PREVIEW_CANCEL_PICK_ELEMENT_CHANNEL, { tabId }),
374388
captureScreenshot: (tabId) =>

‎apps/desktop/src/preview/Annotation.css‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
--t3-popover-foreground: oklch(0.269 0 0);
3737
--t3-primary: oklch(0.488 0.217 264);
3838
--t3-primary-foreground: white;
39+
--t3-destructive: oklch(0.577 0.245 27.325);
3940
--t3-muted: rgb(0 0 0 / 4%);
4041
--t3-muted-foreground: oklch(0.556 0 0);
4142
--t3-accent: rgb(0 0 0 / 4%);
@@ -66,3 +67,8 @@ textarea:focus-visible {
6667
outline: 2px solid color-mix(in srgb, var(--t3-ring) 72%, transparent);
6768
outline-offset: -2px;
6869
}
70+
71+
/* Utility display classes must not override the native hidden state. */
72+
[hidden] {
73+
display: none !important;
74+
}

‎apps/desktop/src/preview/AnnotationStyles.generated.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ export const RECORDING_CONTROLLER_CHANNEL = "preview:recording-controller";
1414
export const PASSKEY_CREATE_CHANNEL = "preview:passkey-create";
1515
export const PASSKEY_GET_CHANNEL = "preview:passkey-get";
1616
export const PASSKEY_BRIDGE_ARGUMENT = "--t3code-preview-passkey-bridge";
17+
export const ANNOTATION_VOICE_EVENT_CHANNEL = "preview:annotation-voice-event";
18+
export const ANNOTATION_VOICE_STATE_CHANNEL = "preview:annotation-voice-state";

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,70 @@ describe("PreviewManager", () => {
24432443
),
24442444
);
24452445

2446+
effectIt.effect("delivers annotation voice state only to the pick session that owns it", () =>
2447+
withManager((manager) =>
2448+
Effect.gen(function* () {
2449+
const firstReady = yield* Deferred.make<void>();
2450+
const secondReady = yield* Deferred.make<void>();
2451+
let registrations = 0;
2452+
const guest = {
2453+
...makeTestPreviewWebContents(async () => ({
2454+
toPNG: () => Buffer.from("unused"),
2455+
toJPEG: () => Buffer.from("unused"),
2456+
getSize: () => ({ width: 1, height: 1 }),
2457+
})),
2458+
isFocused: () => true,
2459+
focus: vi.fn(),
2460+
send: (channel: string, ...args: unknown[]) => {
2461+
webviewSend(channel, ...args);
2462+
if (channel === "preview:start-pick")
2463+
Deferred.doneUnsafe(registrations++ === 0 ? firstReady : secondReady, Effect.void);
2464+
},
2465+
once: vi.fn(),
2466+
ipc: { on: vi.fn(), off: vi.fn(), removeListener: vi.fn() },
2467+
};
2468+
fromId.mockReturnValue(guest as never);
2469+
yield* manager.createTab("tab_1");
2470+
yield* manager.registerWebview("tab_1", 42);
2471+
const first = yield* manager
2472+
.pickElement("tab_1", { sessionId: "first", shortcuts: [] })
2473+
.pipe(Effect.forkChild);
2474+
yield* Deferred.await(firstReady);
2475+
const state = {
2476+
tabId: "tab_1",
2477+
sessionId: "first",
2478+
available: true,
2479+
phase: "recording" as const,
2480+
status: "Recording",
2481+
errorAction: null,
2482+
preview: null,
2483+
freezesEditor: true,
2484+
blocksSubmission: true,
2485+
level: 0,
2486+
shortcutLabel: "Ctrl+D",
2487+
draft: { text: "Tighten spacing", cursor: 15 },
2488+
};
2489+
yield* manager.updateAnnotationVoice(state);
2490+
expect(webviewSend).toHaveBeenCalledWith("preview:annotation-voice-state", state);
2491+
const second = yield* manager
2492+
.pickElement("tab_1", { sessionId: "second", shortcuts: [] })
2493+
.pipe(Effect.forkChild);
2494+
yield* Deferred.await(secondReady);
2495+
expect(yield* Fiber.join(first)).toBeNull();
2496+
webviewSend.mockClear();
2497+
yield* manager.updateAnnotationVoice(state);
2498+
expect(webviewSend).not.toHaveBeenCalled();
2499+
yield* manager.updateAnnotationVoice({ ...state, sessionId: "second" });
2500+
expect(webviewSend).toHaveBeenCalledOnce();
2501+
yield* manager.cancelPickElement("tab_1");
2502+
expect(yield* Fiber.join(second)).toBeNull();
2503+
webviewSend.mockClear();
2504+
yield* manager.updateAnnotationVoice({ ...state, sessionId: "second" });
2505+
expect(webviewSend).not.toHaveBeenCalled();
2506+
}),
2507+
),
2508+
);
2509+
24462510
effectIt.effect("keeps annotation send grants isolated and updates an active pick", () =>
24472511
withManager((manager) =>
24482512
Effect.gen(function* () {

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

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as NodeZlib from "node:zlib";
22
import {
3+
DesktopPreviewAnnotationVoiceEventSchema,
34
DesktopPreviewRecordingInputSchema,
45
DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER,
56
} from "@t3tools/contracts";
67
import type {
78
DesktopPreviewAnnotationTheme,
9+
DesktopPreviewAnnotationVoiceConfig,
10+
DesktopPreviewAnnotationVoiceState,
811
DesktopPreviewColorScheme,
912
DesktopPreviewFavicon,
1013
DesktopPreviewOpenLinkEvent,
@@ -56,13 +59,19 @@ import * as SynchronizedRef from "effect/SynchronizedRef";
5659

5760
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
5861
import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts";
59-
import { MENU_ACTION_CHANNEL, PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "../ipc/channels.ts";
62+
import {
63+
MENU_ACTION_CHANNEL,
64+
PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL,
65+
PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL,
66+
} from "../ipc/channels.ts";
6067
import * as DesktopBrowserHost from "./DesktopBrowserHost.ts";
6168
import * as PreviewPasskeys from "./Passkeys.ts";
6269
import * as BrowserSession from "./BrowserSession.ts";
6370
import {
6471
ANNOTATION_CAPTURED_CHANNEL,
6572
ANNOTATION_SEND_ENABLED_CHANNEL,
73+
ANNOTATION_VOICE_EVENT_CHANNEL,
74+
ANNOTATION_VOICE_STATE_CHANNEL,
6675
ANNOTATION_THEME_CHANNEL,
6776
CANCEL_PICK_CHANNEL,
6877
ELEMENT_PICKED_CHANNEL,
@@ -396,9 +405,14 @@ interface PendingRecording {
396405
}
397406

398407
interface PickSession {
408+
readonly voiceSessionId?: string | undefined;
399409
readonly cancel: Effect.Effect<void>;
400410
}
401411

412+
const decodeAnnotationVoiceEvent = Schema.decodeUnknownOption(
413+
DesktopPreviewAnnotationVoiceEventSchema,
414+
);
415+
402416
interface BrowserControlSession {
403417
readonly webContentsId: number;
404418
// Retain the attached Debugger to prevent GC crashes (electron/electron#53376); wc.debugger throws after destruction.
@@ -2074,16 +2088,35 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
20742088
});
20752089
});
20762090

2077-
const pickElement = Effect.fn("PreviewManager.pickElement")(function* (tabId: string) {
2091+
// Voice state reaches a guest only while its pick session, by id, still owns the tab.
2092+
const updateAnnotationVoice = Effect.fn("PreviewManager.updateAnnotationVoice")(function* (
2093+
state: DesktopPreviewAnnotationVoiceState,
2094+
) {
2095+
const sessions = yield* Ref.get(pickSessionsRef);
2096+
if (sessions.get(state.tabId)?.voiceSessionId !== state.sessionId) return;
2097+
const wc = yield* requireWebContents(state.tabId);
2098+
yield* attempt({ operation: "annotationVoice.update", tabId: state.tabId }, () =>
2099+
wc.send(ANNOTATION_VOICE_STATE_CHANNEL, state),
2100+
);
2101+
});
2102+
2103+
const pickElement = Effect.fn("PreviewManager.pickElement")(function* (
2104+
tabId: string,
2105+
voice?: DesktopPreviewAnnotationVoiceConfig,
2106+
) {
20782107
const wc = yield* requireWebContents(tabId);
20792108
yield* cancelPickElement(tabId);
20802109
const annotationTheme = yield* Ref.get(annotationThemeRef);
20812110
return yield* Effect.callback<PreviewAnnotationSubmissionResult | null, PreviewManagerError>(
20822111
(resume) => {
2083-
const session: PickSession = { cancel: Effect.suspend(() => cancelPickSession()) };
2112+
const session: PickSession = {
2113+
voiceSessionId: voice?.sessionId,
2114+
cancel: Effect.suspend(() => cancelPickSession()),
2115+
};
20842116
const cleanup = Effect.fn("PreviewManager.cleanupPickElement")(function* () {
20852117
yield* attempt({ operation: "pickElement.cleanup", tabId, webContentsId: wc.id }, () => {
20862118
wc.ipc.removeListener(ELEMENT_PICKED_CHANNEL, onMessage);
2119+
wc.ipc.removeListener(ANNOTATION_VOICE_EVENT_CHANNEL, onVoiceEvent);
20872120
wc.off("destroyed", onDestroyed);
20882121
wc.off("did-start-navigation", onNavigated);
20892122
}).pipe(Effect.ignore);
@@ -2191,6 +2224,25 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
21912224
),
21922225
);
21932226
};
2227+
// Only this guest's listener sees these; the renderer still checks the session id.
2228+
const onVoiceEvent = (_event: Electron.IpcMainEvent, value: unknown) => {
2229+
const decoded = decodeAnnotationVoiceEvent(value);
2230+
if (settled || !voice || Option.isNone(decoded)) return;
2231+
if (decoded.value.sessionId !== voice.sessionId) return;
2232+
runFork(
2233+
Effect.gen(function* () {
2234+
const window = yield* Ref.get(mainWindowRef);
2235+
if (Option.isNone(window) || window.value.isDestroyed()) return;
2236+
yield* attempt({ operation: "annotationVoice.forward", tabId }, () =>
2237+
window.value.webContents.send(
2238+
PREVIEW_ANNOTATION_VOICE_EVENT_CHANNEL,
2239+
tabId,
2240+
decoded.value,
2241+
),
2242+
).pipe(Effect.ignore);
2243+
}),
2244+
);
2245+
};
21942246
const onDestroyed = () => settle(null);
21952247
const onNavigated = (
21962248
event: Electron.Event<Electron.WebContentsDidStartNavigationEventParams>,
@@ -2210,10 +2262,16 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
22102262
if (settled) return;
22112263
yield* attempt({ operation: "pickElement.register", tabId, webContentsId: wc.id }, () => {
22122264
wc.ipc.on(ELEMENT_PICKED_CHANNEL, onMessage);
2265+
if (voice) wc.ipc.on(ANNOTATION_VOICE_EVENT_CHANNEL, onVoiceEvent);
22132266
wc.once("destroyed", onDestroyed);
22142267
wc.on("did-start-navigation", onNavigated);
22152268
if (!wc.isFocused()) wc.focus();
2216-
wc.send(START_PICK_CHANNEL, annotationTheme, annotationSendEnabled.get(tabId) === true);
2269+
wc.send(
2270+
START_PICK_CHANNEL,
2271+
annotationTheme,
2272+
annotationSendEnabled.get(tabId) === true,
2273+
voice,
2274+
);
22172275
});
22182276
});
22192277
runFork(
@@ -3312,6 +3370,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
33123370
openPictureInPicture,
33133371
openDevTools,
33143372
pickElement,
3373+
updateAnnotationVoice,
33153374
prepareWebview,
33163375
reapplyZoom,
33173376
refresh,
@@ -3552,7 +3611,11 @@ export class PreviewManager extends Context.Service<
35523611
) => Effect.Effect<void, PreviewManagerError>;
35533612
readonly pickElement: (
35543613
tabId: string,
3614+
voice?: DesktopPreviewAnnotationVoiceConfig,
35553615
) => Effect.Effect<PreviewAnnotationSubmissionResult | null, PreviewManagerError>;
3616+
readonly updateAnnotationVoice: (
3617+
state: DesktopPreviewAnnotationVoiceState,
3618+
) => Effect.Effect<void, PreviewManagerError>;
35563619
readonly cancelPickElement: (tabId: string) => Effect.Effect<void, PreviewManagerError>;
35573620
readonly captureScreenshot: (
35583621
tabId: string,
@@ -3703,6 +3766,7 @@ export const make = Effect.gen(function* PreviewManagerMake() {
37033766
setAnnotationTheme: operations.setAnnotationTheme,
37043767
setAnnotationSendEnabled: operations.setAnnotationSendEnabled,
37053768
pickElement: operations.pickElement,
3769+
updateAnnotationVoice: operations.updateAnnotationVoice,
37063770
cancelPickElement: operations.cancelPickElement,
37073771
captureScreenshot: operations.captureScreenshot,
37083772
revealArtifact: operations.revealArtifact,

0 commit comments

Comments
 (0)