-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
124 lines (104 loc) · 3.83 KB
/
main.js
File metadata and controls
124 lines (104 loc) · 3.83 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const { app, BrowserWindow, Notification, ipcMain } = require('electron');
const sound = require("sound-play");
const path = require("path");
let mainWindow;
let intervalId;
// Function to display a notification with emoji and play a beep sound
const displayNotificationAndBeep = (title, message) => {
const iconPath = path.join(__dirname, 'media', 'icon.png');
const notification = new Notification({
title,
body: message,
icon: iconPath,
silent: true,
});
notification.show();
const beepPath = __dirname + '/../media/bubble.wav'
sound.play(beepPath, 1.0);
}
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 500,
height: 350,
autoHideMenuBar: true,
resizable: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
mainWindow.loadFile(path.join(__dirname, 'ui', 'main.html'));
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('window-loaded');
});
}
app.whenReady().then(() => {
createWindow();
// Add auto-start functionality
const appName = "20-20-20-refresh";
// Add the application name to the Windows Registry entry
const appExePath = app.getPath('exe');
const regCommand = `REG ADD HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /v ${appName} /t REG_SZ /d "${appExePath}" /f`;
require('child_process').exec(regCommand, (error, stdout, stderr) => {
if (error) {
console.error(`Error adding Registry entry: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(`Registry entry added successfully: ${stdout}`);
});
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
ipcMain.on('startApp', () => {
updateTimer();
});
ipcMain.on('stopApp', () => {
clearInterval(intervalId);
minutes = 20
seconds = 0
mainWindow.webContents.send('updateTimer', minutes, seconds);
intervalId = null;
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});
const updateTimer = () => {
let minutes = 20;
let seconds = 0;
const startTimer = () => {
intervalId = setInterval(() => {
if (minutes === 0 && seconds === 0) {
clearInterval(intervalId); // Clear the main timer interval
// Start 20-second break
displayNotificationAndBeep("Take a Break! ", "Remember to rest your eyes. Look at something 20 feet away for 20 seconds.");
let breakSeconds = 20;
let breakIntervalId = setInterval(() => {
if (breakSeconds === 0) {
clearInterval(breakIntervalId); // Clear the break interval
displayNotificationAndBeep("Break Over! ", "Back to work! Let's get productive. ");
updateTimer(); // Restart the timer after the break
}
// Send updated timer values to renderer process
mainWindow.webContents.send('updateTimer', 0, breakSeconds);
breakSeconds--;
}, 1000); // Update every second during the break
}
// Send updated timer values to renderer process
mainWindow.webContents.send('updateTimer', minutes, seconds);
// Decrease timer
if (seconds === 0) {
seconds = 59;
minutes--;
} else {
seconds--;
}
}, 1000); // Update every second
};
startTimer();
};