Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/desktop/src/ipc/DesktopIpcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
const ipc = yield* DesktopIpc.DesktopIpc;
yield* installNotificationBadge();
yield* PreviewIpc.installPreviewEventForwarding();
yield* ipc.handle(PreviewIpc.acknowledgeCapture);

yield* ipc.handle(AppActivationIpc.setReady);
yield* ipc.handle(AppActivationIpc.complete);
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/ipc/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export const PREVIEW_RECORDING_SAVE_CHANNEL = "desktop:preview-recording-save";
export const PREVIEW_RECORDING_FRAME_CHANNEL = "desktop:preview-recording-frame";
export const PREVIEW_STATE_CHANGE_CHANNEL = "desktop:preview-state-change";
export const PREVIEW_POINTER_EVENT_CHANNEL = "desktop:preview-pointer-event";
export const PREVIEW_CAPTURE_REQUEST_CHANNEL = "desktop:preview-capture-request";
export const PREVIEW_CAPTURE_READY_CHANNEL = "desktop:preview-capture-ready";
export const PREVIEW_OPEN_LINK_CHANNEL = "desktop:preview-open-link";

export const MAC_PERMISSION_HELPER_CHANNEL = "desktop:mac-permission-helper";
Expand Down
21 changes: 21 additions & 0 deletions apps/desktop/src/ipc/methods/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
import * as Option from "effect/Option";
import * as Stream from "effect/Stream";
import * as NodeURL from "node:url";

import * as ElectronWindow from "../../electron/ElectronWindow.ts";
Expand All @@ -36,12 +37,20 @@ import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts"
import { PREVIEW_WEBVIEW_PREFERENCES } from "../../preview/WebviewPreferences.ts";
import * as IpcChannels from "../channels.ts";
import * as DesktopIpc from "../DesktopIpc.ts";
import * as DesktopBrowserHost from "../../preview/DesktopBrowserHost.ts";

export const installPreviewEventForwarding = Effect.fn(
"desktop.ipc.preview.installEventForwarding",
)(function* () {
const electronWindow = yield* ElectronWindow.ElectronWindow;
const manager = yield* PreviewManager.PreviewManager;
const browserHost = yield* DesktopBrowserHost.DesktopBrowserHost;
yield* browserHost.captureRequests.pipe(
Stream.runForEach((event) =>
electronWindow.sendAll(IpcChannels.PREVIEW_CAPTURE_REQUEST_CHANNEL, event),
),
Effect.forkScoped,
);
yield* manager.subscribeStateChanges((tabId, state) =>
electronWindow.sendAll(IpcChannels.PREVIEW_STATE_CHANGE_CHANNEL, tabId, state),
);
Expand All @@ -59,6 +68,18 @@ export const installPreviewEventForwarding = Effect.fn(
);
});

export const acknowledgeCapture = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_CAPTURE_READY_CHANNEL,
payload: Schema.String,
result: Schema.Void,
handler: Effect.fn("desktop.ipc.preview.acknowledgeCapture")(function* (requestId, event) {
const main = yield* (yield* ElectronWindow.ElectronWindow).main;
if (!event || Option.isNone(main) || main.value.webContents.id !== event.sender.id) return;
const host = yield* DesktopBrowserHost.DesktopBrowserHost;
host.acknowledgeCapture(requestId);
}),
});

export const setForwardedShortcuts = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_SET_FORWARDED_SHORTCUTS_CHANNEL,
payload: Schema.Array(PreviewForwardedShortcut).check(Schema.isMaxLength(MAX_KEYBINDINGS_COUNT)),
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
DesktopBridge,
DesktopPreviewOpenLinkEvent,
DesktopPreviewPointerEvent,
DesktopPreviewCaptureRequest,
DesktopPreviewRecordingInputEvent,
DesktopPreviewRecordingFrame,
DesktopPreviewTabState,
Expand Down Expand Up @@ -417,6 +418,17 @@ contextBridge.exposeInMainWorld("desktopBridge", {
return () =>
ipcRenderer.removeListener(IpcChannels.PREVIEW_POINTER_EVENT_CHANNEL, wrappedListener);
},
acknowledgeCapture: (requestId) =>
ipcRenderer.invoke(IpcChannels.PREVIEW_CAPTURE_READY_CHANNEL, requestId),
onCaptureRequest: (listener) => {
const wrappedListener = (
_event: Electron.IpcRendererEvent,
request: DesktopPreviewCaptureRequest,
) => listener(request);
ipcRenderer.on(IpcChannels.PREVIEW_CAPTURE_REQUEST_CHANNEL, wrappedListener);
return () =>
ipcRenderer.removeListener(IpcChannels.PREVIEW_CAPTURE_REQUEST_CHANNEL, wrappedListener);
},
onOpenLink: (listener) => {
const wrappedListener = (_event: Electron.IpcRendererEvent, linkEvent: unknown) => {
if (typeof linkEvent !== "object" || linkEvent === null) return;
Expand Down
Loading
Loading