-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
84 lines (67 loc) · 2.66 KB
/
renderer.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
const { ipcRenderer } = require('electron');
const $btnStopResume = document.getElementById('stop-resume');
const $btnPlay = document.getElementById('play');
const $btnCloseApp = document.getElementById('close-app');
const $timerDisplay = document.getElementById('timer');
const $btnStopResumeIcon = document.getElementById('stop-resume_icon');
const $btnPlayIcon = document.getElementById('play_icon');
document.addEventListener('DOMContentLoaded', () => {
const [min, sec] = $timerDisplay.innerText.split(':').map(Number);
let configuredTime = min * 60 + sec;
let timeLeft = configuredTime;
let paused = false;
const showNotification = (NOTIFICATION_TITLE, NOTIFICATION_BODY) => {
new window.Notification(
NOTIFICATION_TITLE,
{
body: NOTIFICATION_BODY
}
)
//.onclick = () => { document.getElementById('output').innerText = CLICK_MESSAGE }
}
const updateTimerDisplay = () => {
let min = String(Math.floor(timeLeft / 60)).padStart(2, '0');
let sec = String(timeLeft % 60).padStart(2, '0');
if (timeLeft <= 0) {
min = String(Math.floor(configuredTime / 60)).padStart(2, '0');
sec = String(configuredTime % 60).padStart(2, '0');
}
$timerDisplay.textContent = `${min}:${sec}`;
}
let counter;
const start = () => {
counter = setInterval(() => {
if (timeLeft <= 0) {
clearInterval(counter);
showNotification('Timer encerrado', 'Seu timer foi concluído, tire uma pausa.');
}
if (!paused && timeLeft > 0) {
timeLeft--;
updateTimerDisplay();
$btnPlayIcon.src = './resources/icons/restart_alt_24dp.svg'
}
}, 1000);
}
$btnPlay.addEventListener('click', e => {
e.preventDefault();
if(timeLeft > 0 && timeLeft < configuredTime) {
clearInterval(counter);
paused = false;
$btnStopResumeIcon.src = './resources/icons/pause_24dp.svg';
$btnPlayIcon.src = './resources/icons/play_arrow_24dp.svg';
timeLeft = configuredTime;
updateTimerDisplay();
} else {
start();
}
});
$btnStopResume.addEventListener('click', e => {
e.preventDefault();
if (timeLeft == configuredTime || timeLeft <= 0) return;
paused = !paused;
$btnStopResumeIcon.src = paused ? './resources/icons/resume_24dp.svg' : './resources/icons/pause_24dp.svg';
});
$btnCloseApp.addEventListener('click', () => {
ipcRenderer.send('close-app');
});
});