timeLimitsManager: Delete the history file if history is disabled

I forgot to include this in the first implementation, but it was always
meant to be here: when screen time data collection is disabled, the
history file should be deleted — it’s not being added to, and is just a
privacy risk.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/3306
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3610>
This commit is contained in:
Philip Withnall 2025-01-24 12:09:03 +00:00 committed by Marge Bot
parent 11d8b9337d
commit 98758c86d8

View File

@ -281,6 +281,7 @@ export const TimeLimitsManager = GObject.registerClass({
this._lastStateChangeTimeSecs = 0;
this.notify('state');
if (this._screenTimeLimitSettings.get_boolean('history-enabled')) {
// Add a fake transition to show the shutdown.
if (this._userState !== UserState.INACTIVE) {
const nowSecs = this.getCurrentTime();
@ -292,6 +293,13 @@ export const TimeLimitsManager = GObject.registerClass({
} 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.
this._cancellable?.cancel();
@ -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.