-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
91 lines (73 loc) · 2.14 KB
/
app.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
const { app, screen, BrowserWindow, Menu } = require("electron");
const windowState = require("electron-window-state");
const path = require("path");
const { userAgent, isDevelopment } = require("./js/config");
const { template, createTray } = require("./js/menu");
let mainWindow;
let tray;
if (isDevelopment) {
try {
require("electron-reload")(__dirname, {
electron: path.join(__dirname, "node_modules", ".bin", "electron"),
hardResetMethod: "exit",
});
} catch (_) {}
}
function createWindow() {
const { workAreaSize } = screen.getPrimaryDisplay();
const mainWindowState = windowState({
defaultWidth: workAreaSize.width - 200,
defaultHeight: workAreaSize.height - 100,
});
mainWindow = new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
minWidth: 300,
minHeight: 300,
center: true,
backgroundColor: "#FFF",
webPreferences: {
preload: path.join(__dirname, "js", "preload.js"),
nodeIntegration: true,
contextIsolation: false,
},
icon: path.join(__dirname, "icons/png/64x64.png"),
});
mainWindowState.manage(mainWindow);
mainWindow.loadURL("https://classroom.google.com", { userAgent });
const menu = template(mainWindow);
Menu.setApplicationMenu(menu);
tray = createTray(mainWindow);
mainWindow.on("minimize", (event) => {
event.preventDefault();
mainWindow.hide();
});
mainWindow.on("close", (event) => {
if (!app.isQuiting) {
event.preventDefault();
mainWindow.hide();
}
return false;
});
}
const SingleInstance = app.requestSingleInstanceLock();
if (!SingleInstance) {
app.quit();
} else {
app.on("second-instance", () => {
if (mainWindow) {
if (!mainWindow.isVisible()) mainWindow.show();
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
app.whenReady().then(createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
}