-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
116 lines (101 loc) · 2.7 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
// Main Process
const {
app,
BrowserWindow,
Notification,
ipcMain,
Menu,
Tray,
} = require('electron');
const isDev = !app.isPackaged;
const path = require('path');
const dockIcon = path.join(__dirname, 'assets', 'images', 'react_app_logo.png');
const trayIcon = path.join(__dirname, 'assets', 'images', 'react_icon.png');
function createSplashWindow() {
// Browser Window <- Renderer Process
const window = new BrowserWindow({
width: 400,
height: 200,
backgroundColor: '#6e707e',
frame: false,
transparent: true,
webPreferences: {
nodeIntegration: false,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
},
});
window.loadFile('splash.html');
return window;
}
function createWindow() {
const window = new BrowserWindow({
width: 1200,
height: 800,
backgroundColor: '#6e707e',
show: false,
webPreferences: {
nodeIntegration: false,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
},
});
window.loadFile('index.html');
isDev && window.webContents.openDevTools();
return window;
}
console.log(isDev);
if (isDev) {
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron'),
});
}
if (process.platform === 'darwin') {
app.dock.setIcon(dockIcon);
}
let tray = null;
app.whenReady().then(() => {
const template = require('./utils/Menu').createTemplate(app);
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
tray = new Tray(trayIcon);
tray.setContextMenu(menu);
const splash = createSplashWindow();
const mainApp = createWindow();
mainApp.once('ready-to-show', () => {
// splash.destroy();
// mainApp.show();
setTimeout(() => {
splash.destroy();
mainApp.show();
}, 1000);
});
});
ipcMain.on('notify', (_, message) => {
new Notification({
title: 'Notification',
body: message,
}).show();
});
ipcMain.on('app-quit', () => {
app.quit();
});
app.on('window-all-closed', () => {
if (process.platform !== 'win32') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// Chromium -> Web Engine for rendering the UI, full Chrome web browser with the removal of the Google Excess
// V8 -> Engine that provies capabilities to execute, run JS code in the browser
// Node JS(V8) -> we able to run JS code + provide more features
// Webpack -> is a module builder, main purpose is to bundle JS files for usage in browser
// Babel -> JS compiler
console.log('Hello World!');
console.log(process.platform);
console.log('We made it!, Website has loaded');