Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 684c089

Browse files
committed
chore: send date object in app tick
1 parent 8a2a9d8 commit 684c089

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

app/components/Clock.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
const datefns = require('date-fns');
22

33
class Clock {
4+
#tickId = null;
5+
46
constructor(options = {}) {
57
const { onTick, locale, format } = options;
68

79
this.locale = locale.getObject();
810

911
this
1012
.setFormat(format)
11-
.onTick();
12-
13-
if (typeof onTick === 'function') {
14-
setInterval(() => onTick(this.onTick()), 1000);
15-
onTick(this.onTick());
16-
}
13+
.onTick(onTick);
1714
}
1815

1916
getFormat() {
@@ -31,10 +28,14 @@ class Clock {
3128
return this;
3229
}
3330

34-
onTick() {
31+
onTick(fn) {
3532
this.now = new Date();
3633

37-
return this;
34+
fn(this);
35+
36+
if (this.#tickId === null) {
37+
this.#tickId = setInterval(() => this.onTick(fn), 1000);
38+
}
3839
}
3940

4041
toString() {

app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const defaultPreferences = {
127127

128128
onTick(clock) {
129129
this.tray.setLabel(clock.toString());
130-
this.calendar?.window.getWebContents().send(APP_TICK);
130+
this.calendar?.window.getWebContents().send(APP_TICK, clock.now);
131131
}
132132

133133
onTranslate(event, key, options = {}) {

0 commit comments

Comments
 (0)