Skip to content

Commit

Permalink
Add sendNotifications option to clock module (MagicMirrorOrg#3059)
Browse files Browse the repository at this point in the history
Fixes MagicMirrorOrg#3056 

One question here would be if the default for this new option should be
true or false.

True: keeps the current behaviour, nobody needs to change his config if
they rely on this option

False: keeps the clock notifications quiet, doesnt waste time/resources,
keeps the noise low

Maybe the original author @cybex-dev can weigh in on this, and why he
added this notification.

---------

Co-authored-by: veeck <michael@veeck.de>
  • Loading branch information
rejas and veeck committed Apr 1, 2023
1 parent 4ef030a commit b5a22bc
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _This release is scheduled to be released on 2023-04-01._
- Added possibility to use environment variables in `config.js` (#1756)
- Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed
- Added thai language to alert module
- Added option `sendNotifications` in clock module (#3056)

### Removed

Expand Down
27 changes: 16 additions & 11 deletions modules/default/clock/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Module.register("clock", {
showTime: true,
showWeek: false,
dateFormat: "dddd, LL",
sendNotifications: false,

/* specific to the analog clock */
analogSize: "200px",
Expand Down Expand Up @@ -66,23 +67,27 @@ Module.register("clock", {
const notificationTimer = () => {
this.updateDom();

// If seconds is displayed CLOCK_SECOND-notification should be sent (but not when CLOCK_MINUTE-notification is sent)
if (this.config.displaySeconds) {
this.second = moment().second();
if (this.second !== 0) {
this.sendNotification("CLOCK_SECOND", this.second);
setTimeout(notificationTimer, delayCalculator(0));
return;
if (this.config.sendNotifications) {
// If seconds is displayed CLOCK_SECOND-notification should be sent (but not when CLOCK_MINUTE-notification is sent)
if (this.config.displaySeconds) {
this.second = moment().second();
if (this.second !== 0) {
this.sendNotification("CLOCK_SECOND", this.second);
setTimeout(notificationTimer, delayCalculator(0));
return;
}
}

// If minute changed or seconds isn't displayed send CLOCK_MINUTE-notification
this.minute = moment().minute();
this.sendNotification("CLOCK_MINUTE", this.minute);
}

// If minute changed or seconds isn't displayed send CLOCK_MINUTE-notification
this.minute = moment().minute();
this.sendNotification("CLOCK_MINUTE", this.minute);
setTimeout(notificationTimer, delayCalculator(0));
};

// Set the initial timeout with the amount of seconds elapsed as reducedSeconds so it will trigger when the minute changes
// Set the initial timeout with the amount of seconds elapsed as
// reducedSeconds, so it will trigger when the minute changes
setTimeout(notificationTimer, delayCalculator(this.second));

// Set locale.
Expand Down
Loading

0 comments on commit b5a22bc

Please sign in to comment.