-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
37 lines (32 loc) · 2.35 KB
/
preload.js
File metadata and controls
37 lines (32 loc) · 2.35 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, webUtils } = require('electron');
contextBridge.exposeInMainWorld('api', {
// ── File Operations ─────────────────────────────────────────────────────
openFile: () => ipcRenderer.invoke('file:open-dialog'),
openFilePath: (filePath) => ipcRenderer.invoke('file:open-path', filePath),
saveFile: (content, filePath) => ipcRenderer.invoke('file:save', { content, filePath }),
saveFileAs: (content) => ipcRenderer.invoke('file:save-as', { content }),
setDirty: (dirty) => ipcRenderer.send('file:set-dirty', dirty),
setClean: () => ipcRenderer.send('file:set-clean'),
// ── Export ──────────────────────────────────────────────────────────────
exportPDF: (html, css) => ipcRenderer.invoke('export:pdf', { html, css }),
exportHTML: (html, css) => ipcRenderer.invoke('export:html', { html, css }),
// ── Settings ────────────────────────────────────────────────────────────
getSettings: () => ipcRenderer.invoke('settings:get'),
setSettings: (settings) => ipcRenderer.invoke('settings:set', settings),
// ── Image Handling ──────────────────────────────────────────────────────
processImage: (filePath, mode, docPath) =>
ipcRenderer.invoke('image:process', { filePath, mode, docPath }),
pickImage: () => ipcRenderer.invoke('image:pick'),
askImageHandling: () => ipcRenderer.invoke('dialog:image-handling'),
getFilePathForFile: (file) => webUtils.getPathForFile(file),
// ── Event Listeners ─────────────────────────────────────────────────────
onMenuAction: (callback) => {
ipcRenderer.on('menu:action', (_event, action) => callback(action));
},
onFileOpened: (callback) => {
ipcRenderer.on('file:opened', (_event, data) => callback(data));
},
onNewFile: (callback) => {
ipcRenderer.on('file:new', () => callback());
}
});