-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.js
85 lines (73 loc) · 2.05 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
const electron = require('electron');
const menuTemplate = require('./menu.js');
const ipcMain = electron.ipcMain;
const app = electron.app;
const Menu = electron.Menu;
const BrowserWindow = electron.BrowserWindow;
let loadingParams = {
width: 580,
height: 200,
frame: false,
show: false
};
let mainParams = {
width: 1300,
height: 780,
icon: __dirname + '/icon1.png',
// titleBarStyle: 'hidden-inset',
backgroundColor: '#fff',
show: false
};
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow(mainParams);
mainWindow.setTitle(require('./package.json').name);
//setting in .vscode/launch.json
if (process.env.NODE_ENV === 'development') {
console.log('develop');
mainWindow.loadURL('http://localhost:8099');
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadURL(`file://${__dirname}/client/index.html`);
}
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
if (loadingScreen) {
loadingScreen.close();
}
});
mainWindow.on('closed', () => {
mainWindow = null;
});
}
function createLoadingScreen() {
loadingScreen = new BrowserWindow(Object.assign(loadingParams, {parent: mainWindow}));
if (process.env.NODE_ENV === 'development') {
loadingScreen.loadURL('http://localhost:4000/loading.html');
} else {
loadingScreen.loadURL(`file://${__dirname}/client/loading.html`);
}
loadingScreen.on('closed', () => loadingScreen = null);
loadingScreen.webContents.on('did-finish-load', () => {
loadingScreen.show();
});
}
function createMenu() {
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
}
app.on('ready', () => {
createLoadingScreen();
createWindow();
createMenu();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});