AiDemo/electron/preload.js
2025-10-24 17:31:14 +08:00

36 行
1.7 KiB
JavaScript

const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
// 窗口操作
minimizeWindow: () => ipcRenderer.invoke('window-minimize'),
closeWindow: () => ipcRenderer.invoke('window-close'),
// 登录相关
login: (credentials) => ipcRenderer.invoke('login', credentials),
logout: () => ipcRenderer.invoke('logout'),
// 窗口管理
showSettings: () => ipcRenderer.invoke('show-settings'),
// 文件操作
openFile: (filePath) => ipcRenderer.invoke('open-file', filePath),
// WPS操作
getWPSStatus: () => ipcRenderer.invoke('get-wps-status'),
navigateParagraph: (direction) => ipcRenderer.invoke('navigate-paragraph', direction),
getFullParagraphContent: () => ipcRenderer.invoke('get-full-paragraph-content'),
updateParagraphWithRevisions: (content) => ipcRenderer.invoke('update-paragraph-with-revisions', content),
handleRevision: (action, revisionIndex) => ipcRenderer.invoke('handle-revision', action, revisionIndex),
addComment: (commentText) => ipcRenderer.invoke('add-comment', commentText),
setTrackRevisions: (track) => ipcRenderer.invoke('set-track-revisions', track),
switchDocument: (filePath) => ipcRenderer.invoke('switch-document', filePath),
// 事件监听
onWPSStatusChange: (callback) => ipcRenderer.on('wps-status-changed', callback),
onDocumentsListChange: (callback) => ipcRenderer.on('documents-list-changed', callback),
onActiveDocumentChange: (callback) => ipcRenderer.on('active-document-changed', callback),
onFullParagraphContentChange: (callback) => ipcRenderer.on('full-paragraph-content-changed', callback),
removeAllListeners: (channel) => ipcRenderer.removeAllListeners(channel)
});