-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmain.js
More file actions
58 lines (49 loc) · 1.59 KB
/
main.js
File metadata and controls
58 lines (49 loc) · 1.59 KB
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
'use strict';
const { app, ipcMain, BrowserWindow, dialog, Menu, globalShortcut } = require('electron');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow = null;
ipcMain.on('crash', function(event, arg) {
process.crash(arg);
});
// Quit when all windows are closed.
app.on('window-all-closed', function() {
app.quit();
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({
useContentSize: true,
width: 1010,
height: 650,
'autoHideMenuBar': true,
resizable: false,
show: false
});
// Some processing is required to make sure local file can be opened in browser
// windows allows # in names and it should be replaced with ASCII encoding.
let baseLocation = encodeURI(__dirname.replace(/\\/g, '/')).replace(/#/g, '%23');
// Load the index.html of the app
mainWindow.loadURL(`file://${baseLocation}/dist/index.html`);
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
mainWindow = null;
});
mainWindow.on('close', function(e) {
let opt = {
type: 'none',
buttons: ['Yes', 'No'],
defaultId: 1,
cancelId: 1,
message: 'Are you sure you want to close the installer?'
};
if (dialog.showMessageBox(mainWindow, opt)) {
e.preventDefault();
}
});
});