timeLimitsManager: Reset screen time if daily limit is changed
If the limit for the day had already been reached, the `timeLimitsManager` was not resetting the screen time state if the daily limit setting was then changed (and increased). Fix that, and add a unit test for it. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/8164 Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3603>
This commit is contained in:
parent
1471733dfd
commit
c890a2f1e3
@ -666,6 +666,8 @@ export const TimeLimitsManager = GObject.registerClass({
|
|||||||
// Schedule an update for when the limit will be reset again.
|
// Schedule an update for when the limit will be reset again.
|
||||||
this._scheduleUpdateState(startOfTomorrowSecs - nowSecs);
|
this._scheduleUpdateState(startOfTomorrowSecs - nowSecs);
|
||||||
} else if (this._userState === UserState.ACTIVE) {
|
} else if (this._userState === UserState.ACTIVE) {
|
||||||
|
newState = TimeLimitsState.ACTIVE;
|
||||||
|
|
||||||
// Schedule an update for when we expect the limit will be reached.
|
// Schedule an update for when we expect the limit will be reached.
|
||||||
this._scheduleUpdateState(dailyLimitSecs - activeTimeTodaySecs);
|
this._scheduleUpdateState(dailyLimitSecs - activeTimeTodaySecs);
|
||||||
} else {
|
} else {
|
||||||
|
@ -720,6 +720,42 @@ describe('Time limits manager', () => {
|
|||||||
harness.run();
|
harness.run();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('resets usage if the time limit is changed', () => {
|
||||||
|
const harness = new TestHarness({
|
||||||
|
'org.gnome.desktop.screen-time-limits': {
|
||||||
|
'enabled': true,
|
||||||
|
'daily-limit-seconds': 4 * 60 * 60,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
harness.initializeMockClock('2024-06-01T10:00:00Z');
|
||||||
|
const timeLimitsManager = new TimeLimitsManager.TimeLimitsManager(harness.mockHistoryFile, harness.mockClock, harness.mockLoginUserFactory, harness.mockSettingsFactory);
|
||||||
|
|
||||||
|
// Run until the limit is reached.
|
||||||
|
harness.expectState('2024-06-01T10:00:01Z', timeLimitsManager, TimeLimitsState.ACTIVE);
|
||||||
|
harness.expectProperties('2024-06-01T15:00:00Z', timeLimitsManager, {
|
||||||
|
'state': TimeLimitsState.LIMIT_REACHED,
|
||||||
|
'dailyLimitTime': TestHarness.timeStrToSecs('2024-06-01T14:00:00Z'),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Increase the limit.
|
||||||
|
harness.addSettingsChangeEvent('2024-06-01T15:10:00Z',
|
||||||
|
'org.gnome.desktop.screen-time-limits', 'daily-limit-seconds', 8 * 60 * 60);
|
||||||
|
harness.expectProperties('2024-06-01T15:10:01Z', timeLimitsManager, {
|
||||||
|
'state': TimeLimitsState.ACTIVE,
|
||||||
|
'dailyLimitTime': TestHarness.timeStrToSecs('2024-06-01T18:00:00Z'),
|
||||||
|
});
|
||||||
|
|
||||||
|
// The new limit should be reached eventually
|
||||||
|
harness.expectProperties('2024-06-01T18:00:01Z', timeLimitsManager, {
|
||||||
|
'state': TimeLimitsState.LIMIT_REACHED,
|
||||||
|
'dailyLimitTime': TestHarness.timeStrToSecs('2024-06-01T18:00:00Z'),
|
||||||
|
});
|
||||||
|
|
||||||
|
harness.shutdownManager('2024-06-01T18:10:00Z', timeLimitsManager);
|
||||||
|
|
||||||
|
harness.run();
|
||||||
|
});
|
||||||
|
|
||||||
it('tracks usage correctly from an existing history file', () => {
|
it('tracks usage correctly from an existing history file', () => {
|
||||||
const harness = new TestHarness({
|
const harness = new TestHarness({
|
||||||
'org.gnome.desktop.screen-time-limits': {
|
'org.gnome.desktop.screen-time-limits': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user