Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
112 lines (94 loc) · 2.8 KB
/
Copy pathmain.js
File metadata and controls
112 lines (94 loc) · 2.8 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
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
// Main Process
const {
app,
BrowserWindow,
ipcMain,
Notification,
Menu,
Tray,
} = require("electron");
const path = require("path");
const isDev = !app.isPackaged;
const dockIcon = path.join(__dirname, "assets", "images", "react_app_logo.png");
const trayIcon = path.join(__dirname, "assets", "images", "react_icon.png");
// This is a window for our splash screen. Not a bad idea to have one before the app is ready.
function createSplashWindow() {
const win = new BrowserWindow({
width: 400,
height: 200,
frame: false,
transparent: true,
webPreferences: {
nodeIntegration: false,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
},
});
win.loadFile("splash.html");
return win;
}
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
backgroundColor: "#6e707e",
show: false,
webPreferences: {
nodeIntegration: false,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
preload: path.join(__dirname, "preload.js"),
},
});
win.loadFile("index.html");
isDev && win.webContents.openDevTools();
return win;
}
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();
// Should we get it out of the timeout probably?
setTimeout(() => {
splash.destroy();
mainApp.show();
}, 2000);
});
});
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 !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// Chromium -> web eingine for rendering the UI, full Chrome-like web browser
// V8 -> engine that provides capabilities to execute, run, JS code in the browser
// Node JS(V8) -> we are able to run JS code + provides more features
// Webpack -> is a module builder, main purpose is to bundle JS files for usage in the browsert
// Babel -> js a JS compiler