import { contextBridge, ipcRenderer } from 'electron'
/**
* Preload Script - 安全的IPC通信桥接
* 遵循Electron安全最佳实践
*/
// 定义API接口
interface ElectronAPI {
getGroupedResources: () => Promise<any>
searchResources: (query: string) => Promise<any>
getStatistics: () => Promise<any>
activateRole: (roleId: string) => Promise<any>
executeTool: (toolId: string, parameters?: any) => Promise<any>
invoke: (channel: string, ...args: any[]) => Promise<any>
}
contextBridge.exposeInMainWorld('electronAPI', {
getGroupedResources: () => ipcRenderer.invoke('resources:getGrouped'),
searchResources: (query: string) => ipcRenderer.invoke('resources:search', query),
getStatistics: () => ipcRenderer.invoke('resources:getStatistics'),
activateRole: (roleId: string) => ipcRenderer.invoke('resources:activateRole', roleId),
executeTool: (toolId: string, parameters?: any) => ipcRenderer.invoke('resources:executeTool', toolId, parameters),
invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args)
} as ElectronAPI)
// 为window对象添加类型定义
declare global {
interface Window {
electronAPI: ElectronAPI
}
}