-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
29 lines (26 loc) · 1.01 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
const { contextBridge, ipcRenderer } = require('electron/renderer');
const superagent = require('superagent');
const cheerio = require('cheerio');
const { resolve } = require('path');
contextBridge.exposeInMainWorld('electron', {
loadPage: url => ipcRenderer.send('load-page', url),
maximize: () => ipcRenderer.send('max-app', {}),
closeApp: () => ipcRenderer.send('close-app', {}),
getAppVersion: () => {
return require('./package.json').version;
}
});
contextBridge.exposeInMainWorld('webSupplier', {
getTitle: url => {
if(url.length == 0) return new Promise((resolve, reject) => resolve(null));
return new Promise((resolve, reject) => {
superagent.get(url).then(html => {
resolve(cheerio.load(html.text)('head>title').text());
}).catch(reject);
});
}
});
contextBridge.exposeInMainWorld('emitter', {
send: (channel, data) => ipcRenderer.send(channel, data),
recieve: (channel, callback) => ipcRenderer.on(channel, (_, ...data) => callback(...data))
});