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,16 +281,24 @@ export const TimeLimitsManager = GObject.registerClass({
this._lastStateChangeTimeSecs = 0; this._lastStateChangeTimeSecs = 0;
this.notify('state'); this.notify('state');
// Add a fake transition to show the shutdown. if (this._screenTimeLimitSettings.get_boolean('history-enabled')) {
if (this._userState !== UserState.INACTIVE) { // Add a fake transition to show the shutdown.
const nowSecs = this.getCurrentTime(); if (this._userState !== UserState.INACTIVE) {
this._addTransition(UserState.ACTIVE, UserState.INACTIVE, nowSecs); const nowSecs = this.getCurrentTime();
} this._addTransition(UserState.ACTIVE, UserState.INACTIVE, nowSecs);
}
try { try {
await this._storeTransitions(); await this._storeTransitions();
} catch (e) { } catch (e) {
console.warn(`Failed to store screen time limits data: ${e.message}`); 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. // 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 * Get the Unix timestamp (in real seconds since the epoch) for the start of
* today and the start of tomorrow. * today and the start of tomorrow.