-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
58 lines (48 loc) · 1.34 KB
/
Copy pathmain.js
File metadata and controls
58 lines (48 loc) · 1.34 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
const { app, BrowserWindow, powerSaveBlocker, ipcMain } = require('electron');
let mainWindow;
let timer;
let timeLeft = 25 * 60; // 25 minutes
let powerSaveId;
function createWindow() {
powerSaveId = powerSaveBlocker.start('prevent-app-suspension');
mainWindow = new BrowserWindow({
width: 800,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.loadFile('index.html');
}
app.whenReady().then(createWindow);
app.on('will-quit', () => {
powerSaveBlocker.stop(powerSaveId);
});
// Timer control functions
function startTimer() {
if (timer) return; // Prevent multiple intervals
timer = setInterval(() => {
timeLeft--;
mainWindow.webContents.send('timer-update', timeLeft);
if (timeLeft <= 0) {
clearInterval(timer);
timer = null;
mainWindow.webContents.send('timer-finished');
}
}, 1000);
}
function pauseTimer() {
clearInterval(timer);
timer = null;
}
function resetTimer() {
clearInterval(timer);
timer = null;
timeLeft = 25 * 60;
mainWindow.webContents.send('timer-update', timeLeft);
}
// IPC handlers
ipcMain.on('start-timer', startTimer);
ipcMain.on('pause-timer', pauseTimer);
ipcMain.on('reset-timer', resetTimer);