From d7c5c2b9a45c45e79a817651f3c30bf8984bce02 Mon Sep 17 00:00:00 2001 From: icarus Date: Thu, 25 Dec 2025 20:56:35 +0800 Subject: [PATCH] feat(preload): add windows-only OVMS API and improve type safety Extract OVMS API methods into a separate windowsOnlyApi object for better organization Add explicit return type for getDeviceType method --- src/preload/index.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/preload/index.ts b/src/preload/index.ts index 424253f8e3..b5566d3d0e 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -75,8 +75,22 @@ export function tracedInvoke(channel: string, spanContext: SpanContext | undefin return ipcRenderer.invoke(channel, ...args) } +const windowsOnlyApi = { + ovms: { + addModel: (modelName: string, modelId: string, modelSource: string, task: string) => + ipcRenderer.invoke(IpcChannel.Ovms_AddModel, modelName, modelId, modelSource, task), + stopAddModel: () => ipcRenderer.invoke(IpcChannel.Ovms_StopAddModel), + getModels: () => ipcRenderer.invoke(IpcChannel.Ovms_GetModels), + isRunning: () => ipcRenderer.invoke(IpcChannel.Ovms_IsRunning), + getStatus: () => ipcRenderer.invoke(IpcChannel.Ovms_GetStatus), + runOvms: () => ipcRenderer.invoke(IpcChannel.Ovms_RunOVMS), + stopOvms: () => ipcRenderer.invoke(IpcChannel.Ovms_StopOVMS) + } +} as const + // Custom APIs for renderer const api = { + ...windowsOnlyApi, getAppInfo: () => ipcRenderer.invoke(IpcChannel.App_Info), getDiskInfo: (directoryPath: string): Promise<{ free: number; size: number } | null> => ipcRenderer.invoke(IpcChannel.App_GetDiskInfo, directoryPath), @@ -129,7 +143,7 @@ const api = { send: (notification: Notification) => ipcRenderer.invoke(IpcChannel.Notification_Send, notification) }, system: { - getDeviceType: () => ipcRenderer.invoke(IpcChannel.System_GetDeviceType), + getDeviceType: (): Promise<'mac' | 'windows' | 'linux'> => ipcRenderer.invoke(IpcChannel.System_GetDeviceType), getHostname: () => ipcRenderer.invoke(IpcChannel.System_GetHostname), getCpuName: () => ipcRenderer.invoke(IpcChannel.System_GetCpuName), checkGitBash: (): Promise => ipcRenderer.invoke(IpcChannel.System_CheckGitBash), @@ -330,7 +344,6 @@ const api = { selectionMenu: { action: (action: string) => ipcRenderer.invoke('selection-menu:action', action) }, - vertexAI: { getAuthHeaders: (params: { projectId: string; serviceAccount?: { privateKey: string; clientEmail: string } }) => ipcRenderer.invoke(IpcChannel.VertexAI_GetAuthHeaders, params), @@ -339,16 +352,6 @@ const api = { clearAuthCache: (projectId: string, clientEmail?: string) => ipcRenderer.invoke(IpcChannel.VertexAI_ClearAuthCache, projectId, clientEmail) }, - ovms: { - addModel: (modelName: string, modelId: string, modelSource: string, task: string) => - ipcRenderer.invoke(IpcChannel.Ovms_AddModel, modelName, modelId, modelSource, task), - stopAddModel: () => ipcRenderer.invoke(IpcChannel.Ovms_StopAddModel), - getModels: () => ipcRenderer.invoke(IpcChannel.Ovms_GetModels), - isRunning: () => ipcRenderer.invoke(IpcChannel.Ovms_IsRunning), - getStatus: () => ipcRenderer.invoke(IpcChannel.Ovms_GetStatus), - runOvms: () => ipcRenderer.invoke(IpcChannel.Ovms_RunOVMS), - stopOvms: () => ipcRenderer.invoke(IpcChannel.Ovms_StopOVMS) - }, config: { set: (key: string, value: any, isNotify: boolean = false) => ipcRenderer.invoke(IpcChannel.Config_Set, key, value, isNotify),