-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.js
62 lines (50 loc) · 1.42 KB
/
notification.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
const dataStore = require('./dataStore');
const eventHandler = require('./eventHandler');
const notifier = require('node-notifier');
const settings = require('./settings');
let tasks = require('./tasks.json');
const checkTime = (time, taskID) => {
let currentHour = time.getHours();
let currentMinute = time.getMinutes();
let currentSecond = time.getSeconds();
let taskHour = tasks[taskID].time.hours;
let taskMinute = tasks[taskID].time.minutes;
let taskSecond = tasks[taskID].time.seconds;
if (taskHour == currentHour &&
taskMinute == currentMinute &&
taskSecond == currentSecond) {
return true;
}
return false;
}
const timerId = setInterval(() => {
let now = new Date();
process.stdout.write("Current time is: " + now);
setTimeout(() => {
process.stdout.clearLine();
}, 900);
process.stdout.cursorTo(0);
for (let task in tasks) {
let timeMatch = checkTime(now, task);
if (timeMatch) {
notifier.notify(tasks[task].props);
delete tasks[task];
}
}
}, settings.workingIntervalSec);
console.log("Running timer");
setTimeout(() => {
console.log("Timer was stopped");
clearInterval(timerId);
dataStore(tasks);
}, settings.workingTimeSec);
process.on('SIGINT', () => {
console.log('Goodbye!');
process.exit(2);
});
notifier.on('click', (obj, options) => {
eventHandler.processClick(obj, options);
});
notifier.on('timeout', (obj, options) => {
eventHandler.processTimeout(obj, options);
});