-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
142 lines (121 loc) · 4.11 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const { app, BrowserWindow, ipcMain, Menu, shell } = require('electron');
const path = require('path');
const url = require('url');
const log = require('electron-log');
const { autoUpdater } = require('electron-updater');
function isDev() {
// return require.main.filename.indexOf('app.asar') === -1;
//TODO: update to check for dev
return true;
};
app.allowRendererProcessReuse = false
// Logger for autoUpdater
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
//needed for forcing update check in develop
// autoUpdater.forceDevUpdateConfig = true;
log.info('App starting...');
let win = null;
app.on('ready', function () {
// Initialize the window to our specified dimensions
win = new BrowserWindow({
width: 1000,
height: 600,
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, 'preload.js')
},
});
win.maximize();
// Specify entry point
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/neb-tool/browser/index.html'),
protocol: 'file',
slashes: true
}));
if (isDev()) {
win.toggleDevTools();
}
// Remove window once app is closed
win.on('closed', function () {
win = null;
});
//signal from core.component to check for update
ipcMain.on('ready', (coreCompEvent, arg) => {
if (!isDev()) {
autoUpdater.checkForUpdates().then(() => {
log.info('done checking for updates');
if (autoUpdater.updateInfoAndProvider) {
win.webContents.send('release-info', autoUpdater.updateInfoAndProvider.info);
}
});
autoUpdater.on('update-available', (event, info) => {
log.info('update available');
win.webContents.send('available', true);
});
autoUpdater.on('error', (event, error) => {
log.info('error');
win.webContents.send('error', error);
});
autoUpdater.on('update-downloaded', (event, info) => {
autoUpdater.quitAndInstall();
win.webContents.send('update-downloaded');
});
}
})
ipcMain.once('quit-and-install', (event, arg) => {
autoUpdater.quitAndInstall(false);
})
//Check for updates and install
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
var template = [{
label: "Application",
submenu: [
{ label: "Quit", accelerator: "Command+Q", click: function () { app.quit(); } },
{ label: "Dev Tools", accelerator: "CmdOrCtrl+I", click: function () { win.toggleDevTools(); } }
]
}, {
label: "Edit",
submenu: [
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ type: "separator" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
win.setMenuBarVisibility(false)
win.webContents.on('new-window', function (e, url) {
// make sure local urls stay in electron perimeter
if ('file://' === url.substr(0, 'file://'.length)) {
return;
}
e.preventDefault();
shell.openExternal(url);
});
});
// Listen for message from application (electron component) to either download updates
ipcMain.once('update', (event, arg) => {
log.info('update')
autoUpdater.downloadUpdate();
});
ipcMain.once('later', (event, arg) => {
update = null;
});
ipcMain.once('relaunch', () => {
app.relaunch();
app.exit();
});
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
app.on('window-all-closed', function () {
app.quit();
});