-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
125 lines (110 loc) · 3.65 KB
/
index.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
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
125
/**
* This file is loaded via the <script> tag in the index.html file and will
* be executed in the renderer process for that window. No Node.js APIs are
* available in this process because `nodeIntegration` is turned off and
* `contextIsolation` is turned on. Use the contextBridge API in `preload.js`
* to expose Node.js functionality from the main process.
*/
const workInputLabel = document.getElementById("workInputLabel");
const workInput = document.getElementById("workInput");
const restInputLabel = document.getElementById("restInputLabel");
const restInput = document.getElementById("restInput");
const resetBtn = document.getElementById("resetBtn");
const startBtn = document.getElementById("startBtn");
const progressBar = document.querySelector(".progress-bar");
const trayToggle = document.getElementById('trayToggle');
workInputLabel.innerText = workInput.value;
restInputLabel.innerText = restInput.value;
resetBtn.setAttribute("disabled", "disabled");
window.electronAPI.setWorkMinutes(workInput.value);
window.electronAPI.setRestMinutes(restInput.value);
workInput.addEventListener("change", () => {
workInputLabel.innerText = workInput.value;
window.electronAPI.setWorkMinutes(workInput.value);
});
restInput.addEventListener("change", () => {
restInputLabel.innerText = restInput.value;
window.electronAPI.setRestMinutes(restInput.value);
});
startBtn.addEventListener("click", () => {
window.electronAPI.startTimer();
startBtn.setAttribute("disabled", "disabled");
resetBtn.removeAttribute("disabled");
});
resetBtn.addEventListener("click", () => {
window.electronAPI.stopTimer();
resetBtn.setAttribute("disabled", "disabled");
startBtn.removeAttribute("disabled");
});
trayToggle.addEventListener("change",()=>{
window.electronAPI.toggleTrayStatus();
})
window.electronAPI.handleProgress((event, value) => {
progressBar.style.width = `${value}%`;
if (value <= 0) {
progressBar.classList.replace("bg-info", "bg-primary");
}
if (value >= 100) {
progressBar.classList.replace("bg-primary", "bg-info");
}
});
// let counter = 0;
// let isRunning = false;
// async function stopTimer() {
// isRunning = false;
// resetBtn.setAttribute("disabled", "disabled");
// startBtn.removeAttribute("disabled");
// // progressBar.style.width = "0%";
// }
//
// async function startTimer() {
// startBtn.setAttribute("disabled", "disabled");
// resetBtn.removeAttribute("disabled");
//
// counter = 0;
// isRunning = true;
// await workTimer();
// }
// async function workTimer() {
// const timer = setInterval(async () => {
// if (!isRunning) {
// clearInterval(timer);
// return;
// } else {
// if (counter >= 100) {
// new Notification("💧");
// clearInterval(timer);
// await restTimer();
// return;
// } else {
// counter += 100 / (workInput.value * 60);
// console.log(counter);
// progressBar.style.width = `${counter}%`;
// progressBar.setAttribute("class", "bg-primary progress-bar");
// return;
// }
// }
// }, 1000);
// }
//
// async function restTimer() {
// const timer = setInterval(async () => {
// if (!isRunning) {
// clearInterval(timer);
// return;
// } else {
// if (counter <= 0) {
// new Notification("🚀");
// clearInterval(timer);
// await workTimer();
// return;
// } else {
// counter -= 100 / (restInput.value * 60);
// console.log(counter);
// progressBar.setAttribute("class", "bg-info progress-bar");
// progressBar.style.width = `${counter}%`;
// return;
// }
// }
// }, 1000);
// }