Skip to content

Commit b532136

Browse files
authored
Merge pull request #1597 from igor-semenov/fix-today-view-midnight-refresh
2 parents f5f2d51 + c115a52 commit b532136

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/Services/TimeMonitor.vala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ public class Services.TimeMonitor : Object {
3030
}
3131

3232
private DateTime last_registered_date;
33+
private uint timeout_id = 0;
3334

3435
public void init_timeout () {
3536
last_registered_date = new DateTime.now_local ();
36-
uint interval = calculate_seconds_until_midnight ();
37+
schedule_next_check ();
38+
}
3739

38-
Timeout.add_seconds (interval, on_timeout);
40+
private void schedule_next_check () {
41+
if (timeout_id != 0) {
42+
Source.remove (timeout_id);
43+
}
44+
45+
uint interval = calculate_seconds_until_midnight ();
46+
timeout_id = Timeout.add_seconds (interval, on_timeout);
3947
}
4048

4149
private bool on_timeout () {
@@ -49,14 +57,9 @@ public class Services.TimeMonitor : Object {
4957
Services.Notification.get_default ().regresh ();
5058

5159
last_registered_date = now;
52-
uint interval = calculate_seconds_until_midnight ();
53-
54-
Timeout.add_seconds (interval, on_timeout);
55-
} else {
56-
uint interval = calculate_seconds_until_midnight ();
57-
Timeout.add_seconds (interval, on_timeout);
5860
}
5961

62+
schedule_next_check ();
6063
return false;
6164
}
6265

0 commit comments

Comments
 (0)