Open History to see the last commit
1import {
2 DesktopPreviewAnnotationThemeInputSchema,
3 DesktopPreviewArtifactInputSchema,
4 DesktopPreviewAutomationClickInputSchema,
5 DesktopPreviewAutomationEvaluateInputSchema,
6 DesktopPreviewAutomationPressInputSchema,
7 DesktopPreviewAutomationScrollInputSchema,
8 DesktopPreviewAutomationTypeInputSchema,
9 DesktopPreviewAutomationWaitForInputSchema,
10 DesktopPreviewConfigInputSchema,
11 DesktopPreviewNavigateInputSchema,
12 DesktopPreviewRecordingArtifactSchema,
13 DesktopPreviewRecordingSaveInputSchema,
14 DesktopPreviewRegisterWebviewInputSchema,
15 DesktopPreviewScreenshotArtifactSchema,
16 DesktopPreviewSetAudioMutedInputSchema,
17 DesktopPreviewSetColorSchemeInputSchema,
18 DesktopPreviewCreateTabInputSchema,
19 DesktopPreviewTabInputSchema,
20 DesktopPreviewWebviewConfigSchema,
21 PreviewAnnotationSubmissionResultSchema,
22 PreviewAutomationSnapshot,
23 PreviewAutomationStatus,
24} from "@t3tools/contracts";
25import * as Effect from "effect/Effect";
26import * as Schema from "effect/Schema";
27import * as NodeURL from "node:url";
28
29import * as ElectronWindow from "../../electron/ElectronWindow.ts";
30import * as PreviewManager from "../../preview/Manager.ts";
31import { PREVIEW_WEBVIEW_PREFERENCES } from "../../preview/WebviewPreferences.ts";
32import * as IpcChannels from "../channels.ts";
33import * as DesktopIpc from "../DesktopIpc.ts";
34
35export const installPreviewEventForwarding = Effect.fn(
36 "desktop.ipc.preview.installEventForwarding",
37)(function* () {
38 const electronWindow = yield* ElectronWindow.ElectronWindow;
39 const manager = yield* PreviewManager.PreviewManager;
40 yield* manager.subscribeStateChanges((tabId, state) =>
41 electronWindow.sendAll(IpcChannels.PREVIEW_STATE_CHANGE_CHANNEL, tabId, state),
42 );
43 yield* manager.subscribeRecordingFrames((frame) =>
44 electronWindow.sendAll(IpcChannels.PREVIEW_RECORDING_FRAME_CHANNEL, frame),
45 );
46 yield* manager.subscribePointerEvents((event) =>
47 electronWindow.sendAll(IpcChannels.PREVIEW_POINTER_EVENT_CHANNEL, event),
48 );
49});
50
51export const createTab = DesktopIpc.makeIpcMethod({
52 channel: IpcChannels.PREVIEW_CREATE_TAB_CHANNEL,
53 payload: DesktopPreviewCreateTabInputSchema,
54 result: Schema.Void,
55 handler: Effect.fn("desktop.ipc.preview.createTab")(function* ({
56 tabId,
57 zoomFactor,
58 colorScheme,
59 }) {
60 const manager = yield* PreviewManager.PreviewManager;
61 yield* manager.createTab(tabId, { zoomFactor, colorScheme });
62 }),
63});
64
65export const closeTab = DesktopIpc.makeIpcMethod({
66 channel: IpcChannels.PREVIEW_CLOSE_TAB_CHANNEL,
67 payload: DesktopPreviewTabInputSchema,
68 result: Schema.Void,
69 handler: Effect.fn("desktop.ipc.preview.closeTab")(function* ({ tabId }) {
70 const manager = yield* PreviewManager.PreviewManager;
71 yield* manager.closeTab(tabId);
72 }),
73});
74
75export const registerWebview = DesktopIpc.makeIpcMethod({
76 channel: IpcChannels.PREVIEW_REGISTER_WEBVIEW_CHANNEL,
77 payload: DesktopPreviewRegisterWebviewInputSchema,
78 result: Schema.Void,
79 handler: Effect.fn("desktop.ipc.preview.registerWebview")(function* ({ tabId, webContentsId }) {
80 const manager = yield* PreviewManager.PreviewManager;
81 yield* manager.registerWebview(tabId, webContentsId);
82 }),
83});
84
85export const navigate = DesktopIpc.makeIpcMethod({
86 channel: IpcChannels.PREVIEW_NAVIGATE_CHANNEL,
87 payload: DesktopPreviewNavigateInputSchema,
88 result: Schema.Void,
89 handler: Effect.fn("desktop.ipc.preview.navigate")(function* ({ tabId, url }) {
90 const manager = yield* PreviewManager.PreviewManager;
91 yield* manager.navigate(tabId, url);
92 }),
93});
94
95const tabMethod = (
96 channel: string,
97 name: string,
98 invoke: (
99 manager: PreviewManager.PreviewManager["Service"],
100 tabId: string,
101 ) => Effect.Effect<void, PreviewManager.PreviewManagerError>,
102) =>
103 DesktopIpc.makeIpcMethod({
104 channel,
105 payload: DesktopPreviewTabInputSchema,
106 result: Schema.Void,
107 handler: Effect.fn(name)(function* ({ tabId }) {
108 const manager = yield* PreviewManager.PreviewManager;
109 yield* invoke(manager, tabId);
110 }),
111 });
112
113export const goBack = tabMethod(
114 IpcChannels.PREVIEW_GO_BACK_CHANNEL,
115 "desktop.ipc.preview.goBack",
116 (manager, tabId) => manager.goBack(tabId),
117);
118export const goForward = tabMethod(
119 IpcChannels.PREVIEW_GO_FORWARD_CHANNEL,
120 "desktop.ipc.preview.goForward",
121 (manager, tabId) => manager.goForward(tabId),
122);
123export const refresh = tabMethod(
124 IpcChannels.PREVIEW_REFRESH_CHANNEL,
125 "desktop.ipc.preview.refresh",
126 (manager, tabId) => manager.refresh(tabId),
127);
128export const zoomIn = tabMethod(
129 IpcChannels.PREVIEW_ZOOM_IN_CHANNEL,
130 "desktop.ipc.preview.zoomIn",
131 (manager, tabId) => manager.zoomIn(tabId),
132);
133export const zoomOut = tabMethod(
134 IpcChannels.PREVIEW_ZOOM_OUT_CHANNEL,
135 "desktop.ipc.preview.zoomOut",
136 (manager, tabId) => manager.zoomOut(tabId),
137);
138export const resetZoom = tabMethod(
139 IpcChannels.PREVIEW_RESET_ZOOM_CHANNEL,
140 "desktop.ipc.preview.resetZoom",
141 (manager, tabId) => manager.resetZoom(tabId),
142);
143export const hardReload = tabMethod(
144 IpcChannels.PREVIEW_HARD_RELOAD_CHANNEL,
145 "desktop.ipc.preview.hardReload",
146 (manager, tabId) => manager.hardReload(tabId),
147);
148export const setColorScheme = DesktopIpc.makeIpcMethod({
149 channel: IpcChannels.PREVIEW_SET_COLOR_SCHEME_CHANNEL,
150 payload: DesktopPreviewSetColorSchemeInputSchema,
151 result: Schema.Void,
152 handler: Effect.fn("desktop.ipc.preview.setColorScheme")(function* ({ tabId, colorScheme }) {
153 const manager = yield* PreviewManager.PreviewManager;
154 yield* manager.setColorScheme(tabId, colorScheme);
155 }),
156});
157export const setAudioMuted = DesktopIpc.makeIpcMethod({
158 channel: IpcChannels.PREVIEW_SET_AUDIO_MUTED_CHANNEL,
159 payload: DesktopPreviewSetAudioMutedInputSchema,
160 result: Schema.Void,
161 handler: Effect.fn("desktop.ipc.preview.setAudioMuted")(function* ({ tabId, audioMuted }) {
162 const manager = yield* PreviewManager.PreviewManager;
163 yield* manager.setAudioMuted(tabId, audioMuted);
164 }),
165});
166export const openDevTools = tabMethod(
167 IpcChannels.PREVIEW_OPEN_DEVTOOLS_CHANNEL,
168 "desktop.ipc.preview.openDevTools",
169 (manager, tabId) => manager.openDevTools(tabId),
170);
171export const cancelPickElement = tabMethod(
172 IpcChannels.PREVIEW_CANCEL_PICK_ELEMENT_CHANNEL,
173 "desktop.ipc.preview.cancelPickElement",
174 (manager, tabId) => manager.cancelPickElement(tabId),
175);
176export const startRecording = tabMethod(
177 IpcChannels.PREVIEW_RECORDING_START_CHANNEL,
178 "desktop.ipc.preview.startRecording",
179 (manager, tabId) => manager.startRecording(tabId),
180);
181export const stopRecording = tabMethod(
182 IpcChannels.PREVIEW_RECORDING_STOP_CHANNEL,
183 "desktop.ipc.preview.stopRecording",
184 (manager, tabId) => manager.stopRecording(tabId),
185);
186export const openPictureInPicture = tabMethod(
187 IpcChannels.PREVIEW_PICTURE_IN_PICTURE_OPEN_CHANNEL,
188 "desktop.ipc.preview.openPictureInPicture",
189 (manager, tabId) => manager.openPictureInPicture(tabId),
190);
191export const closePictureInPicture = tabMethod(
192 IpcChannels.PREVIEW_PICTURE_IN_PICTURE_CLOSE_CHANNEL,
193 "desktop.ipc.preview.closePictureInPicture",
194 (manager, tabId) => manager.closePictureInPicture(tabId),
195);
196
197export const clearCookies = DesktopIpc.makeIpcMethod({
198 channel: IpcChannels.PREVIEW_CLEAR_COOKIES_CHANNEL,
199 payload: Schema.Void,
200 result: Schema.Void,
201 handler: Effect.fn("desktop.ipc.preview.clearCookies")(function* () {
202 const manager = yield* PreviewManager.PreviewManager;
203 yield* manager.clearCookies();
204 }),
205});
206
207export const clearCache = DesktopIpc.makeIpcMethod({
208 channel: IpcChannels.PREVIEW_CLEAR_CACHE_CHANNEL,
209 payload: Schema.Void,
210 result: Schema.Void,
211 handler: Effect.fn("desktop.ipc.preview.clearCache")(function* () {
212 const manager = yield* PreviewManager.PreviewManager;
213 yield* manager.clearCache();
214 }),
215});
216
217export const getPreviewConfig = DesktopIpc.makeIpcMethod({
218 channel: IpcChannels.PREVIEW_GET_CONFIG_CHANNEL,
219 payload: DesktopPreviewConfigInputSchema,
220 result: DesktopPreviewWebviewConfigSchema,
221 handler: Effect.fn("desktop.ipc.preview.getConfig")(function* ({ environmentId }) {
222 const manager = yield* PreviewManager.PreviewManager;
223 yield* manager.getBrowserSession(environmentId);
224 return {
225 partition: yield* manager.getBrowserPartition(environmentId),
226 webPreferences: PREVIEW_WEBVIEW_PREFERENCES,
227 preloadUrl: NodeURL.pathToFileURL(`${__dirname}/preview-pick-preload.cjs`).href,
228 };
229 }),
230});
231
232export const setAnnotationTheme = DesktopIpc.makeIpcMethod({
233 channel: IpcChannels.PREVIEW_SET_ANNOTATION_THEME_CHANNEL,
234 payload: DesktopPreviewAnnotationThemeInputSchema,
235 result: Schema.Void,
236 handler: Effect.fn("desktop.ipc.preview.setAnnotationTheme")(function* ({ theme }) {
237 const manager = yield* PreviewManager.PreviewManager;
238 yield* manager.setAnnotationTheme(theme);
239 }),
240});
241
242export const pickElement = DesktopIpc.makeIpcMethod({
243 channel: IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL,
244 payload: DesktopPreviewTabInputSchema,
245 result: Schema.NullOr(PreviewAnnotationSubmissionResultSchema),
246 handler: Effect.fn("desktop.ipc.preview.pickElement")(function* ({ tabId }) {
247 const manager = yield* PreviewManager.PreviewManager;
248 return yield* manager.pickElement(tabId);
249 }),
250});
251
252export const captureScreenshot = DesktopIpc.makeIpcMethod({
253 channel: IpcChannels.PREVIEW_CAPTURE_SCREENSHOT_CHANNEL,
254 payload: DesktopPreviewTabInputSchema,
255 result: DesktopPreviewScreenshotArtifactSchema,
256 handler: Effect.fn("desktop.ipc.preview.captureScreenshot")(function* ({ tabId }) {
257 const manager = yield* PreviewManager.PreviewManager;
258 return yield* manager.captureScreenshot(tabId);
259 }),
260});
261
262export const revealArtifact = DesktopIpc.makeIpcMethod({
263 channel: IpcChannels.PREVIEW_REVEAL_ARTIFACT_CHANNEL,
264 payload: DesktopPreviewArtifactInputSchema,
265 result: Schema.Void,
266 handler: Effect.fn("desktop.ipc.preview.revealArtifact")(function* ({ path }) {
267 const manager = yield* PreviewManager.PreviewManager;
268 yield* manager.revealArtifact(path);
269 }),
270});
271
272export const copyArtifactToClipboard = DesktopIpc.makeIpcMethod({
273 channel: IpcChannels.PREVIEW_COPY_ARTIFACT_CHANNEL,
274 payload: DesktopPreviewArtifactInputSchema,
275 result: Schema.Void,
276 handler: Effect.fn("desktop.ipc.preview.copyArtifactToClipboard")(function* ({ path }) {
277 const manager = yield* PreviewManager.PreviewManager;
278 yield* manager.copyArtifactToClipboard(path);
279 }),
280});
281
282export const automationStatus = DesktopIpc.makeIpcMethod({
283 channel: IpcChannels.PREVIEW_AUTOMATION_STATUS_CHANNEL,
284 payload: DesktopPreviewTabInputSchema,
285 result: PreviewAutomationStatus,
286 handler: Effect.fn("desktop.ipc.preview.automationStatus")(function* ({ tabId }) {
287 const manager = yield* PreviewManager.PreviewManager;
288 return yield* manager.automationStatus(tabId);
289 }),
290});
291
292export const automationSnapshot = DesktopIpc.makeIpcMethod({
293 channel: IpcChannels.PREVIEW_AUTOMATION_SNAPSHOT_CHANNEL,
294 payload: DesktopPreviewTabInputSchema,
295 result: PreviewAutomationSnapshot,
296 handler: Effect.fn("desktop.ipc.preview.automationSnapshot")(function* ({ tabId }) {
297 const manager = yield* PreviewManager.PreviewManager;
298 return yield* manager.automationSnapshot(tabId);
299 }),
300});
301
302export const automationClick = DesktopIpc.makeIpcMethod({
303 channel: IpcChannels.PREVIEW_AUTOMATION_CLICK_CHANNEL,
304 payload: DesktopPreviewAutomationClickInputSchema,
305 result: Schema.Void,
306 handler: Effect.fn("desktop.ipc.preview.automationClick")(function* ({ tabId, input }) {
307 const manager = yield* PreviewManager.PreviewManager;
308 yield* manager.automationClick(tabId, input);
309 }),
310});
311
312export const automationType = DesktopIpc.makeIpcMethod({
313 channel: IpcChannels.PREVIEW_AUTOMATION_TYPE_CHANNEL,
314 payload: DesktopPreviewAutomationTypeInputSchema,
315 result: Schema.Void,
316 handler: Effect.fn("desktop.ipc.preview.automationType")(function* ({ tabId, input }) {
317 const manager = yield* PreviewManager.PreviewManager;
318 yield* manager.automationType(tabId, input);
319 }),
320});
321
322export const automationPress = DesktopIpc.makeIpcMethod({
323 channel: IpcChannels.PREVIEW_AUTOMATION_PRESS_CHANNEL,
324 payload: DesktopPreviewAutomationPressInputSchema,
325 result: Schema.Void,
326 handler: Effect.fn("desktop.ipc.preview.automationPress")(function* ({ tabId, input }) {
327 const manager = yield* PreviewManager.PreviewManager;
328 yield* manager.automationPress(tabId, input);
329 }),
330});
331
332export const automationScroll = DesktopIpc.makeIpcMethod({
333 channel: IpcChannels.PREVIEW_AUTOMATION_SCROLL_CHANNEL,
334 payload: DesktopPreviewAutomationScrollInputSchema,
335 result: Schema.Void,
336 handler: Effect.fn("desktop.ipc.preview.automationScroll")(function* ({ tabId, input }) {
337 const manager = yield* PreviewManager.PreviewManager;
338 yield* manager.automationScroll(tabId, input);
339 }),
340});
341
342export const automationEvaluate = DesktopIpc.makeIpcMethod({
343 channel: IpcChannels.PREVIEW_AUTOMATION_EVALUATE_CHANNEL,
344 payload: DesktopPreviewAutomationEvaluateInputSchema,
345 result: Schema.Unknown,
346 handler: Effect.fn("desktop.ipc.preview.automationEvaluate")(function* ({ tabId, input }) {
347 const manager = yield* PreviewManager.PreviewManager;
348 return yield* manager.automationEvaluate(tabId, input);
349 }),
350});
351
352export const automationWaitFor = DesktopIpc.makeIpcMethod({
353 channel: IpcChannels.PREVIEW_AUTOMATION_WAIT_FOR_CHANNEL,
354 payload: DesktopPreviewAutomationWaitForInputSchema,
355 result: Schema.Void,
356 handler: Effect.fn("desktop.ipc.preview.automationWaitFor")(function* ({ tabId, input }) {
357 const manager = yield* PreviewManager.PreviewManager;
358 yield* manager.automationWaitFor(tabId, input);
359 }),
360});
361
362export const saveRecording = DesktopIpc.makeIpcMethod({
363 channel: IpcChannels.PREVIEW_RECORDING_SAVE_CHANNEL,
364 payload: DesktopPreviewRecordingSaveInputSchema,
365 result: DesktopPreviewRecordingArtifactSchema,
366 handler: Effect.fn("desktop.ipc.preview.saveRecording")(function* ({ tabId, mimeType, data }) {
367 const manager = yield* PreviewManager.PreviewManager;
368 return yield* manager.saveRecording(tabId, mimeType, data);
369 }),
370});
371
372export const methods = [
373 createTab,
374 closeTab,
375 registerWebview,
376 navigate,
377 goBack,
378 goForward,
379 refresh,
380 zoomIn,
381 zoomOut,
382 resetZoom,
383 hardReload,
384 setColorScheme,
385 setAudioMuted,
386 openDevTools,
387 clearCookies,
388 clearCache,
389 getPreviewConfig,
390 setAnnotationTheme,
391 pickElement,
392 cancelPickElement,
393 captureScreenshot,
394 revealArtifact,
395 copyArtifactToClipboard,
396 openPictureInPicture,
397 closePictureInPicture,
398 automationStatus,
399 automationSnapshot,
400 automationClick,
401 automationType,
402 automationPress,
403 automationScroll,
404 automationEvaluate,
405 automationWaitFor,
406 startRecording,
407 stopRecording,
408 saveRecording,
409] as const;