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