preload.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const { contextBridge, ipcRenderer } = require('electron');
  2. contextBridge.exposeInMainWorld('electronAPI', {
  3. // 窗口操作
  4. minimizeWindow: () => ipcRenderer.invoke('window-minimize'),
  5. closeWindow: () => ipcRenderer.invoke('window-close'),
  6. // 登录相关
  7. login: (credentials) => ipcRenderer.invoke('login', credentials),
  8. logout: () => ipcRenderer.invoke('logout'),
  9. // 窗口管理
  10. showSettings: () => ipcRenderer.invoke('show-settings'),
  11. // 文件操作
  12. openFile: (filePath) => ipcRenderer.invoke('open-file', filePath),
  13. // WPS操作
  14. getWPSStatus: () => ipcRenderer.invoke('get-wps-status'),
  15. navigateParagraph: (direction) => ipcRenderer.invoke('navigate-paragraph', direction),
  16. getFullParagraphContent: () => ipcRenderer.invoke('get-full-paragraph-content'),
  17. updateParagraphWithRevisions: (content) => ipcRenderer.invoke('update-paragraph-with-revisions', content),
  18. handleRevision: (action, revisionIndex) => ipcRenderer.invoke('handle-revision', action, revisionIndex),
  19. addComment: (commentText) => ipcRenderer.invoke('add-comment', commentText),
  20. setTrackRevisions: (track) => ipcRenderer.invoke('set-track-revisions', track),
  21. switchDocument: (filePath) => ipcRenderer.invoke('switch-document', filePath),
  22. // 事件监听
  23. onWPSStatusChange: (callback) => ipcRenderer.on('wps-status-changed', callback),
  24. onDocumentsListChange: (callback) => ipcRenderer.on('documents-list-changed', callback),
  25. onActiveDocumentChange: (callback) => ipcRenderer.on('active-document-changed', callback),
  26. onFullParagraphContentChange: (callback) => ipcRenderer.on('full-paragraph-content-changed', callback),
  27. removeAllListeners: (channel) => ipcRenderer.removeAllListeners(channel)
  28. });