-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.js
47 lines (34 loc) · 1.12 KB
/
window.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
let { ipcRenderer, remote } = require('electron');
let moment = require('moment');
let eventLog = remote.require('./event-log.js');
(function () {
let eventList = document.querySelector('.event-log');
let clearButton = document.querySelector('.clear-button');
clearButton.addEventListener('click', clearEventLog);
let closeButton = document.querySelector('.close-button');
closeButton.addEventListener('click', quit);
let storedEvents = eventLog.loadStoredEvents();
storedEvents.forEach(logEvent);
ipcRenderer.on('notify', (event, arg) => {
logEvent({ text: arg.options.body });
notify(arg);
});
function logEvent(event) {
let time = moment(event.date).calendar();
let log = `${time} — ${event.text}`;
let li = document.createElement('li');
li.textContent = log;
eventList.insertBefore(li, eventList.children[0]);
eventLog.addEvent(event);
}
function clearEventLog() {
eventList.innerHTML = '';
eventLog.clearStoredEvents();
}
function notify({ title, options }) {
new Notification(title, options);
}
function quit () {
ipcRenderer.send('quit');
}
})();