Skip to content

refactor(desktop): add typed ipc contract bridge#37588

Open
Hona wants to merge 1 commit into
anomalyco:devfrom
Hona:typed-desktop-ipc
Open

refactor(desktop): add typed ipc contract bridge#37588
Hona wants to merge 1 commit into
anomalyco:devfrom
Hona:typed-desktop-ipc

Conversation

@Hona

@Hona Hona commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

Introduces a end-to-end typed IPC contract bridge (\DesktopIpcContract) for desktop IPC calls between preload and main process.

Details

  • Establishes static type mapping for desktop IPC channels and request/response payloads.
  • Exports typed helpers (\invokeIpcWith, \handleIpcWith) for runtime invocation and main process IPC registration.
  • Prevents channel name typos and parameter mismatches across preload and main.

Copilot AI review requested due to automatic review settings July 18, 2026 02:01
@Hona
Hona requested a review from Brendonovich as a code owner July 18, 2026 02:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an initial typed IPC contract layer for the desktop app to centralize IPC channel names and associate request/response types, with small helper wrappers and basic tests to encourage typed usage across preload and main IPC calls.

Changes:

  • Introduces DesktopIpcContract and typed helper wrappers (invokeIpcWith, handleIpcWith) for IPC calls.
  • Adds a small bun:test suite covering the helper wrappers.
  • Establishes a single place to enumerate IPC channels and their payload types (currently partial).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
packages/desktop/src/preload/ipc-contract.ts Adds the typed IPC channel contract plus typed invoke/handle helper wrappers.
packages/desktop/src/preload/ipc-contract.test.ts Adds bun:test coverage for the typed IPC helper wrappers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +25
import type { ServerReadyData } from "./types"

export interface DesktopIpcContract {
"kill-sidecar": { request: void; response: void }
"await-initialization": { request: void; response: ServerReadyData }
"consume-initial-deep-links": { request: void; response: string[] }
"get-default-server-url": { request: void; response: string | null }
"set-default-server-url": { request: string | null; response: void }
"is-first-launch-onboarding-pending": { request: void; response: boolean }
"finish-first-launch-onboarding": { request: boolean; response: string | null }
"is-old-layout-eligible": { request: void; response: boolean }
"get-display-backend": { request: void; response: string | null }
"set-display-backend": { request: string | null; response: void }
"parse-markdown": { request: string; response: string }
"check-app-exists": { request: string; response: boolean }
"resolve-app-path": { request: string; response: string | null }
"set-background-color": { request: string; response: void }
"export-debug-logs": { request: void; response: string }
"store-get": { request: { name: string; key: string }; response: string | null }
"store-set": { request: { name: string; key: string; value: string }; response: void }
"store-delete": { request: { name: string; key: string }; response: void }
"store-clear": { request: { name: string }; response: void }
"store-keys": { request: { name: string }; response: string[] }
"store-length": { request: { name: string }; response: number }
}
Comment on lines +27 to +43
export type IpcChannel = keyof DesktopIpcContract

export async function invokeIpcWith<K extends IpcChannel>(
ipcRenderer: { invoke(channel: string, ...args: any[]): Promise<any> },
channel: K,
request: DesktopIpcContract[K]["request"],
): Promise<DesktopIpcContract[K]["response"]> {
return ipcRenderer.invoke(channel, request)
}

export function handleIpcWith<K extends IpcChannel>(
ipcMain: { handle(channel: string, listener: (event: any, request: any) => any): void },
channel: K,
handler: (request: DesktopIpcContract[K]["request"]) => Promise<DesktopIpcContract[K]["response"]> | DesktopIpcContract[K]["response"],
) {
ipcMain.handle(channel, (_event, request) => handler(request))
}
Comment on lines +5 to +13
test("invokeIpcWith calls renderer with typed payload and receives response", async () => {
const mockInvoke = vi.fn().mockResolvedValue("https://127.0.0.1:4096")
const mockRenderer = { invoke: mockInvoke } as any

const result = await invokeIpcWith(mockRenderer, "get-default-server-url", undefined)

expect(mockInvoke).toHaveBeenCalledWith("get-default-server-url", undefined)
expect(result).toBe("https://127.0.0.1:4096")
})
Comment on lines +3 to +16
export interface DesktopIpcContract {
"kill-sidecar": { request: void; response: void }
"await-initialization": { request: void; response: ServerReadyData }
"consume-initial-deep-links": { request: void; response: string[] }
"get-default-server-url": { request: void; response: string | null }
"set-default-server-url": { request: string | null; response: void }
"is-first-launch-onboarding-pending": { request: void; response: boolean }
"finish-first-launch-onboarding": { request: boolean; response: string | null }
"is-old-layout-eligible": { request: void; response: boolean }
"get-display-backend": { request: void; response: string | null }
"set-display-backend": { request: string | null; response: void }
"parse-markdown": { request: string; response: string }
"check-app-exists": { request: string; response: boolean }
"resolve-app-path": { request: string; response: string | null }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants