-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
executable file
·78 lines (64 loc) · 1.84 KB
/
timer.js
File metadata and controls
executable file
·78 lines (64 loc) · 1.84 KB
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
#!/usr/bin/node
/**
*
* Timer for tea or mate time! or anything else.
* Displays system notification bubble
* Author: Andrrr
*
* Usage: $ node timer.js [time in minutes] [message on timer finish]
* Example: $ node timer.js 0.3 "Finished after 30 seconds!"
*
*/
'use strict';
let
notifier = require('node-notifier'),
path = require('path'),
colors = require('colors');
const
icon_start = 'img/pava-calentando.png',
icon_end = 'img/pava-hirviendo.png';
var
time = process.argv[2] || 5,
message = process.argv[3] || 'Time\'s up!',
unit = 'minutes',
time_message = '';
if (time < 1) {
time_message = parseInt(time * 100);
time = parseInt(time * 100000);
unit = 'seconds';
} else {
time_message = parseInt(time);
time = parseInt(time) * 60000;
}
// Define notification announcing that the counter started
var start_timer = {
title: 'Counting...',
message: '(' + time_message + ' ' + unit + ')',
icon: path.join(__dirname, icon_start),
wait: false
}
// Define notification announcing that the counter ended
var end_timer = {
title: 'Done!',
message: message,
icon: path.join(__dirname, icon_end),
sound: true,
wait: false
}
// Show bubble notification (start)
notifier.notify(start_timer);
// Show console notification (start), for example, for use in CLI or SSH
console.log('+-------------------------+');
console.log(start_timer.title.red.bold);
console.log(start_timer.message.red);
console.log('+-------------------------+');
// Start timer
let timer = setTimeout(function() {
// Show bubble notification (end)
notifier.notify(end_timer);
// Show console notification (end)
console.log('+-------------------------+');
console.log(end_timer.title.green.bold);
console.log(end_timer.message.green);
console.log('+-------------------------+');
}, time);