Consolidate Electron IPC POC protocol in shared contracts

- Move the POC RPC group and methods to `@t3tools/contracts`
- Inline the renderer client setup in the IPC test and remove obsolete example files
- Update the main window placeholder copy
This commit is contained in:
Julius Marminge committed 2026-05-06 11:47:45 -07:00
1 parent d16cdd00d8
commit e11dba8fe4
6 files changed
+44 -102

No files matched your search

+42 -7
View File
@@ -1,12 +1,17 @@
import { Effect, Stream } from "effect";
import { RpcClient } from "effect/unstable/rpc";
import { describe, expect, it } from "vitest";
import {
loadDesktopIpcPocSnapshot,
makeDesktopIpcPocBrowserClient,
} from "./effectRpcIpcPoc/example/browser-client.ts";
DESKTOP_IPC_POC_METHODS,
DesktopIpcPocRpcGroup,
} from "@t3tools/contracts/effectElectronIpcPoc";
import { runDesktopIpcPocRpcServer } from "./effectRpcIpcPoc/example/rpc-server.ts";
import { DESKTOP_IPC_POC_METHODS } from "./effectRpcIpcPoc/example/protocol.ts";
import {
getEffectElectronIpcRendererBridge,
makeEffectElectronIpcRendererPort,
makeEffectElectronIpcRendererProtocol,
} from "effect-electron-ipc/client";
import { EFFECT_ELECTRON_IPC_RENDERER_BRIDGE_KEY } from "effect-electron-ipc/ipc";
import type {
EffectElectronIpcMainFrame,
@@ -15,6 +20,8 @@ import type {
EffectElectronIpcRendererFrame,
} from "effect-electron-ipc/ipc";
const makeDesktopIpcPocClient = RpcClient.make(DesktopIpcPocRpcGroup);
describe("effect RPC over Electron IPC proof of concept", () => {
it("runs the end-to-end consumer example over the Electron IPC transport", async () => {
const ipc = new InMemoryEffectElectronIpc();
@@ -31,7 +38,25 @@ describe("effect RPC over Electron IPC proof of concept", () => {
return yield* withEffectElectronIpcRendererBridge(
ipc.rendererPort,
loadDesktopIpcPocSnapshot,
Effect.gen(function* () {
const client = yield* makeTestDesktopIpcPocClient;
const runtimeInfo = yield* client[DESKTOP_IPC_POC_METHODS.getRuntimeInfo]({});
const echo = yield* client[DESKTOP_IPC_POC_METHODS.echo]({
text: "hello from the renderer",
});
const ticks = yield* client[DESKTOP_IPC_POC_METHODS.subscribeTicks]({
take: 3,
}).pipe(
Stream.runCollect,
Effect.map((chunk) => Array.from(chunk)),
);
return {
runtimeInfo,
echo,
ticks,
};
}),
);
}),
),
@@ -70,7 +95,7 @@ describe("effect RPC over Electron IPC proof of concept", () => {
return yield* withEffectElectronIpcRendererBridge(
ipc.rendererPort,
Effect.gen(function* () {
const client = yield* makeDesktopIpcPocBrowserClient;
const client = yield* makeTestDesktopIpcPocClient;
return yield* client[DESKTOP_IPC_POC_METHODS.subscribeTicks]({ take: 3 }).pipe(
Stream.runCollect,
@@ -104,7 +129,7 @@ describe("effect RPC over Electron IPC proof of concept", () => {
return yield* withEffectElectronIpcRendererBridge(
ipc.rendererPort,
Effect.gen(function* () {
const client = yield* makeDesktopIpcPocBrowserClient;
const client = yield* makeTestDesktopIpcPocClient;
return yield* client[DESKTOP_IPC_POC_METHODS.echo]({ text: "" }).pipe(Effect.flip);
}),
@@ -208,3 +233,13 @@ const withEffectElectronIpcRendererBridge = <A, E, R>(
() => effect,
(restore) => Effect.sync(restore),
);
const makeTestDesktopIpcPocClient = Effect.gen(function* () {
const bridge = yield* Effect.sync(() => getEffectElectronIpcRendererBridge());
const rendererPort = makeEffectElectronIpcRendererPort(bridge);
const rendererProtocol = yield* makeEffectElectronIpcRendererProtocol(rendererPort);
return yield* makeDesktopIpcPocClient.pipe(
Effect.provideService(RpcClient.Protocol, rendererProtocol),
);
});
@@ -1,62 +0,0 @@
import { Effect, Scope, Stream } from "effect";
import { RpcClient } from "effect/unstable/rpc";
import type { RpcClientError } from "effect/unstable/rpc/RpcClientError";
import {
getEffectElectronIpcRendererBridge,
makeEffectElectronIpcRendererPort,
makeEffectElectronIpcRendererProtocol,
} from "effect-electron-ipc/client";
import {
DESKTOP_IPC_POC_METHODS,
makeDesktopIpcPocClient,
type DesktopIpcPocClient,
type DesktopIpcPocEchoError,
type DesktopIpcPocEchoResult,
type DesktopIpcPocRuntimeInfo,
type DesktopIpcPocTick,
} from "./protocol.ts";
export interface DesktopIpcPocSnapshot {
readonly runtimeInfo: DesktopIpcPocRuntimeInfo;
readonly echo: DesktopIpcPocEchoResult;
readonly ticks: ReadonlyArray<DesktopIpcPocTick>;
}
export const makeDesktopIpcPocBrowserClient: Effect.Effect<
DesktopIpcPocClient,
never,
Scope.Scope
> = Effect.gen(function* () {
const bridge = yield* Effect.sync(() => getEffectElectronIpcRendererBridge());
const rendererPort = makeEffectElectronIpcRendererPort(bridge);
const rendererProtocol = yield* makeEffectElectronIpcRendererProtocol(rendererPort);
return yield* makeDesktopIpcPocClient.pipe(
Effect.provideService(RpcClient.Protocol, rendererProtocol),
);
});
export const loadDesktopIpcPocSnapshot: Effect.Effect<
DesktopIpcPocSnapshot,
DesktopIpcPocEchoError | RpcClientError,
Scope.Scope
> = Effect.gen(function* () {
const client = yield* makeDesktopIpcPocBrowserClient;
const runtimeInfo = yield* client[DESKTOP_IPC_POC_METHODS.getRuntimeInfo]({});
const echo = yield* client[DESKTOP_IPC_POC_METHODS.echo]({
text: "hello from the renderer",
});
const ticks = yield* client[DESKTOP_IPC_POC_METHODS.subscribeTicks]({
take: 3,
}).pipe(
Stream.runCollect,
Effect.map((chunk) => Array.from(chunk)),
);
return {
runtimeInfo,
echo,
ticks,
};
});
@@ -29,7 +29,7 @@ export const makeMainWindow = Effect.sync(() => {
<title>Effect RPC Electron IPC POC</title>
</head>
<body>
<main id="root">Renderer bundle would call example/renderer.ts here.</main>
<main id="root">Renderer bundle would mount apps/web/src/examples/effectElectronIpcPoc.tsx here.</main>
</body>
</html>
`)}`,
@@ -1,12 +0,0 @@
import { DesktopIpcPocRpcGroup } from "@t3tools/contracts/effectElectronIpcPoc";
import { Effect } from "effect";
import { RpcClient } from "effect/unstable/rpc";
export * from "@t3tools/contracts/effectElectronIpcPoc";
export const makeDesktopIpcPocClient = RpcClient.make(DesktopIpcPocRpcGroup);
type DesktopIpcPocClientFactory = typeof makeDesktopIpcPocClient;
export type DesktopIpcPocClient =
DesktopIpcPocClientFactory extends Effect.Effect<infer Client, infer _Error, infer _Services>
? Client
: never;
@@ -1,19 +0,0 @@
import { Effect } from "effect";
import { loadDesktopIpcPocSnapshot } from "./browser-client.ts";
const program = Effect.gen(function* () {
const snapshot = yield* loadDesktopIpcPocSnapshot;
const root = document.querySelector("#root");
if (root) {
root.textContent = JSON.stringify(snapshot, null, 2);
}
}).pipe(Effect.scoped);
Effect.runPromise(program).catch((error: unknown) => {
const root = document.querySelector("#root");
if (root) {
root.textContent = error instanceof Error ? error.message : String(error);
}
});
@@ -7,7 +7,7 @@ import {
DESKTOP_IPC_POC_METHODS,
DesktopIpcPocEchoError,
DesktopIpcPocRpcGroup,
} from "./protocol.ts";
} from "@t3tools/contracts/effectElectronIpcPoc";
export interface DesktopIpcPocMainOptions {
readonly port: EffectElectronIpcMainPort;