diff --git a/js/misc/timeLimitsManager.js b/js/misc/timeLimitsManager.js index 60919a448..f8c882c86 100644 --- a/js/misc/timeLimitsManager.js +++ b/js/misc/timeLimitsManager.js @@ -281,16 +281,24 @@ export const TimeLimitsManager = GObject.registerClass({ this._lastStateChangeTimeSecs = 0; this.notify('state'); - // Add a fake transition to show the shutdown. - if (this._userState !== UserState.INACTIVE) { - const nowSecs = this.getCurrentTime(); - this._addTransition(UserState.ACTIVE, UserState.INACTIVE, nowSecs); - } + if (this._screenTimeLimitSettings.get_boolean('history-enabled')) { + // Add a fake transition to show the shutdown. + if (this._userState !== UserState.INACTIVE) { + const nowSecs = this.getCurrentTime(); + this._addTransition(UserState.ACTIVE, UserState.INACTIVE, nowSecs); + } - try { - await this._storeTransitions(); - } catch (e) { - console.warn(`Failed to store screen time limits data: ${e.message}`); + try { + await this._storeTransitions(); + } catch (e) { + console.warn(`Failed to store screen time limits data: ${e.message}`); + } + } else { + try { + await this._deleteTransitions(); + } catch (e) { + console.warn(`Failed to delete screen time limits data: ${e.message}`); + } } // Make sure no async operations are still pending. @@ -531,6 +539,19 @@ export const TimeLimitsManager = GObject.registerClass({ } } + async _deleteTransitions() { + const file = this._historyFile; + + console.debug(`TimeLimitsManager: Deleting screen time limits data in ‘${file.peek_path()}’`); + + try { + await file.delete(this._cancellable); + } catch (e) { + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND)) + throw e; + } + } + /** * Get the Unix timestamp (in real seconds since the epoch) for the start of * today and the start of tomorrow.