-
Notifications
You must be signed in to change notification settings - Fork 29
/
preload.js
24 lines (20 loc) · 1.12 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
'use strict';
const electron = require('electron');
const { contextBridge } = electron;
const { ipcRenderer } = electron;
const deserializeJson = (serializedJavascript) => eval('(' + serializedJavascript + ')'); //deserialize function for 'serialize-javascript' library
let onPreferencesUpdatedHandler;
contextBridge.exposeInMainWorld('api', {
getSections: () => deserializeJson(ipcRenderer.sendSync('getSections')),
getPreferences: () => ipcRenderer.sendSync('getPreferences'),
getDefaults: () => ipcRenderer.sendSync('getDefaults'),
getConfig: () => ipcRenderer.sendSync('getConfig'),
setPreferences: preferences => ipcRenderer.send('setPreferences', preferences),
showOpenDialog: dialogOptions => ipcRenderer.sendSync('showOpenDialog', dialogOptions),
sendButtonClick: channel => ipcRenderer.send('sendButtonClick', channel),
encrypt: secret => ipcRenderer.sendSync('encrypt', secret),
onPreferencesUpdated: handler => { onPreferencesUpdatedHandler = handler; },
});
ipcRenderer.on('preferencesUpdated', (e, preferences) => {
typeof onPreferencesUpdatedHandler === "function" && onPreferencesUpdatedHandler(preferences);
});