-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
103 lines (81 loc) · 2.47 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
'use strict';
// Modules
const {app, BrowserWindow} = require('electron');
const windowStateKeeper = require('electron-window-state');
let mainWindow;
console.log('checking ready: ' + app.isReady());
// Create a new BrowserWindow when `app` is ready
function createWindow() {
let mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 800
});
console.log("creating windows...");
mainWindow = new BrowserWindow({
width: mainWindowState.width, height: mainWindowState.height,
x: mainWindowState.x, y: mainWindowState.y,
//frame: false,
webPreferences: {
// --- !! IMPORTANT !! ---
// Disable 'contextIsolation' to allow 'nodeIntegration'
// 'contextIsolation' defaults to "true" as from Electron v12
contextIsolation: false,
nodeIntegration: true,
//show: false
backgroundColor: '#00105a'
}
});
mainWindowState.manage(mainWindow);
// Load index.html into the new BrowserWindow
mainWindow.loadFile('index.html');
mainWindow.once('ready-to-show', mainWindow.show);
// Open DevTools - Remove for PRODUCTION!
//mainWindow.webContents.openDevTools();
// let wc = mainWindow.webContents
// console.log(wc);
// wc.on('before-input-event', (e, input) => {
// console.log(`${input.key} : ${input.type}`)
// });
// Listen for window being closed
mainWindow.on('closed', () => {
//debugger
mainWindow = null
});
}
// Electron `app` is ready
app.on('ready', () => {
console.log('app is ready? ' + app.isReady());
// console.log(app.getPath('home'));
// console.log(app.getPath('appData'));
// console.log(app.getPath('userData'));
// console.log(app.getPath('desktop'));
// console.log(app.getPath('documents'));
// console.log(app.getPath('downloads'));
createWindow()
});
//
// Quit when all windows are closed
app.on('window-all-closed', () => {
// check platform to avoid quitting (MacOS = Darwin)
if (process.platform !== 'darwin') app.quit();
// app.quit();
});
// MacOS only
// When app icon is clicked and app is running, (macOS) recreate the BrowserWindow
app.on('activate', () => {
console.log('activate triggered');
if (mainWindow === null)
createWindow();
});
app.on('before-quit', e => {
console.log('app is quitting...');
// check whether the work needs to be saved before quitting
// console.log('prevent app from quitting');
// e.preventDefault();
});
// app.on('browser-window-blur', () => {
// console.log('app unfocused')
// });
// app.on('browser-window-focus', () => {
// console.log('app focused')
// });