Skip to content

Commit ba1c317

Browse files
authored
fix: infinite loop at midnight (#1858)
1 parent ce26827 commit ba1c317

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

  • prayertimes@linworx.org/files/prayertimes@linworx.org/5.8

prayertimes@linworx.org/files/prayertimes@linworx.org/5.8/desklet.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MuslimPrayerTimesDesklet extends Desklet.Desklet {
4141
this.settings.bind("desklet_size", "desklet_size", this.setupUI);
4242
this.settings.bind("color", "color", this.setupUI);
4343
this.settings.bind("show_city", "show_city", this.setupUI);
44-
this.settings.bind("show_countdown", "show_countdown", this.setupUI);
44+
this.settings.bind("show_countdown", "show_countdown", this.updateCountdown);
4545
this.settings.bind("show_table", "show_table", this.setupUI);
4646
this.settings.bind("show_date", "show_date", this.setupUI);
4747
this.settings.bindProperty(Settings.BindingDirection.BIDIRECTIONAL, "transparency", "transparency", this.setupUI);
@@ -60,6 +60,7 @@ class MuslimPrayerTimesDesklet extends Desklet.Desklet {
6060

6161
this.setupUI();
6262
this.getLocation();
63+
this.startUpdateTimer();
6364
}
6465

6566
async getLocation() {
@@ -93,7 +94,7 @@ class MuslimPrayerTimesDesklet extends Desklet.Desklet {
9394
this.calculatePrayerTimes();
9495
} catch (e) {
9596
this.logger.Log(`Could not get location: ${e.message}, retrying in 10 seconds`);
96-
this._retryId = Mainloop.timeout_add_seconds(10, Lang.bind(this, this.getLocation));
97+
this._retryId = Mainloop.timeout_add_seconds(10, () => this.getLocation());
9798
}
9899
this.logger.Log(`Got location: ${this.latitude}, ${this.longitude}`)
99100
}
@@ -149,14 +150,31 @@ class MuslimPrayerTimesDesklet extends Desklet.Desklet {
149150
}
150151

151152
this.setContent(window);
152-
this.refresh();
153153
}
154154

155155
get countdown() {
156156
if (!this.currentPrayer) return '--:--:--';
157157
return Utils.roundTime(this.prayerTimes[this.currentPrayer])
158158
}
159159

160+
updateCountdown() {
161+
// Update only the countdown timer without rebuilding entire UI
162+
if (!this.show_countdown) return;
163+
164+
const now = new Date().getDate();
165+
if (now != this.today) {
166+
this.calculatePrayerTimes();
167+
this.today = now;
168+
}
169+
}
170+
171+
startUpdateTimer() {
172+
if (typeof this._timeoutId !== 'undefined') {
173+
Mainloop.source_remove(this._timeoutId);
174+
}
175+
this._timeoutId = Mainloop.timeout_add_seconds(1, () => this.updateCountdown());
176+
}
177+
160178

161179
calculatePrayerTimes() {
162180
let method;
@@ -218,19 +236,7 @@ class MuslimPrayerTimesDesklet extends Desklet.Desklet {
218236
this.calculatePrayerTimes();
219237
}
220238

221-
222-
refresh() {
223-
this.on_desklet_removed();
224-
this._timeoutId = Mainloop.timeout_add_seconds(1, Lang.bind(this, this.setupUI));
225-
const today = new Date().getDate();
226-
if (today != this.today) {
227-
this.calculatePrayerTimes();
228-
this.today = today;
229-
}
230-
}
231-
232239
on_desklet_removed() {
233-
// this.logger.Log(`Cleaning up timers`)
234240
if (typeof this._timeoutId !== 'undefined') {
235241
Mainloop.source_remove(this._timeoutId);
236242
}

0 commit comments

Comments
 (0)