2026-04-19 14:18:20 +08:00
|
|
|
import { contextBridge, ipcRenderer } from "electron/renderer";
|
2026-04-20 17:16:15 +08:00
|
|
|
import type { IpcRendererEvent } from "electron";
|
2026-04-20 09:52:48 +08:00
|
|
|
import type {
|
|
|
|
|
CreatePublishJobResponse,
|
|
|
|
|
DesktopAccountInfo,
|
|
|
|
|
DesktopPublishTaskListResponse,
|
|
|
|
|
DesktopRuntimeSessionSyncRequest,
|
|
|
|
|
ListDesktopPublishTasksParams,
|
|
|
|
|
} from "@geo/shared-types";
|
2026-04-19 14:18:20 +08:00
|
|
|
import type { DesktopRuntimeSnapshot } from "../renderer/types";
|
|
|
|
|
|
2026-04-20 11:59:35 +08:00
|
|
|
interface DesktopDeviceInfo {
|
|
|
|
|
device_name: string;
|
|
|
|
|
os: string;
|
|
|
|
|
cpu_arch: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 14:18:20 +08:00
|
|
|
const desktopBridge = {
|
|
|
|
|
app: {
|
|
|
|
|
ping: () => ipcRenderer.invoke("desktop:ping") as Promise<string>,
|
2026-04-20 11:59:35 +08:00
|
|
|
deviceInfo: () => ipcRenderer.invoke("desktop:device-info") as Promise<DesktopDeviceInfo>,
|
2026-04-19 14:18:20 +08:00
|
|
|
runtimeSnapshot: () =>
|
|
|
|
|
ipcRenderer.invoke("desktop:runtime-snapshot") as Promise<DesktopRuntimeSnapshot>,
|
|
|
|
|
bindPublishAccount: (platformId: string) =>
|
|
|
|
|
ipcRenderer.invoke("desktop:bind-publish-account", platformId) as Promise<DesktopAccountInfo>,
|
2026-04-20 09:52:48 +08:00
|
|
|
refreshRuntimeAccounts: () =>
|
|
|
|
|
ipcRenderer.invoke("desktop:refresh-runtime-accounts") as Promise<null>,
|
2026-04-19 14:18:20 +08:00
|
|
|
openPublishAccountConsole: (account: {
|
|
|
|
|
id: string;
|
|
|
|
|
platform: string;
|
|
|
|
|
platformUid: string;
|
|
|
|
|
displayName: string;
|
|
|
|
|
}) =>
|
|
|
|
|
ipcRenderer.invoke("desktop:open-publish-account-console", account) as Promise<null>,
|
2026-04-20 09:52:48 +08:00
|
|
|
unbindPublishAccount: (accountId: string, syncVersion: number) =>
|
|
|
|
|
ipcRenderer.invoke("desktop:unbind-publish-account", accountId, syncVersion) as Promise<null>,
|
|
|
|
|
listPublishTasks: (params?: ListDesktopPublishTasksParams) =>
|
|
|
|
|
ipcRenderer.invoke("desktop:list-publish-tasks", params) as Promise<DesktopPublishTaskListResponse>,
|
|
|
|
|
retryPublishTask: (taskId: string) =>
|
|
|
|
|
ipcRenderer.invoke("desktop:retry-publish-task", taskId) as Promise<CreatePublishJobResponse>,
|
2026-04-19 14:18:20 +08:00
|
|
|
syncRuntimeSession: (session: DesktopRuntimeSessionSyncRequest | null) =>
|
|
|
|
|
ipcRenderer.invoke("desktop:runtime-session-sync", session) as Promise<null>,
|
2026-04-20 09:52:48 +08:00
|
|
|
releaseRuntimeSession: (revoke?: boolean) =>
|
|
|
|
|
ipcRenderer.invoke("desktop:runtime-session-release", revoke) as Promise<null>,
|
2026-04-20 17:16:15 +08:00
|
|
|
onRuntimeInvalidated: (
|
|
|
|
|
listener: (event: { reason: "account-health"; at: number }) => void,
|
|
|
|
|
) => {
|
|
|
|
|
const wrapped = (_event: IpcRendererEvent, payload: { reason: "account-health"; at: number }) => {
|
|
|
|
|
listener(payload);
|
|
|
|
|
};
|
|
|
|
|
ipcRenderer.on("desktop:runtime-invalidated", wrapped);
|
|
|
|
|
return () => {
|
|
|
|
|
ipcRenderer.off("desktop:runtime-invalidated", wrapped);
|
|
|
|
|
};
|
|
|
|
|
},
|
2026-04-19 14:18:20 +08:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld("desktopBridge", desktopBridge);
|