electronAPI.ts 828 B

123456789101112131415161718
  1. import { contextBridge, ipcRenderer } from "electron";
  2. contextBridge.exposeInMainWorld("electronAPI", {
  3. max: (...res: any) => ipcRenderer.invoke("max", ...res),
  4. min: (...res: any) => ipcRenderer.invoke("min", ...res),
  5. middle: (...res: any) => ipcRenderer.invoke("middle", ...res),
  6. close: (...res: any) => ipcRenderer.invoke("close", ...res),
  7. send: (channel, data) => ipcRenderer.send(channel, data),
  8. on: (channel, callback) =>
  9. ipcRenderer.on(channel, (event, ...args) => callback(...args)),
  10. getWindowWidth: () => ipcRenderer.invoke("get-window-info"),
  11. // 添加新的监听方法
  12. onNewNotification: (callback) =>
  13. ipcRenderer.on("new-notification", (event, data) => callback(data)),
  14. removeNotificationListener: () =>
  15. ipcRenderer.removeAllListeners("new-notification"),
  16. // ...sqlitePreload,
  17. });