- Reorganize project structure with new electron and shared directories - Add comprehensive i18n support with Chinese, English, and Japanese locales - Update build configurations and TypeScript paths for new structure - Add various UI components including chat interface and task management - Include Windows release binaries and localization files - Update dependencies and fix import paths throughout the codebase
66 lines
2.6 KiB
TypeScript
66 lines
2.6 KiB
TypeScript
import { contextBridge, ipcRenderer } from 'electron'
|
|
import { IPC_EVENTS } from '@lib/constants';
|
|
|
|
const api: WindowApi = {
|
|
versions: process.versions,
|
|
|
|
external: {
|
|
open: (url: string) => ipcRenderer.invoke('external-open', url)
|
|
},
|
|
|
|
closeWindow: () => ipcRenderer.send(IPC_EVENTS.WINDOW_CLOSE),
|
|
minimizeWindow: () => ipcRenderer.send(IPC_EVENTS.WINDOW_MINIMIZE),
|
|
maximizeWindow: () => ipcRenderer.send(IPC_EVENTS.WINDOW_MAXIMIZE),
|
|
onWindowMaximized: (callback: (isMaximized: boolean) => void) => ipcRenderer.on(IPC_EVENTS.WINDOW_MAXIMIZE + 'back', (_, isMaximized) => callback(isMaximized)),
|
|
isWindowMaximized: () => ipcRenderer.invoke(IPC_EVENTS.IS_WINDOW_MAXIMIZED),
|
|
viewIsReady: () => ipcRenderer.send(IPC_EVENTS.RENDERER_IS_READY),
|
|
|
|
app: {
|
|
setFrameless: (route?: string) => ipcRenderer.invoke(IPC_EVENTS.APP_SET_FRAMELESS, route),
|
|
loadPage: (page: string) => ipcRenderer.invoke(IPC_EVENTS.APP_LOAD_PAGE, page)
|
|
},
|
|
|
|
// 通过 IPC 调用主进程
|
|
readFile: (filePath: string) => ipcRenderer.invoke(IPC_EVENTS.READ_FILE, filePath),
|
|
|
|
// 同步调用
|
|
invoke: (channel: IPC_EVENTS, ...args: any[]) => ipcRenderer.sendSync(IPC_EVENTS.INVOKE, channel, ...args),
|
|
|
|
// 异步调用
|
|
invokeAsync: (channel: IPC_EVENTS, ...args: any[]) => {
|
|
try {
|
|
ipcRenderer.invoke(IPC_EVENTS.INVOKE_ASYNC, channel, ...args)
|
|
} catch (error) {
|
|
throw error
|
|
}
|
|
},
|
|
|
|
// 监听主进程消息
|
|
on: (event: IPC_EVENTS, callback: (...args: any[]) => void) => {
|
|
const subscription = (_event: any, ...args: any[]) => callback(...args)
|
|
ipcRenderer.on(event, subscription)
|
|
return () => ipcRenderer.removeListener(event, subscription)
|
|
},
|
|
|
|
// 发送消息到主进程
|
|
send: (channel: IPC_EVENTS, ...args: any[]) => ipcRenderer.send(channel, ...args),
|
|
|
|
// 获取窗口ID
|
|
getCurrentWindowId: () => ipcRenderer.sendSync(IPC_EVENTS.GET_WINDOW_ID),
|
|
|
|
// 发送日志
|
|
logger: {
|
|
debug: (message: string, ...meta: any[]) => ipcRenderer.send(IPC_EVENTS.LOG_DEBUG, message, ...meta),
|
|
info: (message: string, ...meta: any[]) => ipcRenderer.send(IPC_EVENTS.LOG_INFO, message, ...meta),
|
|
warn: (message: string, ...meta: any[]) => ipcRenderer.send(IPC_EVENTS.LOG_WARN, message, ...meta),
|
|
error: (message: string, ...meta: any[]) => ipcRenderer.send(IPC_EVENTS.LOG_ERROR, message, ...meta),
|
|
},
|
|
|
|
// 执行脚本
|
|
executeScript: (params: any) => ipcRenderer.invoke(IPC_EVENTS.EXECUTE_SCRIPT, params),
|
|
|
|
// 打开渠道
|
|
openChannel: (channels: any) => ipcRenderer.invoke(IPC_EVENTS.OPEN_CHANNEL, channels),
|
|
}
|
|
|
|
contextBridge.exposeInMainWorld('api', api) |