/
main.js
81 lines (67 loc) · 1.78 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
const {
app,
BrowserWindow,
ipcMain,
Tray,
Menu,
globalShortcut
} = require("electron");
const data = require("./data.js");
const templateGenerator = require("./template");
let tray = null;
let mainWindow;
/**
* Inicialização da Janela Principal
*/
app.on("ready", () => {
mainWindow = new BrowserWindow({
width: 600,
height: 400
});
tray = new Tray(__dirname + "/app/img/icon-tray.png");
let template = templateGenerator.generateTrayTemplate(mainWindow);
let traySubMenu = Menu.buildFromTemplate(template);
tray.setContextMenu(traySubMenu);
let templateMenu = templateGenerator.generateMainMenuTemplate(app);
let mainMenu = Menu.buildFromTemplate(templateMenu);
globalShortcut.register("CmdOrCtrl+Shift+S", () => {
mainWindow.send("shortcut-start-stop");
});
Menu.setApplicationMenu(mainMenu);
mainWindow.loadURL(`file://${__dirname}/app/index.html`);
});
app.on("window-all-close", () => {
app.quit();
});
let aboutWindow = null;
ipcMain.on("open-window-about", () => {
if (aboutWindow === null) {
aboutWindow = new BrowserWindow({
width: 300,
height: 220,
alwaysOnTop: true,
frame: false
});
}
/**
* Handles window close, to not be deleted by garbage collection
*/
aboutWindow.on("closed", () => {
aboutWindow = null;
});
aboutWindow.loadURL(`file://${__dirname}/app/about.html`);
});
ipcMain.on("close-about-window", () => {
aboutWindow.close();
});
ipcMain.on("stopped-course", (event, course, timeStudied) => {
data.saveData(course, timeStudied);
});
ipcMain.on("added-course", (event, newCourse) => {
let newTemplate = templateGenerator.addCourseOnTray(
newCourse,
mainWindow
);
let newTrayMenu = Menu.buildFromTemplate(newTemplate);
tray.setContextMenu(newTrayMenu);
});