-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
37 lines (29 loc) · 1.06 KB
/
Copy pathpreload.js
File metadata and controls
37 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('editorAPI', {
// 打开 HTML 文件
openFile: () => ipcRenderer.invoke('dialog:openFile'),
// 保存(覆盖原文件)
saveFile: (filePath, content) =>
ipcRenderer.invoke('dialog:saveFile', { filePath, content }),
// 另存为
saveAsFile: (content) =>
ipcRenderer.invoke('dialog:saveAsFile', { content }),
// 拖放打开文件
readFile: (filePath) => ipcRenderer.invoke('dialog:readFile', filePath),
// 接收主进程的拖放文件路径
onFileDropped: (callback) => {
ipcRenderer.on('file-dropped', (_event, filePath) => callback(filePath));
},
// 关闭窗口前询问未保存修改
onBeforeClose: (callback) => {
ipcRenderer.on('app:before-close', () => callback());
},
// 确认关闭窗口
confirmClose: (action) => {
ipcRenderer.send('app:confirm-close', action);
},
// 主题切换时同步 titleBarOverlay 配色
setThemeOverlay: (isLight) => {
ipcRenderer.send('app:set-theme-overlay', isLight);
},
});