-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (61 loc) · 2.34 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { app, BrowserWindow, Menu } = require('electron');
const path = require('path');
require('@electron/remote/main').initialize();
require('electron').protocol.registerSchemesAsPrivileged([
{ scheme: 'js', privileges: { standard: true, secure: true } }
]);
function protocolHandler(request, respond) {
try {
let pathname = request.url.replace(/^js:\/*/, '');
let filename = path.resolve(app.getAppPath(), pathname);
respond({ mimeType: 'text/javascript', data: require('fs').readFileSync(filename) });
} catch (e) {
console.error(e, request);
}
}
app.on('ready', () => {
require('electron').protocol.registerBufferProtocol('js', protocolHandler);
app.win = new BrowserWindow({
width: 544,
height: 244,
minWidth: 512,
minHeight: 212,
backgroundColor: '#000',
icon: { darwin: 'icon.icns', linux: 'icon.png', win32: 'icon.ico' }[process.platform] || 'icon.ico',
resizable: true,
frame: process.platform !== 'darwin',
skipTaskbar: process.platform === 'darwin',
autoHideMenuBar: process.platform === 'darwin',
webPreferences: {
zoomFactor: 1.0,
nodeIntegration: true,
backgroundThrottling: false,
enableRemoteModule: true,
},
});
app.win.loadFile('dist/index.html');
app.win.on('closed', () => { win = null; app.quit(); });
app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); });
app.on('activate', () => { app.win === null ? createWindow() : app.win.show(); });
app.inspect = () => { app.win.toggleDevTools(); }
app.toggleFullscreen = () => {
app.win.setFullScreen(!app.win.isFullScreen());
}
app.toggleVisible = function () {
if (process.platform === 'darwin') {
(app.win.isVisible() && !app.win.isFullScreen()) ? app.win.hide() : app.win.show();
} else {
app.win.isMinimized() ? app.win.restore() : app.win.minimize();
}
}
app.toggleMinimized = function () {
app.win.isMinimized() ? app.win.restore() : app.win.minimize();
}
app.injectMenu = function (menu) {
try {
Menu.setApplicationMenu(Menu.buildFromTemplate(menu));
} catch (err) {
console.warn('Cannot inject menu.');
}
}
});