Repository navigation
Expand file tree
/
Copy pathpreload.js
More file actions
24 lines (23 loc) · 1.51 KB
/
Copy pathpreload.js
File metadata and controls
24 lines (23 loc) · 1.51 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
const {contextBridge, ipcRenderer} = require('electron');
// The renderer (a plain web app, also served over http:// for the browser
// build) has no Node/Electron access by default - contextIsolation keeps it
// that way even here, exposing only this narrow, purpose-built surface
// rather than the raw ipcRenderer/require. window.electronAPI's mere
// presence is what the renderer uses (see App.vue/Configuration.vue's own
// isElectron checks) to tell "running inside the desktop app" apart from
// "running in a browser", where none of this exists at all.
contextBridge.exposeInMainWorld('electronAPI', {
// The system the app runs on ('win32', 'darwin' or 'linux'; 'x64' or 'arm64'): the update notice links the download made for it
// (see src/utils/update-check.js).
platform: process.platform,
arch: process.arch,
pickStellaPath: () => ipcRenderer.invoke('stella:pick-path'),
// romBytes: a Uint8Array (App.vue's compiledRomBytes.output - see
// hooks/rom-status.js) - structured-cloned across the IPC boundary
// automatically, no manual serialization needed.
launchStella: (stellaPath, romBytes) => ipcRenderer.invoke('stella:launch', {stellaPath, romBytes}),
saveProjectAs: (content, suggestedName) => ipcRenderer.invoke('project:save-as', {content, suggestedName}),
saveProject: (filePath, content) => ipcRenderer.invoke('project:save', {filePath, content}),
openProject: () => ipcRenderer.invoke('project:open'),
projectPathExists: (filePath) => ipcRenderer.invoke('project:path-exists', filePath),
});