-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (40 loc) · 1.16 KB
/
index.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
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const url = require("url");
const { IPC_EVENTS, CUSTOM_IPC_EVENTS } = require("./ipcevents");
const chalk = require("chalk");
function onAppReady() {
const mainWindow = new BrowserWindow({
height: 800,
width: 800,
show: false,
webPreferences: {
nodeIntegration: true,
},
allowRendererProcessReuse: true,
});
// Load main.html
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "main.html"),
protocol: "file",
slashes: true,
})
);
// Once electron 'ready-to-show' is emitted, show mainWindow
mainWindow.once(IPC_EVENTS.READY_TO_SHOW, function showMainWindow() {
mainWindow.show();
});
// Upon receiving "PING" event, log and reply if pingPong is still > 0
ipcMain.on(CUSTOM_IPC_EVENTS.PING, function (event, arg) {
console.log(
`${chalk.blue("MAIN PROCESS: ")} ${chalk.yellow(
`${CUSTOM_IPC_EVENTS.PING} message received. Message ${5 - arg + 1}/5`
)}`
);
if (arg > 0) {
event.reply(CUSTOM_IPC_EVENTS.PONG);
}
});
}
app.on(IPC_EVENTS.READY, onAppReady);