-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
38 lines (27 loc) · 1.26 KB
/
Copy pathpreload.js
File metadata and controls
38 lines (27 loc) · 1.26 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
38
/**
* sc-js-electron — Preload Script
*
* Exposes a safe IPC API to the renderer via contextBridge.
* The renderer accesses everything through window.scjs.
*/
'use strict';
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('scjs', {
// ── Discovery ──
startDiscovery: (config) => ipcRenderer.invoke('discovery:start', config),
stopDiscovery: () => ipcRenderer.invoke('discovery:stop'),
onDiscoveryEvent: (callback) => {
const handler = (_event, payload) => callback(payload);
ipcRenderer.on('discovery:event', handler);
// Return cleanup function
return () => ipcRenderer.removeListener('discovery:event', handler);
},
// ── Topology ──
loadMapJson: (filePath) => ipcRenderer.invoke('topology:load-map', filePath),
getOutputMap: (outputDir) => ipcRenderer.invoke('topology:get-output-map', outputDir),
// ── Dialogs ──
openFile: (options) => ipcRenderer.invoke('dialog:open-file', options || {}),
selectDirectory: (options) => ipcRenderer.invoke('dialog:select-directory', options || {}),
saveFile: (options) => ipcRenderer.invoke('dialog:save-file', options || {}),
writeFile: (filePath, content) => ipcRenderer.invoke('fs:write-file', filePath, content),
});