Added clock notifications for elapsed time.

Added notifications to default `clock` module to broadcast:
 - `CLOCK_SECOND` for a clock second, and 
 - `CLOCK_MINUTE` for a clock minute having elapsed.

Each notification is broadcasted with the corresponding value i.e. `CLOCK_SECOND` -> `30` and `CLOCK_MINUTE` -> `5` .
This commit is contained in:
Charles Dyason
2019-06-03 14:01:27 +02:00
parent c7d79bb893
commit b2f59d6813
3 changed files with 26 additions and 0 deletions

View File

@@ -41,11 +41,25 @@ Module.register("clock",{
// Schedule update interval.
var self = this;
self.second = 0;
self.minute = 0;
self.lastDisplayedMinute = null;
setInterval(function() {
if (self.config.displaySeconds || self.lastDisplayedMinute !== moment().minute()) {
self.updateDom();
}
if (self.second === 59) {
self.second = 0;
if (self.minute === 59){
self.minute = 0;
} else {
self.minute++;
}
self.sendNotification("CLOCK_MINUTE", self.minute);
} else {
self.second++;
self.sendNotification("CLOCK_SECOND", self.second);
}
}, 1000);
// Set locale.