This repository was archived by the owner on Jul 24, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change 1
1
const datefns = require ( 'date-fns' ) ;
2
2
3
3
class Clock {
4
+ #tickId = null ;
5
+
4
6
constructor ( options = { } ) {
5
7
const { onTick, locale, format } = options ;
6
8
7
9
this . locale = locale . getObject ( ) ;
8
10
9
11
this
10
12
. setFormat ( format )
11
- . onTick ( ) ;
12
-
13
- if ( typeof onTick === 'function' ) {
14
- setInterval ( ( ) => onTick ( this . onTick ( ) ) , 1000 ) ;
15
- onTick ( this . onTick ( ) ) ;
16
- }
13
+ . onTick ( onTick ) ;
17
14
}
18
15
19
16
getFormat ( ) {
@@ -31,10 +28,14 @@ class Clock {
31
28
return this ;
32
29
}
33
30
34
- onTick ( ) {
31
+ onTick ( fn ) {
35
32
this . now = new Date ( ) ;
36
33
37
- return this ;
34
+ fn ( this ) ;
35
+
36
+ if ( this . #tickId === null ) {
37
+ this . #tickId = setInterval ( ( ) => this . onTick ( fn ) , 1000 ) ;
38
+ }
38
39
}
39
40
40
41
toString ( ) {
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ const defaultPreferences = {
127
127
128
128
onTick ( clock ) {
129
129
this . tray . setLabel ( clock . toString ( ) ) ;
130
- this . calendar ?. window . getWebContents ( ) . send ( APP_TICK ) ;
130
+ this . calendar ?. window . getWebContents ( ) . send ( APP_TICK , clock . now ) ;
131
131
}
132
132
133
133
onTranslate ( event , key , options = { } ) {
You can’t perform that action at this time.
0 commit comments