Files
deepseek-harness-backup/apps/desktop/src/preload-app.ts
T

25 lines
1.3 KiB
TypeScript

/** Startup controls for shell documents; application documents receive only the carrier marker. */
import { contextBridge, ipcRenderer } from 'electron'
import { DESKTOP_IPC, type DshDesktopStartupApi } from './ipc.ts'
import type { DesktopBackendState } from './backend-controller.ts'
const startup: DshDesktopStartupApi = {
protocolVersion: 1,
locale: () => ipcRenderer.invoke(DESKTOP_IPC.localeGet) as ReturnType<DshDesktopStartupApi['locale']>,
backend: {
status: () => ipcRenderer.invoke(DESKTOP_IPC.backendStatus) as ReturnType<DshDesktopStartupApi['backend']['status']>,
subscribe(listener) {
const handle = (_event: Electron.IpcRendererEvent, state: DesktopBackendState): void => { listener(state) }
ipcRenderer.on(DESKTOP_IPC.backendState, handle)
return () => { ipcRenderer.off(DESKTOP_IPC.backendState, handle) }
},
},
disablePlugins: () => ipcRenderer.invoke(DESKTOP_IPC.pluginsDisableAll) as Promise<void>,
restart: () => ipcRenderer.invoke(DESKTOP_IPC.applicationRestart) as Promise<void>,
resetConfiguration: () => ipcRenderer.invoke(DESKTOP_IPC.configurationReset) as Promise<void>,
}
contextBridge.exposeInMainWorld('dshDesktop', location.protocol === 'dsh-app:' && location.hostname === 'shell'
? startup : { protocolVersion: 1 })