forked from hovancik/stretchly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreak.js
54 lines (46 loc) · 2.13 KB
/
break.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
const { ipcRenderer } = require('electron')
const remote = require('@electron/remote')
const Utils = remote.require('./utils/utils')
const HtmlTranslate = require('./utils/htmlTranslate')
window.onload = (event) => {
require('./platform')
new HtmlTranslate(document).translate()
document.ondragover = event =>
event.preventDefault()
document.ondrop = event =>
event.preventDefault()
document.querySelector('#close').onclick = event =>
ipcRenderer.send('finish-break', false)
document.querySelector('#postpone').onclick = event =>
ipcRenderer.send('postpone-break')
ipcRenderer.on('breakIdea', (event, message) => {
const breakIdea = document.querySelector('.break-idea')
breakIdea.innerHTML = message[0]
const breakText = document.querySelector('.break-text')
breakText.innerHTML = message[1]
})
ipcRenderer.on('progress', (event, started, duration, strictMode, postpone, postponePercent, settings) => {
const progress = document.querySelector('#progress')
const progressTime = document.querySelector('#progress-time')
const postponeElement = document.querySelector('#postpone')
const closeElement = document.querySelector('#close')
const mainColor = settings.data.mainColor
document.body.classList.add(mainColor.substring(1))
document.querySelectorAll('.tiptext').forEach(tt => {
const keyboardShortcut = settings.data.endBreakShortcut
tt.innerHTML = Utils.formatKeyboardShortcut(keyboardShortcut)
})
window.setInterval(() => {
if (Date.now() - started < duration) {
const passedPercent = (Date.now() - started) / duration * 100
Utils.canSkip(strictMode, postpone, passedPercent, postponePercent)
postponeElement.style.display =
Utils.canPostpone(postpone, passedPercent, postponePercent) ? 'flex' : 'none'
closeElement.style.display =
Utils.canSkip(strictMode, postpone, passedPercent, postponePercent) ? 'flex' : 'none'
progress.value = (100 - passedPercent) * progress.max / 100
progressTime.innerHTML = Utils.formatTimeRemaining(Math.trunc(duration - Date.now() + started))
}
}, 100)
})
}