Skip to content
Merged
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
30 changes: 16 additions & 14 deletions apps/desktop/src/ipc/DesktopIpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Schema from "effect/Schema";
import * as Scope from "effect/Scope";

Expand Down Expand Up @@ -33,20 +34,19 @@ export interface DesktopSyncIpcMethod<E, R> {
readonly handler: () => Effect.Effect<unknown, E, R>;
}

export interface DesktopIpcShape {
readonly handle: <E, R>(
input: DesktopIpcMethod<E, R>,
) => Effect.Effect<void, never, R | Scope.Scope>;
readonly handleSync: <E, R>(
input: DesktopSyncIpcMethod<E, R>,
) => Effect.Effect<void, never, R | Scope.Scope>;
}

export class DesktopIpc extends Context.Service<DesktopIpc, DesktopIpcShape>()(
"@t3tools/desktop/ipc/DesktopIpc",
) {}

export const make = (ipcMain: DesktopIpcMain): DesktopIpcShape =>
export class DesktopIpc extends Context.Service<
DesktopIpc,
{
readonly handle: <E, R>(
input: DesktopIpcMethod<E, R>,
) => Effect.Effect<void, never, R | Scope.Scope>;
readonly handleSync: <E, R>(
input: DesktopSyncIpcMethod<E, R>,
) => Effect.Effect<void, never, R | Scope.Scope>;
}
>()("@t3tools/desktop/ipc/DesktopIpc") {}

