fixup! breakManager: Add new state machine for screen time/health breaks

This commit is contained in:
Philip Withnall 2024-06-07 16:09:28 +01:00
parent 80719358e5
commit d4e57d3e20

View file

@ -740,19 +740,23 @@ class BreakDispatcher extends GObject.Object {
const [nextBreakType, nextBreakDueTime] = this._manager.getNextBreakDue(currentTime);
if (this._manager.breakTypeShouldCountdown(nextBreakType)) {
const countdownStart = Math.max((nextBreakDueTime - currentTime) - BREAK_COUNTDOWN_TIME_SECONDS, 0);
const dueInSeconds = nextBreakDueTime - currentTime;
const countdownStart = Math.max(dueInSeconds - BREAK_COUNTDOWN_TIME_SECONDS, 0);
console.debug(`BreakDispatcher: Scheduling break countdown to start in ${countdownStart}s`);
if (this._countdownTimerId !== 0)
GLib.source_remove(this._countdownTimerId);
this._countdownTimerId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, countdownStart, () => {
if (this._countdownOsd == null) {
this._countdownOsd = new OsdBreakCountdownLabel(this._manager);
this._countdownOsd.connect('destroy', () => (this._countdownOsd = null));
}
this._countdownTimerId = 0;
return GLib.SOURCE_REMOVE;
});
this._countdownTimerId = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
countdownStart, () => {
if (this._countdownOsd == null) {
this._countdownOsd = new OsdBreakCountdownLabel(this._manager);
this._countdownOsd.connect('destroy',
() => (this._countdownOsd = null));
}
this._countdownTimerId = 0;
return GLib.SOURCE_REMOVE;
});
}
break;