Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

preview.ts

603 lines22.0 KB

1import {
2 DesktopPreviewAnnotationSendEnabledInputSchema,
3 DesktopPreviewAnnotationThemeInputSchema,
4 DesktopPreviewAnnotationVoiceStateSchema,
5 DesktopPreviewPickElementInputSchema,
6 DesktopPreviewArtifactInputSchema,
7 DesktopPreviewConfigInputSchema,
8 DesktopPreviewFindInPageInputSchema,
9 DesktopPreviewNavigateInputSchema,
10 DesktopPreviewRecordingArtifactSchema,
11 DesktopPreviewReadArtifactInputSchema,
12 DesktopPreviewRecordingSaveInputSchema,
13 DesktopPreviewRegisterWebviewInputSchema,
14 DesktopPreviewScreenshotArtifactSchema,
15 DesktopPreviewSetAudioMutedInputSchema,
16 DesktopPreviewSetShownInputSchema,
17 DesktopPreviewSetCaptureDrawnInputSchema,
18 DesktopPreviewSetColorSchemeInputSchema,
19 DesktopPreviewSetZoomFactorInputSchema,
20 BrowserImportResult,
21 BrowserImportSource,
22 DesktopPreviewClearDataInputSchema,
23 DesktopPreviewImportCookiesInputSchema,
24 DesktopPreviewCreateTabInputSchema,
25 DesktopPreviewTabInputSchema,
26 DesktopPreviewTunnelAccessResolutionInputSchema,
27 DesktopPortForwardInputSchema,
28 DesktopPortForwardSchema,
29 DesktopSharesLoopbackInputSchema,
30 DesktopPreviewWebviewConfigSchema,
31 PreviewAnnotationSubmissionResultSchema,
32 PreviewCaptureFailure,
33 DEFAULT_BROWSER_PROFILE_ID,
34 INCOGNITO_BROWSER_PROFILE_ID,
35 PreviewForwardedShortcut,
36 MAX_KEYBINDINGS_COUNT,
37} from "@t3tools/contracts";
38import * as Effect from "effect/Effect";
39import * as Schema from "effect/Schema";
40import * as Option from "effect/Option";
41import * as NodeURL from "node:url";
42​
43import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
44import * as ElectronWindow from "../../electron/ElectronWindow.ts";
45import * as BrowserImport from "../../preview/BrowserImport/BrowserImport.ts";
46import * as LoopbackTunnel from "../../preview/LoopbackTunnel.ts";
47import * as PreviewManager from "../../preview/Manager.ts";
48import { normalizeCaptureFailure } from "../../preview/captureErrors.ts";
49import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts";
50import { PREVIEW_WEBVIEW_PREFERENCES } from "../../preview/WebviewPreferences.ts";
51import * as IpcChannels from "../channels.ts";
52import * as DesktopIpc from "../DesktopIpc.ts";
53​
54export const installPreviewEventForwarding = Effect.fn(
55 "desktop.ipc.preview.installEventForwarding",
56)(function* () {
57 const electronWindow = yield* ElectronWindow.ElectronWindow;
58 const manager = yield* PreviewManager.PreviewManager;
59 yield* manager.subscribeStateChanges((tabId, state) =>
60 electronWindow.sendAll(IpcChannels.PREVIEW_STATE_CHANGE_CHANNEL, tabId, state),
61 );
62 yield* manager.subscribeRecordingInputs((event) =>
63 electronWindow.sendAll(IpcChannels.PREVIEW_RECORDING_INPUT_CHANNEL, event),
64 );
65 yield* manager.subscribePointerEvents((event) =>
66 electronWindow.sendAll(IpcChannels.PREVIEW_POINTER_EVENT_CHANNEL, event),
67 );
68 yield* manager.subscribeOpenLinks((event) =>
69 electronWindow.sendAll(IpcChannels.PREVIEW_OPEN_LINK_CHANNEL, event),
70 );
71 yield* manager.subscribeFindResults((event) =>
72 electronWindow.sendAll(IpcChannels.PREVIEW_FIND_RESULT_CHANNEL, event),
73 );
74 const tunnel = yield* LoopbackTunnel.LoopbackTunnel;
75 yield* tunnel.subscribeForwards((forwards) =>
76 electronWindow.sendAll(IpcChannels.PORT_FORWARD_CHANGE_CHANNEL, forwards),
77 );
78});
79​
80const setForwardedShortcuts = DesktopIpc.makeIpcMethod({
81 channel: IpcChannels.PREVIEW_SET_FORWARDED_SHORTCUTS_CHANNEL,
82 payload: Schema.Array(PreviewForwardedShortcut).check(Schema.isMaxLength(MAX_KEYBINDINGS_COUNT)),
83 result: Schema.Void,
84 handler: Effect.fn("desktop.ipc.preview.setForwardedShortcuts")(function* (shortcuts) {
85 const manager = yield* PreviewManager.PreviewManager;
86 yield* manager.setForwardedShortcuts(shortcuts);
87 }),
88});
89​
90const createTab = DesktopIpc.makeIpcMethod({
91 channel: IpcChannels.PREVIEW_CREATE_TAB_CHANNEL,
92 payload: DesktopPreviewCreateTabInputSchema,
93 result: Schema.Void,
94 handler: Effect.fn("desktop.ipc.preview.createTab")(function* ({
95 tabId,
96 zoomFactor,
97 colorScheme,
98 serverTab,
99 }) {
100 const manager = yield* PreviewManager.PreviewManager;
101 yield* manager.createTab(tabId, { zoomFactor, colorScheme, serverTab });
102 }),
103});
104​
105const closeTab = DesktopIpc.makeIpcMethod({
106 channel: IpcChannels.PREVIEW_CLOSE_TAB_CHANNEL,
107 payload: DesktopPreviewTabInputSchema,
108 result: Schema.Void,
109 handler: Effect.fn("desktop.ipc.preview.closeTab")(function* ({ tabId }) {
110 const manager = yield* PreviewManager.PreviewManager;
111 yield* manager.closeTab(tabId);
112 }),
113});
114​
115const registerWebview = DesktopIpc.makeIpcMethod({
116 channel: IpcChannels.PREVIEW_REGISTER_WEBVIEW_CHANNEL,
117 payload: DesktopPreviewRegisterWebviewInputSchema,
118 result: Schema.Void,
119 handler: Effect.fn("desktop.ipc.preview.registerWebview")(function* ({ tabId, webContentsId }) {
120 const manager = yield* PreviewManager.PreviewManager;
121 yield* manager.registerWebview(tabId, webContentsId);
122 }),
123});
124​
125const navigate = DesktopIpc.makeIpcMethod({
126 channel: IpcChannels.PREVIEW_NAVIGATE_CHANNEL,
127 payload: DesktopPreviewNavigateInputSchema,
128 result: Schema.Void,
129 handler: Effect.fn("desktop.ipc.preview.navigate")(function* ({ tabId, url }) {
130 const manager = yield* PreviewManager.PreviewManager;
131 yield* manager.navigate(tabId, url);
132 }),
133});
134​
135const findInPage = DesktopIpc.makeIpcMethod({
136 channel: IpcChannels.PREVIEW_FIND_IN_PAGE_CHANNEL,
137 payload: DesktopPreviewFindInPageInputSchema,
138 result: Schema.Void,
139 handler: Effect.fn("desktop.ipc.preview.findInPage")(function* ({
140 tabId,
141 text,
142 forward,
143 newSession,
144 }) {
145 const manager = yield* PreviewManager.PreviewManager;
146 yield* manager.findInPage(tabId, text, { forward, newSession });
147 }),
148});
149​
150const tabMethod = (
151 channel: string,
152 name: string,
153 invoke: (
154 manager: PreviewManager.PreviewManager["Service"],
155 tabId: string,
156 ) => Effect.Effect<void, PreviewManager.PreviewManagerError>,
157) =>
158 DesktopIpc.makeIpcMethod({
159 channel,
160 payload: DesktopPreviewTabInputSchema,
161 result: Schema.Void,
162 handler: Effect.fn(name)(function* ({ tabId }) {
163 const manager = yield* PreviewManager.PreviewManager;
164 yield* invoke(manager, tabId);
165 }),
166 });
167​
168const goBack = tabMethod(
169 IpcChannels.PREVIEW_GO_BACK_CHANNEL,
170 "desktop.ipc.preview.goBack",
171 (manager, tabId) => manager.goBack(tabId),
172);
173const goForward = tabMethod(
174 IpcChannels.PREVIEW_GO_FORWARD_CHANNEL,
175 "desktop.ipc.preview.goForward",
176 (manager, tabId) => manager.goForward(tabId),
177);
178const refresh = tabMethod(
179 IpcChannels.PREVIEW_REFRESH_CHANNEL,
180 "desktop.ipc.preview.refresh",
181 (manager, tabId) => manager.refresh(tabId),
182);
183const stopLoading = tabMethod(
184 IpcChannels.PREVIEW_STOP_LOADING_CHANNEL,
185 "desktop.ipc.preview.stopLoading",
186 (manager, tabId) => manager.stopLoading(tabId),
187);
188const zoomIn = tabMethod(
189 IpcChannels.PREVIEW_ZOOM_IN_CHANNEL,
190 "desktop.ipc.preview.zoomIn",
191 (manager, tabId) => manager.zoomIn(tabId),
192);
193const zoomOut = tabMethod(
194 IpcChannels.PREVIEW_ZOOM_OUT_CHANNEL,
195 "desktop.ipc.preview.zoomOut",
196 (manager, tabId) => manager.zoomOut(tabId),
197);
198const resetZoom = tabMethod(
199 IpcChannels.PREVIEW_RESET_ZOOM_CHANNEL,
200 "desktop.ipc.preview.resetZoom",
201 (manager, tabId) => manager.resetZoom(tabId),
202);
203const hardReload = tabMethod(
204 IpcChannels.PREVIEW_HARD_RELOAD_CHANNEL,
205 "desktop.ipc.preview.hardReload",
206 (manager, tabId) => manager.hardReload(tabId),
207);
208const stopFindInPage = tabMethod(
209 IpcChannels.PREVIEW_STOP_FIND_IN_PAGE_CHANNEL,
210 "desktop.ipc.preview.stopFindInPage",
211 (manager, tabId) => manager.stopFindInPage(tabId),
212);
213const setZoomFactor = DesktopIpc.makeIpcMethod({
214 channel: IpcChannels.PREVIEW_SET_ZOOM_FACTOR_CHANNEL,
215 payload: DesktopPreviewSetZoomFactorInputSchema,
216 result: Schema.Void,
217 handler: Effect.fn("desktop.ipc.preview.setZoomFactor")(function* ({ tabId, zoomFactor }) {
218 const manager = yield* PreviewManager.PreviewManager;
219 yield* manager.setZoomFactor(tabId, zoomFactor);
220 }),
221});
222const setColorScheme = DesktopIpc.makeIpcMethod({
223 channel: IpcChannels.PREVIEW_SET_COLOR_SCHEME_CHANNEL,
224 payload: DesktopPreviewSetColorSchemeInputSchema,
225 result: Schema.Void,
226 handler: Effect.fn("desktop.ipc.preview.setColorScheme")(function* ({ tabId, colorScheme }) {
227 const manager = yield* PreviewManager.PreviewManager;
228 yield* manager.setColorScheme(tabId, colorScheme);
229 }),
230});
231const setAudioMuted = DesktopIpc.makeIpcMethod({
232 channel: IpcChannels.PREVIEW_SET_AUDIO_MUTED_CHANNEL,
233 payload: DesktopPreviewSetAudioMutedInputSchema,
234 result: Schema.Void,
235 handler: Effect.fn("desktop.ipc.preview.setAudioMuted")(function* ({ tabId, audioMuted }) {
236 const manager = yield* PreviewManager.PreviewManager;
237 yield* manager.setAudioMuted(tabId, audioMuted);
238 }),
239});
240const setShown = DesktopIpc.makeIpcMethod({
241 channel: IpcChannels.PREVIEW_SET_SHOWN_CHANNEL,
242 payload: DesktopPreviewSetShownInputSchema,
243 result: Schema.Void,
244 handler: Effect.fn("desktop.ipc.preview.setShown")(function* ({ tabId, shown }) {
245 const manager = yield* PreviewManager.PreviewManager;
246 yield* manager.setShown(tabId, shown);
247 }),
248});
249const setCaptureDrawn = DesktopIpc.makeIpcMethod({
250 channel: IpcChannels.PREVIEW_SET_CAPTURE_DRAWN_CHANNEL,
251 payload: DesktopPreviewSetCaptureDrawnInputSchema,
252 result: Schema.Void,
253 handler: Effect.fn("desktop.ipc.preview.setCaptureDrawn")(function* ({ tabId, drawn }) {
254 const manager = yield* PreviewManager.PreviewManager;
255 yield* manager.setCaptureDrawn(tabId, drawn);
256 }),
257});
258const openDevTools = tabMethod(
259 IpcChannels.PREVIEW_OPEN_DEVTOOLS_CHANNEL,
260 "desktop.ipc.preview.openDevTools",
261 (manager, tabId) => manager.openDevTools(tabId),
262);
263const cancelPickElement = tabMethod(
264 IpcChannels.PREVIEW_CANCEL_PICK_ELEMENT_CHANNEL,
265 "desktop.ipc.preview.cancelPickElement",
266 (manager, tabId) => manager.cancelPickElement(tabId),
267);
268export const startRecording = DesktopIpc.makeIpcMethod({
269 channel: IpcChannels.PREVIEW_RECORDING_START_CHANNEL,
270 payload: DesktopPreviewTabInputSchema,
271 // Void encodes any value as undefined, so the tagged failure must be tried first.
272 result: Schema.Union([PreviewCaptureFailure, Schema.Void]),
273 handler: Effect.fn("desktop.ipc.preview.startRecording")(function* ({ tabId }) {
274 const manager = yield* PreviewManager.PreviewManager;
275 const store = yield* DesktopClientSettings.DesktopClientSettings;
276 const settings = yield* store.get;
277 const options = Option.map(settings, (value) => ({
278 showKeyPresses: value.browserRecordingShowKeyPresses,
279 showMousePresses: value.browserRecordingShowMousePresses,
280 }));
281 return yield* manager
282 .startRecording(tabId, Option.getOrUndefined(options))
283 .pipe(
284 Effect.catch((error) => Effect.succeed(normalizeCaptureFailure(error, "recording-start"))),
285 );
286 }),
287});
288const stopRecording = tabMethod(
289 IpcChannels.PREVIEW_RECORDING_STOP_CHANNEL,
290 "desktop.ipc.preview.stopRecording",
291 (manager, tabId) => manager.stopRecording(tabId),
292);
293const openPictureInPicture = tabMethod(
294 IpcChannels.PREVIEW_PICTURE_IN_PICTURE_OPEN_CHANNEL,
295 "desktop.ipc.preview.openPictureInPicture",
296 (manager, tabId) => manager.openPictureInPicture(tabId),
297);
298const closePictureInPicture = tabMethod(
299 IpcChannels.PREVIEW_PICTURE_IN_PICTURE_CLOSE_CHANNEL,
300 "desktop.ipc.preview.closePictureInPicture",
301 (manager, tabId) => manager.closePictureInPicture(tabId),
302);
303​
304const clearCookies = DesktopIpc.makeIpcMethod({
305 channel: IpcChannels.PREVIEW_CLEAR_COOKIES_CHANNEL,
306 payload: DesktopPreviewClearDataInputSchema,
307 result: Schema.Void,
308 handler: Effect.fn("desktop.ipc.preview.clearCookies")(function* ({ environmentId, profileId }) {
309 const manager = yield* PreviewManager.PreviewManager;
310 yield* manager.clearCookies(yield* resolveClearPartitions(manager, environmentId, profileId));
311 }),
312});
313​
314const clearCache = DesktopIpc.makeIpcMethod({
315 channel: IpcChannels.PREVIEW_CLEAR_CACHE_CHANNEL,
316 payload: DesktopPreviewClearDataInputSchema,
317 result: Schema.Void,
318 handler: Effect.fn("desktop.ipc.preview.clearCache")(function* ({ environmentId, profileId }) {
319 const manager = yield* PreviewManager.PreviewManager;
320 yield* manager.clearCache(yield* resolveClearPartitions(manager, environmentId, profileId));
321 }),
322});
323​
324/** Keep the default profile's bare environment id so existing logins retain their partition. */
325export function resolvePartitionScope(
326 environmentId: string,
327 profileId: string | undefined,
328): {
329 readonly scope: string;
330 readonly persistent: boolean;
331 readonly namespace?: "profile";
332} {
333 if (profileId === undefined || profileId === DEFAULT_BROWSER_PROFILE_ID) {
334 return { scope: environmentId, persistent: true };
335 }
336 // JSON framing preserves lone UTF-16 surrogates; URI encoding throws and replacement would collide.
337 return {
338 scope: JSON.stringify([environmentId, profileId]),
339 persistent: profileId !== INCOGNITO_BROWSER_PROFILE_ID,
340 namespace: "profile" as const,
341 };
343​
344/** Omitting a profile clears every partition; a named profile clears only its own partition. */
345const resolveClearPartitions = Effect.fn("desktop.ipc.preview.resolveClearPartitions")(function* (
346 manager: PreviewManager.PreviewManager["Service"],
347 environmentId: string,
348 profileId: string | undefined,
349) {
350 if (profileId === undefined) return undefined;
351 const { scope, persistent, namespace } = resolvePartitionScope(environmentId, profileId);
352 // getBrowserSession registers the partition; deriving its name alone leaves unopened profiles uncleared.
353 yield* manager.getBrowserSession(scope, persistent, namespace);
354 return [yield* manager.getBrowserPartition(scope, persistent, namespace)];
355});
356​
357const getPreviewConfig = DesktopIpc.makeIpcMethod({
358 channel: IpcChannels.PREVIEW_GET_CONFIG_CHANNEL,
359 payload: DesktopPreviewConfigInputSchema,
360 result: DesktopPreviewWebviewConfigSchema,
361 handler: Effect.fn("desktop.ipc.preview.getConfig")(function* ({
362 environmentId,
363 profileId,
364 tunnelLoopback,
365 }) {
366 const manager = yield* PreviewManager.PreviewManager;
367 const tunnel = yield* LoopbackTunnel.LoopbackTunnel;
368 const environment = yield* DesktopEnvironment.DesktopEnvironment;
369 const { scope, persistent, namespace } = resolvePartitionScope(environmentId, profileId);
370 // Session creation installs UA and permission handlers before a guest can attach.
371 const session = yield* manager.getBrowserSession(scope, persistent, namespace);
372 // Routed before the renderer learns the partition, so no guest loads loopback directly.
373 yield* tunnel.route({ environmentId, session, tunnelled: tunnelLoopback === true });
374 return {
375 partition: yield* manager.getBrowserPartition(scope, persistent, namespace),
376 webPreferences: PREVIEW_WEBVIEW_PREFERENCES,
377 preloadUrl: NodeURL.pathToFileURL(environment.previewPickPreloadPath).href,
378 };
379 }),
380});
381​
382const resolveTunnelAccess = DesktopIpc.makeIpcMethod({
383 channel: IpcChannels.PREVIEW_TUNNEL_ACCESS_RESOLVE_CHANNEL,
384 payload: DesktopPreviewTunnelAccessResolutionInputSchema,
385 result: Schema.Void,
386 handler: Effect.fn("desktop.ipc.preview.resolveTunnelAccess")(function* (input) {
387 const tunnel = yield* LoopbackTunnel.LoopbackTunnel;
388 yield* tunnel.resolveAccess(input);
389 }),
390});
391​
392const forwardPort = DesktopIpc.makeIpcMethod({
393 channel: IpcChannels.PORT_FORWARD_START_CHANNEL,
394 payload: DesktopPortForwardInputSchema,
395 result: DesktopPortForwardSchema,
396 handler: Effect.fn("desktop.ipc.preview.forwardPort")(function* (input) {
397 const tunnel = yield* LoopbackTunnel.LoopbackTunnel;
398 return yield* tunnel.forward(input);
399 }),
400});
401​
402const stopPortForward = DesktopIpc.makeIpcMethod({
403 channel: IpcChannels.PORT_FORWARD_STOP_CHANNEL,
404 payload: DesktopPortForwardInputSchema,
405 result: Schema.Void,
406 handler: Effect.fn("desktop.ipc.preview.stopPortForward")(function* (input) {
407 const tunnel = yield* LoopbackTunnel.LoopbackTunnel;
408 yield* tunnel.stopForward(input);
409 }),
410});
411​
412const listPortForwards = DesktopIpc.makeIpcMethod({
413 channel: IpcChannels.PORT_FORWARD_LIST_CHANNEL,
414 payload: Schema.Void,
415 result: Schema.Array(DesktopPortForwardSchema),
416 handler: Effect.fn("desktop.ipc.preview.listPortForwards")(function* () {
417 const tunnel = yield* LoopbackTunnel.LoopbackTunnel;
418 return yield* tunnel.forwards;
419 }),
420});
421​
422const sharesLoopback = DesktopIpc.makeIpcMethod({
423 channel: IpcChannels.PORT_FORWARD_SHARES_LOOPBACK_CHANNEL,
424 payload: DesktopSharesLoopbackInputSchema,
425 result: Schema.Boolean,
426 handler: Effect.fn("desktop.ipc.preview.sharesLoopback")(function* ({ environmentId }) {
427 const tunnel = yield* LoopbackTunnel.LoopbackTunnel;
428 return yield* tunnel.sharesLoopback(environmentId);
429 }),
430});
431​
432export const listBrowserImportSources = DesktopIpc.makeIpcMethod({
433 channel: IpcChannels.PREVIEW_IMPORT_SOURCES_CHANNEL,
434 payload: Schema.Void,
435 result: Schema.Array(BrowserImportSource),
436 handler: Effect.fn("desktop.ipc.preview.listBrowserImportSources")(function* () {
437 const browserImport = yield* BrowserImport.BrowserImport;
438 return yield* browserImport.listSources;
439 }),
440});
441​
442export const importBrowserCookies = DesktopIpc.makeIpcMethod({
443 channel: IpcChannels.PREVIEW_IMPORT_COOKIES_CHANNEL,
444 payload: DesktopPreviewImportCookiesInputSchema,
445 result: BrowserImportResult,
446 handler: Effect.fn("desktop.ipc.preview.importBrowserCookies")(function* ({
447 environmentId,
448 ...importInput
449 }) {
450 const browserImport = yield* BrowserImport.BrowserImport;
451 const { scope, persistent, namespace } = resolvePartitionScope(
452 environmentId,
453 importInput.targetProfileId,
454 );
455 return yield* browserImport.importCookies({
456 input: importInput,
457 scope,
458 persistent,
459 ...(namespace === undefined ? {} : { namespace }),
460 });
461 }),
462});
463​
464const setAnnotationTheme = DesktopIpc.makeIpcMethod({
465 channel: IpcChannels.PREVIEW_SET_ANNOTATION_THEME_CHANNEL,
466 payload: DesktopPreviewAnnotationThemeInputSchema,
467 result: Schema.Void,
468 handler: Effect.fn("desktop.ipc.preview.setAnnotationTheme")(function* ({ theme }) {
469 const manager = yield* PreviewManager.PreviewManager;
470 yield* manager.setAnnotationTheme(theme);
471 }),
472});
473​
474const pickElement = DesktopIpc.makeIpcMethod({
475 channel: IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL,
476 payload: DesktopPreviewPickElementInputSchema,
477 result: Schema.NullOr(PreviewAnnotationSubmissionResultSchema),
478 handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId, voice }) {
479 const manager = yield* PreviewManager.PreviewManager;
480 return yield* manager.pickElement(tabId, voice);
481 }),
482});
483​
484const updateAnnotationVoice = DesktopIpc.makeIpcMethod({
485 channel: IpcChannels.PREVIEW_ANNOTATION_VOICE_STATE_CHANNEL,
486 payload: DesktopPreviewAnnotationVoiceStateSchema,
487 result: Schema.Void,
488 handler: Effect.fn("desktop.ipc.preview.updateAnnotationVoice")(function* (state) {
489 const manager = yield* PreviewManager.PreviewManager;
490 yield* manager.updateAnnotationVoice(state);
491 }),
492});
493​
494const setAnnotationSendEnabled = DesktopIpc.makeIpcMethod({
495 channel: IpcChannels.PREVIEW_SET_ANNOTATION_SEND_ENABLED_CHANNEL,
496 payload: DesktopPreviewAnnotationSendEnabledInputSchema,
497 result: Schema.Void,
498 handler: Effect.fn("desktop.ipc.preview.setAnnotationSendEnabled")(function* ({
499 tabId,
500 enabled,
501 }) {
502 const manager = yield* PreviewManager.PreviewManager;
503 yield* manager.setAnnotationSendEnabled(tabId, enabled);
504 }),
505});
506​
507export const captureScreenshot = DesktopIpc.makeIpcMethod({
508 channel: IpcChannels.PREVIEW_CAPTURE_SCREENSHOT_CHANNEL,
509 payload: DesktopPreviewTabInputSchema,
510 result: Schema.Union([DesktopPreviewScreenshotArtifactSchema, PreviewCaptureFailure]),
511 handler: Effect.fn("desktop.ipc.preview.captureScreenshot")(function* ({ tabId }) {
512 const manager = yield* PreviewManager.PreviewManager;
513 return yield* manager
514 .captureScreenshot(tabId)
515 .pipe(Effect.catch((error) => Effect.succeed(normalizeCaptureFailure(error, "screenshot"))));
516 }),
517});
518​
519const revealArtifact = DesktopIpc.makeIpcMethod({
520 channel: IpcChannels.PREVIEW_REVEAL_ARTIFACT_CHANNEL,
521 payload: DesktopPreviewArtifactInputSchema,
522 result: Schema.Void,
523 handler: Effect.fn("desktop.ipc.preview.revealArtifact")(function* ({ path }) {
524 const manager = yield* PreviewManager.PreviewManager;
525 yield* manager.revealArtifact(path);
526 }),
527});
528​
529const copyArtifactToClipboard = DesktopIpc.makeIpcMethod({
530 channel: IpcChannels.PREVIEW_COPY_ARTIFACT_CHANNEL,
531 payload: DesktopPreviewArtifactInputSchema,
532 result: Schema.Void,
533 handler: Effect.fn("desktop.ipc.preview.copyArtifactToClipboard")(function* ({ path }) {
534 const manager = yield* PreviewManager.PreviewManager;
535 yield* manager.copyArtifactToClipboard(path);
536 }),
537});
538​
539const readArtifact = DesktopIpc.makeIpcMethod({
540 channel: IpcChannels.PREVIEW_READ_ARTIFACT_CHANNEL,
541 payload: DesktopPreviewReadArtifactInputSchema,
542 result: Schema.Uint8Array,
543 handler: Effect.fn("desktop.ipc.preview.readArtifact")(function* ({ artifactId, maxBytes }) {
544 const manager = yield* PreviewManager.PreviewManager;
545 return yield* manager.readArtifact(artifactId, maxBytes);
546 }),
547});
548​
549const saveRecording = DesktopIpc.makeIpcMethod({
550 channel: IpcChannels.PREVIEW_RECORDING_SAVE_CHANNEL,
551 payload: DesktopPreviewRecordingSaveInputSchema,
552 result: DesktopPreviewRecordingArtifactSchema,
553 handler: Effect.fn("desktop.ipc.preview.saveRecording")(function* ({ tabId, mimeType, data }) {
554 const manager = yield* PreviewManager.PreviewManager;
555 return yield* manager.saveRecording(tabId, mimeType, data);
556 }),
557});
558​
559export const methods = [
560 setForwardedShortcuts,
561 updateAnnotationVoice,
562 createTab,
563 closeTab,
564 registerWebview,
565 navigate,
566 goBack,
567 goForward,
568 refresh,
569 stopLoading,
570 zoomIn,
571 zoomOut,
572 resetZoom,
573 hardReload,
574 findInPage,
575 stopFindInPage,
576 setColorScheme,
577 setZoomFactor,
578 setAudioMuted,
579 setShown,
580 setCaptureDrawn,
581 openDevTools,
582 clearCookies,
583 clearCache,
584 getPreviewConfig,
585 resolveTunnelAccess,
586 forwardPort,
587 stopPortForward,
588 listPortForwards,
589 sharesLoopback,
590 setAnnotationTheme,
591 setAnnotationSendEnabled,
592 pickElement,
593 cancelPickElement,
594 captureScreenshot,
595 revealArtifact,
596 copyArtifactToClipboard,
597 readArtifact,
598 openPictureInPicture,
599 closePictureInPicture,
600 startRecording,
601 stopRecording,
602 saveRecording,
603] as const;