export const make = (ipcMain: DesktopIpcMain): DesktopIpc["Service"] =>
DesktopIpc.of({
handle: Effect.fn("desktop.ipc.registerInvoke")(function* <E, R>({
channel,
Expand Down Expand Up @@ -97,6 +97,8 @@ export const make = (ipcMain: DesktopIpcMain): DesktopIpcShape =>
}),
});

export const layer = (ipcMain: DesktopIpcMain) => Layer.succeed(DesktopIpc, make(ipcMain));

/**
* Convenience helpers for creating IPC methods
*/
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/ipc/methods/clientSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as Schema from "effect/Schema";

import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts";
import * as IpcChannels from "../channels.ts";
import { makeIpcMethod } from "../DesktopIpc.ts";
import * as DesktopIpc from "../DesktopIpc.ts";

export const getClientSettings = makeIpcMethod({
export const getClientSettings = DesktopIpc.makeIpcMethod({
channel: IpcChannels.GET_CLIENT_SETTINGS_CHANNEL,
payload: Schema.Void,
result: Schema.NullOr(ClientSettingsSchema),
Expand All @@ -17,7 +17,7 @@ export const getClientSettings = makeIpcMethod({
}),
});

export const setClientSettings = makeIpcMethod({
export const setClientSettings = DesktopIpc.makeIpcMethod({
channel: IpcChannels.SET_CLIENT_SETTINGS_CHANNEL,
payload: ClientSettingsSchema,
result: Schema.Void,
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src/ipc/methods/connectionCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as Schema from "effect/Schema";

import * as DesktopConnectionCatalogStore from "../../app/DesktopConnectionCatalogStore.ts";
import * as IpcChannels from "../channels.ts";
import { makeIpcMethod } from "../DesktopIpc.ts";
import * as DesktopIpc from "../DesktopIpc.ts";

export const getConnectionCatalog = makeIpcMethod({
export const getConnectionCatalog = DesktopIpc.makeIpcMethod({
channel: IpcChannels.GET_CONNECTION_CATALOG_CHANNEL,
payload: Schema.Void,
result: Schema.NullOr(Schema.String),
Expand All @@ -16,7 +16,7 @@ export const getConnectionCatalog = makeIpcMethod({
}),
});

export const setConnectionCatalog = makeIpcMethod({
export const setConnectionCatalog = DesktopIpc.makeIpcMethod({
channel: IpcChannels.SET_CONNECTION_CATALOG_CHANNEL,
payload: Schema.String,
result: Schema.Boolean,
Expand All @@ -26,7 +26,7 @@ export const setConnectionCatalog = makeIpcMethod({
}),
});

export const clearConnectionCatalog = makeIpcMethod({
export const clearConnectionCatalog = DesktopIpc.makeIpcMethod({
channel: IpcChannels.CLEAR_CONNECTION_CATALOG_CHANNEL,
payload: Schema.Void,
result: Schema.Void,
Expand Down
46 changes: 23 additions & 23 deletions apps/desktop/src/ipc/methods/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { pathToFileURL } from "node:url";
import * as PreviewManager from "../../preview/Manager.ts";
import { PREVIEW_WEBVIEW_PREFERENCES } from "../../preview/WebviewPreferences.ts";
import * as IpcChannels from "../channels.ts";
import { makeIpcMethod } from "../DesktopIpc.ts";
import * as DesktopIpc from "../DesktopIpc.ts";

const broadcast = (channel: string, ...args: ReadonlyArray<unknown>): void => {
for (const window of BrowserWindow.getAllWindows()) {
Expand All @@ -52,7 +52,7 @@ export const installPreviewEventForwarding = Effect.fn(
});
});

export const createTab = makeIpcMethod({
export const createTab = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_CREATE_TAB_CHANNEL,
payload: DesktopPreviewTabInputSchema,
result: Schema.Void,
Expand All @@ -62,7 +62,7 @@ export const createTab = makeIpcMethod({
}),
});

export const closeTab = makeIpcMethod({
export const closeTab = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_CLOSE_TAB_CHANNEL,
payload: DesktopPreviewTabInputSchema,
result: Schema.Void,
Expand All @@ -72,7 +72,7 @@ export const closeTab = makeIpcMethod({
}),
});

export const registerWebview = makeIpcMethod({
export const registerWebview = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_REGISTER_WEBVIEW_CHANNEL,
payload: DesktopPreviewRegisterWebviewInputSchema,
result: Schema.Void,
Expand All @@ -82,7 +82,7 @@ export const registerWebview = makeIpcMethod({
}),
});

export const navigate = makeIpcMethod({
export const navigate = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_NAVIGATE_CHANNEL,
payload: DesktopPreviewNavigateInputSchema,
result: Schema.Void,
Expand All @@ -100,7 +100,7 @@ const tabMethod = (
tabId: string,
) => Effect.Effect<void, PreviewManager.PreviewManagerError>,
) =>
makeIpcMethod({
DesktopIpc.makeIpcMethod({
channel,
payload: DesktopPreviewTabInputSchema,
result: Schema.Void,
Expand Down Expand Up @@ -166,7 +166,7 @@ export const stopRecording = tabMethod(
(manager, tabId) => manager.stopRecording(tabId),
);

export const clearCookies = makeIpcMethod({
export const clearCookies = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_CLEAR_COOKIES_CHANNEL,
payload: Schema.Void,
result: Schema.Void,
Expand All @@ -176,7 +176,7 @@ export const clearCookies = makeIpcMethod({
}),
});

export const clearCache = makeIpcMethod({
export const clearCache = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_CLEAR_CACHE_CHANNEL,
payload: Schema.Void,
result: Schema.Void,
Expand All @@ -186,7 +186,7 @@ export const clearCache = makeIpcMethod({
}),
});

export const getPreviewConfig = makeIpcMethod({
export const getPreviewConfig = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_GET_CONFIG_CHANNEL,
payload: DesktopPreviewConfigInputSchema,
result: DesktopPreviewWebviewConfigSchema,
Expand All @@ -201,7 +201,7 @@ export const getPreviewConfig = makeIpcMethod({
}),
});

export const setAnnotationTheme = makeIpcMethod({
export const setAnnotationTheme = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_SET_ANNOTATION_THEME_CHANNEL,
payload: DesktopPreviewAnnotationThemeInputSchema,
result: Schema.Void,
Expand All @@ -211,7 +211,7 @@ export const setAnnotationTheme = makeIpcMethod({
}),
});

export const pickElement = makeIpcMethod({
export const pickElement = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_PICK_ELEMENT_CHANNEL,
payload: DesktopPreviewTabInputSchema,
result: Schema.NullOr(PreviewAnnotationPayloadSchema),
Expand All @@ -221,7 +221,7 @@ export const pickElement = makeIpcMethod({
}),
});

export const captureScreenshot = makeIpcMethod({
export const captureScreenshot = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_CAPTURE_SCREENSHOT_CHANNEL,
payload: DesktopPreviewTabInputSchema,
result: DesktopPreviewScreenshotArtifactSchema,
Expand All @@ -231,7 +231,7 @@ export const captureScreenshot = makeIpcMethod({
}),
});

export const revealArtifact = makeIpcMethod({
export const revealArtifact = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_REVEAL_ARTIFACT_CHANNEL,
payload: DesktopPreviewArtifactInputSchema,
result: Schema.Void,
Expand All @@ -241,7 +241,7 @@ export const revealArtifact = makeIpcMethod({
}),
});

export const copyArtifactToClipboard = makeIpcMethod({
export const copyArtifactToClipboard = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_COPY_ARTIFACT_CHANNEL,
payload: DesktopPreviewArtifactInputSchema,
result: Schema.Void,
Expand All @@ -251,7 +251,7 @@ export const copyArtifactToClipboard = makeIpcMethod({
}),
});

export const automationStatus = makeIpcMethod({
export const automationStatus = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_STATUS_CHANNEL,
payload: DesktopPreviewTabInputSchema,
result: PreviewAutomationStatus,
Expand All @@ -261,7 +261,7 @@ export const automationStatus = makeIpcMethod({
}),
});

export const automationSnapshot = makeIpcMethod({
export const automationSnapshot = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_SNAPSHOT_CHANNEL,
payload: DesktopPreviewTabInputSchema,
result: PreviewAutomationSnapshot,
Expand All @@ -271,7 +271,7 @@ export const automationSnapshot = makeIpcMethod({
}),
});

export const automationClick = makeIpcMethod({
export const automationClick = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_CLICK_CHANNEL,
payload: DesktopPreviewAutomationClickInputSchema,
result: Schema.Void,
Expand All @@ -281,7 +281,7 @@ export const automationClick = makeIpcMethod({
}),
});

export const automationType = makeIpcMethod({
export const automationType = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_TYPE_CHANNEL,
payload: DesktopPreviewAutomationTypeInputSchema,
result: Schema.Void,
Expand All @@ -291,7 +291,7 @@ export const automationType = makeIpcMethod({
}),
});

export const automationPress = makeIpcMethod({
export const automationPress = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_PRESS_CHANNEL,
payload: DesktopPreviewAutomationPressInputSchema,
result: Schema.Void,
Expand All @@ -301,7 +301,7 @@ export const automationPress = makeIpcMethod({
}),
});

export const automationScroll = makeIpcMethod({
export const automationScroll = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_SCROLL_CHANNEL,
payload: DesktopPreviewAutomationScrollInputSchema,
result: Schema.Void,
Expand All @@ -311,7 +311,7 @@ export const automationScroll = makeIpcMethod({
}),
});

export const automationEvaluate = makeIpcMethod({
export const automationEvaluate = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_EVALUATE_CHANNEL,
payload: DesktopPreviewAutomationEvaluateInputSchema,
result: Schema.Unknown,
Expand All @@ -321,7 +321,7 @@ export const automationEvaluate = makeIpcMethod({
}),
});

export const automationWaitFor = makeIpcMethod({
export const automationWaitFor = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_WAIT_FOR_CHANNEL,
payload: DesktopPreviewAutomationWaitForInputSchema,
result: Schema.Void,
Expand All @@ -331,7 +331,7 @@ export const automationWaitFor = makeIpcMethod({
}),
});

export const saveRecording = makeIpcMethod({
export const saveRecording = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_RECORDING_SAVE_CHANNEL,
payload: DesktopPreviewRecordingSaveInputSchema,
result: DesktopPreviewRecordingArtifactSchema,
Expand Down
10 changes: 5 additions & 5 deletions apps/desktop/src/ipc/methods/serverExposure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import * as Schema from "effect/Schema";
import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
import * as DesktopServerExposure from "../../backend/DesktopServerExposure.ts";
import * as IpcChannels from "../channels.ts";
import { makeIpcMethod } from "../DesktopIpc.ts";
import * as DesktopIpc from "../DesktopIpc.ts";

const SetTailscaleServeEnabledInput = Schema.Struct({
enabled: Schema.Boolean,
port: Schema.optionalKey(Schema.Number),
});

export const getServerExposureState = makeIpcMethod({
export const getServerExposureState = DesktopIpc.makeIpcMethod({
channel: IpcChannels.GET_SERVER_EXPOSURE_STATE_CHANNEL,
payload: Schema.Void,
result: DesktopServerExposureStateSchema,
Expand All @@ -26,7 +26,7 @@ export const getServerExposureState = makeIpcMethod({
}),
});

export const setServerExposureMode = makeIpcMethod({
export const setServerExposureMode = DesktopIpc.makeIpcMethod({
channel: IpcChannels.SET_SERVER_EXPOSURE_MODE_CHANNEL,
payload: DesktopServerExposureModeSchema,
result: DesktopServerExposureStateSchema,
Expand All @@ -41,7 +41,7 @@ export const setServerExposureMode = makeIpcMethod({
}),
});

export const setTailscaleServeEnabled = makeIpcMethod({
export const setTailscaleServeEnabled = DesktopIpc.makeIpcMethod({
channel: IpcChannels.SET_TAILSCALE_SERVE_ENABLED_CHANNEL,
payload: SetTailscaleServeEnabledInput,
result: DesktopServerExposureStateSchema,
Expand All @@ -58,7 +58,7 @@ export const setTailscaleServeEnabled = makeIpcMethod({
}),
});

export const getAdvertisedEndpoints = makeIpcMethod({
export const getAdvertisedEndpoints = DesktopIpc.makeIpcMethod({
channel: IpcChannels.GET_ADVERTISED_ENDPOINTS_CHANNEL,
payload: Schema.Void,
result: Schema.Array(AdvertisedEndpoint),
Expand Down
Loading
Loading