-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
90 lines (79 loc) · 1.62 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
const { app, BrowserWindow, Menu, ipcMain } = require("electron");
let window_open = false;
let popup, win;
const menu = [
{
label: "File",
submenu: [
{
label: "Hello",
accelerator: "Ctrl+H",
click() {
console.log("Hello");
},
},
{
label: "New Window",
accelerator: "Ctrl+N",
click() {
createPopupWindow();
},
},
{
label: "Quit",
accelerator: "ESC",
click() {
app.quit();
},
},
],
},
{
label: "DevTools",
accelerator: "F12",
click(_item, focusedWindow) {
focusedWindow.toggleDevTools();
},
},
];
const createWindow = () => {
win = new BrowserWindow({
width: 800,
height: 600,
resizable: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
win.loadURL("http://localhost:3000");
};
const createPopupWindow = () => {
if (window_open) return;
popup = new BrowserWindow({
width: 300,
height: 200,
resizable: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
window_open = true;
popup.on("close", () => {
window_open = false;
popup = null;
});
popup.loadFile("popup.html");
popup.setMenu(null);
};
app.on("window-all-closed", () => app.quit());
app.whenReady().then(() => {
createWindow();
const template = Menu.buildFromTemplate(menu);
Menu.setApplicationMenu(template);
});
ipcMain.on("data-from-popup", (_e, payload) => {
popup.close();
win.webContents.send("update", payload);
});