import { contextBridge, ipcRenderer } from 'electron' const electronAPI = { sendMessage: (message: string) => ipcRenderer.send('message', message), getJarVersion: () => ipcRenderer.invoke('get-jar-version'), downloadUpdate: (downloadUrl: string) => ipcRenderer.invoke('download-update', downloadUrl), getDownloadProgress: () => ipcRenderer.invoke('get-download-progress'), installUpdate: () => ipcRenderer.invoke('install-update'), cancelDownload: () => ipcRenderer.invoke('cancel-download'), getUpdateStatus: () => ipcRenderer.invoke('get-update-status'), checkPendingUpdate: () => ipcRenderer.invoke('check-pending-update'), clearUpdateFiles: () => ipcRenderer.invoke('clear-update-files'), // 添加文件保存对话框 API showSaveDialog: (options: any) => ipcRenderer.invoke('show-save-dialog', options), // 添加文件夹选择对话框 API showOpenDialog: (options: any) => ipcRenderer.invoke('show-open-dialog', options), // 添加文件写入 API writeFile: (filePath: string, data: Uint8Array) => ipcRenderer.invoke('write-file', filePath, data), // 添加日志相关 API getLogDates: () => ipcRenderer.invoke('get-log-dates'), readLogFile: (logDate: string) => ipcRenderer.invoke('read-log-file', logDate), // 关闭行为配置 API getCloseAction: () => ipcRenderer.invoke('get-close-action'), setCloseAction: (action: 'quit' | 'minimize' | 'tray') => ipcRenderer.invoke('set-close-action', action), // 缓存管理 API clearCache: () => ipcRenderer.invoke('clear-cache'), // 启动配置 API getLaunchConfig: () => ipcRenderer.invoke('get-launch-config'), setLaunchConfig: (config: { autoLaunch: boolean; launchMinimized: boolean }) => ipcRenderer.invoke('set-launch-config', config), // 刷新页面 API reload: () => ipcRenderer.invoke('reload'), // 窗口控制 API windowMinimize: () => ipcRenderer.invoke('window-minimize'), windowMaximize: () => ipcRenderer.invoke('window-maximize'), windowClose: () => ipcRenderer.invoke('window-close'), windowIsMaximized: () => ipcRenderer.invoke('window-is-maximized'), // 开屏图片相关 API saveSplashConfig: (username: string, imageUrl: string) => ipcRenderer.invoke('save-splash-config', username, imageUrl), getSplashConfig: () => ipcRenderer.invoke('get-splash-config'), // 品牌logo相关 API saveBrandLogoConfig: (username: string, logoUrl: string) => ipcRenderer.invoke('save-brand-logo-config', username, logoUrl), loadConfig: () => ipcRenderer.invoke('load-config'), clearUserConfig: () => ipcRenderer.invoke('clear-user-config'), onDownloadProgress: (callback: (progress: any) => void) => { ipcRenderer.removeAllListeners('download-progress') ipcRenderer.on('download-progress', (event, progress) => callback(progress)) }, removeDownloadProgressListener: () => { ipcRenderer.removeAllListeners('download-progress') } } contextBridge.exposeInMainWorld('electronAPI', electronAPI) export type ElectronApi = typeof electronAPI