-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.ts
78 lines (67 loc) · 1.94 KB
/
main.ts
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
import path from "path";
import { format as formatUrl } from "url";
import { app, BrowserWindow } from "electron";
import KeyEvents from "./main/events/KeyEvents";
import MouseEvents from "./main/events/MouseEvents";
import ScrollEvents from "./main/events/ScrollEvents";
// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow;
require("electron-debug")();
class MainProcess {
constructor() {
app.whenReady().then(() => {
this.createWindows();
this.registerEvents();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
this.createWindows();
}
});
});
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", function() {
if (process.platform !== "darwin") {
app.quit();
}
});
}
private createWindows() {
let url = formatUrl({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true,
});
let windowOptions = {
width: 800,
height: 600,
webPreferences: {
webSecurity: false,
nodeIntegration: true,
},
};
if (process.env.NODE_ENV !== "production") {
url = formatUrl({
pathname: `${process.cwd()}/dist/renderer/index.html`,
protocol: "file",
slashes: true,
});
new BrowserWindow(windowOptions).loadURL(url);
}
mainWindow = new BrowserWindow(windowOptions);
mainWindow.loadURL(url);
mainWindow.webContents.on("devtools-opened", () => {
mainWindow.focus();
setImmediate(() => {
mainWindow.focus();
});
});
}
private registerEvents() {
new KeyEvents().register();
new MouseEvents().register();
new ScrollEvents().register();
}
}
new MainProcess();