-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (82 loc) · 2.26 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
const fs = require('fs');
const electron = require('electron');
const {app, remote, Menu, BrowserWindow} = electron;
// prevent certain things from being garbage collected
let mainWindow;
let rpcServer;
let storage;
function onClosed() {
// dereference the window
// for multiple windows store them in an array
mainWindow = null;
}
function createMainWindow() {
var opts = {
title: 'Cerebral Electron Boilerplate',
width: 1200,
height: 600,
minWidth: 500,
minHeight: 200,
acceptFirstMouse: true,
//titleBarStyle: 'default',
backgroundColor: '#000000',
resizable: true,
webPreferences: {
nodeIntegration: true,
java: false,
javascript: true,
webSecurity: false,
allowDisplayingInsecureContent: false,
allowRunningUnsecureContent: false,
experimentalFeatures: true,
subpixelFontScaling: true
}
};
const win = new BrowserWindow(opts);
rpcServer = require('./scripts/rpcServer')(win.webContents);
const template = require('./scripts/menu')(rpcServer);
var menu = Menu.buildFromTemplate(template);
if (process.env.DEV) {
win.loadURL('http://localhost:8000/dev.html'); // no Node context
//win.loadURL(`file://${__dirname}/index.html`); // Node
win.openDevTools();
} else {
win.loadURL(`file://${__dirname}/index.html`); // Node context
}
win.on('closed', onClosed);
win.webContents.on('did-finish-load', function() {
//
})
//be aware that this is nested!
win.on('close', () => {
rpcServer.destroy()
});
if (menu) {
Menu.setApplicationMenu(menu);
menu = null;
}
return win;
}
app.on('window-all-closed', () => {
app.quit()
});
app.on('activate-with-no-open-windows', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
app.on('ready', () => {
//BrowserWindow.removeDevToolsExtension('Cerebral Debugger')
if (process.env.NODE_ENV !== 'production') { //this might not be right
let installer = require('electron-devtools-installer').default
installer('ddefoknoniaeoikpgneklcbjlipfedbb')
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
}
mainWindow = createMainWindow();
if (process.env.DEV) {
const watcher = require('./scripts/watcher.js');
watcher.watch(app, ['./index.js', './scripts']);
}
});