From 73565e582c01466a261f696f2cc1d1f5517b2579 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 23 Jan 2025 17:23:23 +0000 Subject: [PATCH] timeLimitsManager: Simple split of enabled setting in two MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As described and motivated in https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/3306, it turns out that we want to be able to save screen time usage data while not enabling limits based on that usage. Bump the shell’s dependency on gsettings-desktop-schemas to get the split setting, and roughly adapt the existing `timeLimitsManager` code to use the new setting names. The code currently treats the two settings as equivalent / expects them both to be set the same. The following commits will refine that behaviour. Signed-off-by: Philip Withnall Helps: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/3306 Part-of: --- .gitlab-ci.yml | 2 +- js/misc/timeLimitsManager.js | 2 +- meson.build | 2 +- tests/unit/timeLimitsManager.js | 47 +++++++++++++++++++++------------ 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 38b8f08aa..ff4d13ff2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,7 +44,7 @@ default: - 'api_failure' variables: - MUTTER_CI_IMAGE: registry.gitlab.gnome.org/gnome/mutter/fedora/41:x86_64-2025-01-15.0 + MUTTER_CI_IMAGE: registry.gitlab.gnome.org/gnome/mutter/fedora/41:x86_64-2025-01-28.0 FDO_UPSTREAM_REPO: GNOME/gnome-shell BUNDLE: "extensions-git.flatpak" LINT_LOG: "eslint-report.xml" diff --git a/js/misc/timeLimitsManager.js b/js/misc/timeLimitsManager.js index c86665ba6..9d6a5efdb 100644 --- a/js/misc/timeLimitsManager.js +++ b/js/misc/timeLimitsManager.js @@ -168,7 +168,7 @@ export const TimeLimitsManager = GObject.registerClass({ } _updateSettings() { - if (!this._screenTimeLimitSettings.get_boolean('enabled')) { + if (!this._screenTimeLimitSettings.get_boolean('history-enabled')) { if (this._state !== TimeLimitsState.DISABLED) { this._stopStateMachine().catch( e => console.warn(`Failed to stop state machine: ${e.message}`)); diff --git a/meson.build b/meson.build index 3e4c05de0..e7f39467d 100644 --- a/meson.build +++ b/meson.build @@ -27,7 +27,7 @@ gjs_req = '>= 1.73.1' gtk_req = '>= 4.0' mutter_req = '>= 48.alpha' polkit_req = '>= 0.100' -schemas_req = '>= 48.alpha' +schemas_req = '>= 48.alpha' # actually requires commit 9d55553, just after alpha systemd_req = '>= 246' gnome_desktop_req = '>= 40' pipewire_req = '>= 0.3.49' diff --git a/tests/unit/timeLimitsManager.js b/tests/unit/timeLimitsManager.js index 3c92518a4..c0615b0e2 100644 --- a/tests/unit/timeLimitsManager.js +++ b/tests/unit/timeLimitsManager.js @@ -585,7 +585,8 @@ describe('Time limits manager', () => { it('can be disabled via GSettings', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': false, + 'history-enabled': false, + 'daily-limit-enabled': false, 'daily-limit-seconds': 4 * 60 * 60, }, }); @@ -608,7 +609,8 @@ describe('Time limits manager', () => { it('can be toggled on and off via GSettings', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }); @@ -617,7 +619,7 @@ describe('Time limits manager', () => { harness.expectState('2024-06-01T10:00:01Z', timeLimitsManager, TimeLimitsState.ACTIVE); harness.addSettingsChangeEvent('2024-06-01T11:00:00Z', - 'org.gnome.desktop.screen-time-limits', 'enabled', false); + 'org.gnome.desktop.screen-time-limits', 'history-enabled', false); harness.expectProperties('2024-06-01T11:00:01Z', timeLimitsManager, { 'state': TimeLimitsState.DISABLED, 'dailyLimitTime': 0, @@ -626,13 +628,13 @@ describe('Time limits manager', () => { // Test that toggling it on and off fast is handled OK for (var i = 0; i < 3; i++) { harness.addSettingsChangeEvent('2024-06-01T11:00:02Z', - 'org.gnome.desktop.screen-time-limits', 'enabled', true); + 'org.gnome.desktop.screen-time-limits', 'history-enabled', true); harness.addSettingsChangeEvent('2024-06-01T11:00:02Z', - 'org.gnome.desktop.screen-time-limits', 'enabled', false); + 'org.gnome.desktop.screen-time-limits', 'history-enabled', false); } harness.addSettingsChangeEvent('2024-06-01T11:00:03Z', - 'org.gnome.desktop.screen-time-limits', 'enabled', true); + 'org.gnome.desktop.screen-time-limits', 'history-enabled', true); harness.expectState('2024-06-01T11:00:04Z', timeLimitsManager, TimeLimitsState.ACTIVE); harness.shutdownManager('2024-06-01T15:10:00Z', timeLimitsManager); @@ -642,7 +644,8 @@ describe('Time limits manager', () => { it('tracks a single day’s usage', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }); @@ -663,7 +666,8 @@ describe('Time limits manager', () => { it('tracks a single day’s usage early in the morning', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 1 * 60 * 60, }, }); @@ -684,7 +688,8 @@ describe('Time limits manager', () => { it('resets usage at the end of the day', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }); @@ -723,7 +728,8 @@ describe('Time limits manager', () => { it('resets usage if the time limit is changed', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }); @@ -759,7 +765,8 @@ describe('Time limits manager', () => { it('tracks usage correctly from an existing history file', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }, JSON.stringify([ @@ -804,7 +811,8 @@ describe('Time limits manager', () => { it('immediately limits usage from an existing history file', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }, JSON.stringify([ @@ -853,7 +861,8 @@ describe('Time limits manager', () => { it(`ignores invalid history file syntax (test case ${idx + 1})`, () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }, invalidHistoryFileContents); @@ -875,7 +884,8 @@ describe('Time limits manager', () => { it('expires old entries from an existing history file', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }, JSON.stringify([ @@ -951,7 +961,8 @@ describe('Time limits manager', () => { it('expires future entries from an existing history file', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }, JSON.stringify([ @@ -985,7 +996,8 @@ describe('Time limits manager', () => { it('doesn’t count usage across time change events forwards', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, }); @@ -1021,7 +1033,8 @@ describe('Time limits manager', () => { it('doesn’t count usage across time change events backwards', () => { const harness = new TestHarness({ 'org.gnome.desktop.screen-time-limits': { - 'enabled': true, + 'history-enabled': true, + 'daily-limit-enabled': true, 'daily-limit-seconds': 4 * 60 * 60, }, });