-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
73 lines (63 loc) · 1.77 KB
/
main.js
File metadata and controls
73 lines (63 loc) · 1.77 KB
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
const {
app,
BrowserWindow,
ipcMain,
Tray,
Menu,
globalShortcut,
} = require('electron');
const data = require('./data');
const templateGenerator = require('./template');
let tray = null;
let mainWindow = null;
app.on('ready', () => {
console.log('App started');
mainWindow = new BrowserWindow({
width: 600,
height: 400,
});
tray = new Tray(`${__dirname}/app/img/icon.png`);
let template = templateGenerator.geraTrayTemplate(mainWindow);
let trayMenu = Menu.buildFromTemplate(template);
tray.setContextMenu(trayMenu);
let templateMenu = templateGenerator.geraMenuPrincipalTemplate();
let menuPrincipal = Menu.buildFromTemplate(templateMenu);
Menu.setApplicationMenu(menuPrincipal);
globalShortcut.register('CmdOrCtrl+Shift+S', () => {
mainWindow.send('atalho-iniciar-parar');
});
mainWindow.loadURL(`file://${__dirname}/app/index.html`);
});
app.on('window-all-closed', () => {
app.quit();
});
let sobreWindow = null;
ipcMain.on('abrir-janela-sobre', () => {
if (sobreWindow == null) {
sobreWindow = new BrowserWindow({
width: 300,
height: 250,
alwaysOnTop: true,
frame: false,
});
sobreWindow.on('closed', () => {
sobreWindow = null;
});
}
sobreWindow.loadURL(`file://${__dirname}/app/sobre.html`);
});
ipcMain.on('fechar-janela-sobre', () => {
sobreWindow.close();
});
ipcMain.on('curso-parado', (event, curso, tempoEstudado) => {
console.log(`O curso ${curso} foi estudado por ${tempoEstudado}`);
data.salvaDados(curso, tempoEstudado);
});
ipcMain.on('curso-adicionado', (event, novoCurso) => {
let novoTemplate = templateGenerator.adicionaCursoNoTray(
novoCurso,
mainWindow
);
let novoTrayMenu = Menu.buildFromTemplate(novoTemplate);
tray.setContextMenu(novoTrayMenu);
});