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