-
Notifications
You must be signed in to change notification settings - Fork 3
/
preload.js
29 lines (26 loc) · 1.05 KB
/
preload.js
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
// https://medium.com/cameron-nokes/how-to-create-a-hybrid-electron-app-53553ece0889
// in preload scripts, we have access to node.js and electron APIs
// the remote web app will not have access, so this is safe
const { ipcRenderer, ipc, remote } = require('electron');
const storage = require('electron-json-storage');
const ReconnectingWebSocket = require('rws').ReconnectingWebSocket;
init();
function init() {
console.log('PRELOADING');
// Expose a bridging API to by setting an global on `window`.
// We'll add methods to it here first, and when the remote web app loads,
// it'll add some additional methods as well.
//
// !CAREFUL! do not expose any functionality or APIs that could compromise the
// user's computer. E.g. don't directly expose core Electron (even IPC) or node.js modules.
window.Bridge = {
getGlobal: remote.getGlobal,
ipcRenderer: ipcRenderer,
ReconnectingWebSocket: ReconnectingWebSocket,
storage: {
get: storage.get,
getMany: storage.getMany,
set: storage.set
}
}
}