-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
86 lines (74 loc) · 1.95 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
const { app, BrowserWindow, Tray, Menu, ipcMain } = require('electron');
const path = require('path');
let tray = null;
let mainWindow = null;
let alertWindow = null;
let alertTimeout = null;
function createWindow() {
mainWindow = new BrowserWindow({
width: 500,
height: 400,
webPreferences: {
nodeIntegration: true,
contextIsolation: false, // Added for ipc communication
},
});
mainWindow.loadFile('index.html');
// Remove the default menu bar
mainWindow.setMenuBarVisibility(false);
}
function createAlertWindow() {
alertWindow = new BrowserWindow({
width: 320,
height: 220,
frame: false,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false, // Added for ipc communication
},
});
alertWindow.loadFile('alert.html');
const closeAlertTimeout = setTimeout(() => {
if (alertWindow && !alertWindow.isDestroyed()) {
alertWindow.close();
alertWindow = null;
}
}, 20000); // 20 seconds
alertWindow.on('closed', () => {
clearTimeout(closeAlertTimeout);
alertWindow = null;
startAlertInterval();
// Send message to mainWindow to reset the timer
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send('reset-timer');
}
});
}
function startAlertInterval() {
alertTimeout = setTimeout(() => {
if (!alertWindow) {
createAlertWindow();
}
}, 20 * 60 * 1000); // 20 minutes in milliseconds
}
app.on('ready', () => {
createWindow();
tray = new Tray(path.join(__dirname, 'icon.png'));
const contextMenu = Menu.buildFromTemplate([
{ label: 'Quit', click: () => { app.quit(); } },
]);
tray.setToolTip('EyeEase');
tray.setContextMenu(contextMenu);
startAlertInterval();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});