209 Commits

Author SHA1 Message Date
Philip Withnall
f8024a5447 timeLimitsManager: Hold inhibitor for sleep to allow saving screen time data
This avoids the race between systemd emitting the `prepare-for-sleep`
signal, gnome-shell then starting to write the screen time data to disk,
and systemd suspending the hardware.

The race isn’t so much of an issue if the suspend succeeds (if
gnome-shell loses, the data will still get written out when the machine
resumes), but it’s slightly problematic if the machine loses power while
suspended, as that means the latest screen time data is lost.

Includes significant suggestions from Florian Müllner.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3643>
2025-03-03 15:15:25 +00:00
Philip Withnall
6a43b6f551 timeLimitsManager: Store screen time state on suspend/resume
There are two main changes in this commit:
 * Listen to the `prepare-for-sleep` signal from `LoginManager`, which
   is emitted just before suspending and just after resuming. When the
   signal is received, update the user’s screen time state (active or
   inactive), add a transition if necessary, and save the screen time
   history if necessary.
 * Factor the `preparingForSleep` property of `LoginManager` into the
   user’s screen time state, meaning that the user will be considered
   inactive between the system going for suspend and coming back from
   resume.

The rest of the changes in the commit are boilerplate to allow for this
functionality to be unit tested.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/8185
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3643>
2025-03-03 15:15:24 +00:00
Philip Withnall
e9eb7e3de6 tests: Add tests for disabling history/limits for screen time
Test that disabling the history and/or screen time limits work. This
adds unit tests for the previous few commits.

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>
2025-01-28 16:19:21 +00:00
Philip Withnall
11d8b9337d timeLimitsManager: Fully handle daily-limit-enabled setting
Separate out how it’s handled from the `history-enabled` setting,
allowing screen time usage data to be recorded with or without limits
being enforced.

This follows on from the previous commit.

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>
2025-01-28 16:19:21 +00:00
Philip Withnall
73565e582c timeLimitsManager: Simple split of enabled setting in two
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 <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>
2025-01-28 16:19:21 +00:00
Philip Withnall
bba85e1fcd tests: Factor out additional env vars mechanism
Make the mechanism more general, so that other tests can now specify
overrides for various defaults, if needed.

This replicates what GLib does:
https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/tests/meson.build#L475.

It introduces no functional changes in how the current set of tests run.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3605>
2025-01-21 14:32:44 +00:00
Philip Withnall
a3d4198c85 tests: Run timeLimitsManager tests in UTC
In order to keep the test code brief, all expected times and dates are
written as ISO 8601 strings in the test code, and use `Z` to specify UTC
(again, to keep things brief).

If the test is run under a significantly different timezone, the
end-of-day timestamp changes significantly, as it’s calculated by the
code-under-test using the local timezone.

Avoid that issue by requiring the `timeLimitsManager` tests to always be
run in UTC.

The previous failure could be reproduced by running `TZ=Europe/Madrid
meson test -C /opt/gnome/build/gnome-shell timeLimitsManager --verbose`
— the test for “tracks a single day’s usage early in the morning” would
fail.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3605>
2025-01-21 14:32:44 +00:00
Philip Withnall
c890a2f1e3 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>
2025-01-20 19:05:58 +00:00
Bilal Elmoussaoui
b3f5f9601b Go through global stage for getting ClutterBackend
Instead of using the default backend.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3528>
2025-01-20 11:50:29 +00:00
Philip Withnall
212e098da1 timeLimitsManager: Add new state machine for screen time limits
This implements wellbeing screen time limits in gnome-shell. It depends
on a few changes in other modules:
 - New settings schemas in gsettings-desktop-schemas
 - A settings UI in gnome-control-center
 - User documentation in gnome-user-docs

It implements the design from
https://gitlab.gnome.org/Teams/Design/settings-mockups/-/blob/master/wellbeing/wellbeing.png.

The core of the implementation is `TimeLimitsManager`, which is a state
machine which uses the user’s session state from logind to track how long
the user has been in an active session, in aggregate, during the day. If
this total exceeds their limit for the day, the state machine changes
state.

The user’s session activity history (basically, when they logged in and
out for the past 14 weeks) is kept in a state file in their home
directory. This is used by gnome-shell to count usage across reboots in
a single day, and in the future it will also be used to provide usage
history in gnome-control-center, so the user can visualise their
historic computer usage at a high level, for the past several weeks.

The `TimeLimitsDispatcher` is based on top of this, and controls showing
notifications and screen fades to make the user aware of whether they’ve
used the computer for too long today, as per their preferences.

Unit tests are included to check that `TimeLimitsManager` works, in
particular with its loading and storing of the history file. The unit
tests provide mock implementations of basic GLib clock functions, the
logind D-Bus proxy and `Gio.Settings` in order to test the state machine in
faster-than-real-time.

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

See: https://gitlab.gnome.org/Teams/Design/initiatives/-/issues/130
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3397>
2025-01-13 14:24:02 +00:00
Philip Withnall
df3b4d302d breakManager: Add new state machine for screen time/health breaks
This implements health break reminder support in gnome-shell. It depends
on a
few bits and bobs from other modules:
 - New settings schemas in gsettings-desktop-schemas (released in
   47.beta, which Mutter already depends on)
 - A settings UI in gnome-control-center
 - User documentation in gnome-user-docs

It implements the design from
https://gitlab.gnome.org/Teams/Design/settings-mockups/-/blob/master/wellbeing/wellbeing.png.

The core of the implementation is `BreakManager`, which is a state
machine which uses the Mutter `IdleMonitor` to track whether the user
is, or should be, in a screen time break.

The `BreakDispatcher` is based on top of this, and controls showing
notifications, countdown timers, screen fades, the lock shield, etc. to
make the user aware of upcoming or due breaks, as per their notification
preferences.

Unit tests are included to check that `BreakManager` works. These
provide mock implementations of basic GLib clock functions, the
`IdleMonitor` and `Gio.Settings` in order to test the state machine in
faster-than-real-time.

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

See: https://gitlab.gnome.org/Teams/Design/initiatives/-/issues/130
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3251>
2024-11-28 10:44:10 +00:00
Florian Müllner
c52ac4baa8 tests: Add extensionUtils unit test
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3379>
2024-10-16 16:16:08 +00:00
Bilal Elmoussaoui
aa0f2c4915 Use NULL for nick/blurb in GObject params
As they are only used by gstreamer for gst-inspect & other tools.
Projects like Mutter/gtk have completely dropped them as well, so follow
their path

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3505>
2024-10-16 10:19:41 +00:00
Jonas Ådahl
40fd7c01ec tests/dbus-runner: Pass along **kargs in setUpClass()
This means gnomeshell_dbusrunner.py only need to bother with arguments
it needs to care about, which currently are none.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3455>
2024-08-28 15:56:27 +02:00
Florian Müllner
105abab1e4 js: Remove modelines
We already include an .editorconfig that is supported by many
editors, including emacs, so no need to repeat an emacs-specific
modeline in every source file.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3431>
2024-07-30 18:20:55 +00:00
Jonas Ådahl
99a36210b6 tests/fittsy: Await leisure before checking fittsiness
Not until we've waited for leisure can we make precise assumptions about
otherwise animated actors sizes and positions, so do that before
checking fittsiness.

This should fix the flakyness of the fittsy test case.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3398>
2024-06-28 21:52:19 +00:00
Florian Müllner
cf1159e6c0 tests: Remove assertArraysEqual()
It is tied to the legacy jsUnit framework and now unused.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:29 +00:00
Florian Müllner
162c9f0056 tests: Port GNOMEversionCompare() test to jasmine
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
41aa44707a tests: Port findUrl() test to jasmine
Based on https://bugzilla.gnome.org/show_bug.cgi?id=783738
from Sam Spilsbury.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
8345047c24 tests: Port signalTracker test to jasmine
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
d4ecb0986b tests: Port Params.parse() test to jasmine
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
847b927367 tests: Port fixMarkup() test to jasmine
Based on https://bugzilla.gnome.org/show_bug.cgi?id=783738
from Sam Spilsbury.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
ab4ca87ee9 tests: Port jsParse test to jasmine
Based on https://bugzilla.gnome.org/show_bug.cgi?id=783738
from Sam Spilsbury.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
40750f5849 tests: Port insertSorted() test to jasmine
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
d62146bc19 tests: Port InjectionManager test to jasmine
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
9315d42dd6 tests: Port Highlighter test to jasmine
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
151e2faa0f build: Set up jasmine for unit testing
Jasmine[0] is a popular testing framework for javascript, which
gjs itself has used in a heavily customized form for its own
unit tests for years.

It's far superior to the very rudimentary `jsUnit` module that
is still included with gjs, and the jasmine-gjs project provides
a general-purpose wrapper for gjs apps.

Set up the necessary build infrastructure to run unit tests
through jasmine. That allows for existing unit tests to be
ported one-by-one.

[0] https://jasmine.github.io/index.html

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Florian Müllner
1fcdc60ca0 tests: Drop wrapper script for unit test runner
We build a small run-js-test executable so tests run in a
similar environment as gnome-shell, and then wrap it with
a generated script that provides environment variables like
GI_TYPELIB_PATH.

This is more complicated than it needs to be, we can just as
well set up the typelib search path from the runner and pass
in the environment via meson.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Sam Spilsbury
3d9c40783f util: Implement fixMarkup in util as opposed to messageList
We want to be able to import it in the markup unit test without
bringing in a UI dependency.

https://bugzilla.gnome.org/show_bug.cgi?id=783738

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>
2024-05-21 13:42:28 +00:00
Julian Sparber
d54219c098 messageTray: Only take params in Notification constructor
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>
2024-03-03 01:33:16 +00:00
Julian Sparber
34f05b075b messageTray: Let the tray decide whether to show a banner
Always use the same code path to add new messages to a source, and
let the `MessageTray` decide whether it shows a banner.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>
2024-03-03 01:33:16 +00:00
Bilal Elmoussaoui
8b6e1fe896 plugin: Stop overriding xevent_filter
The vfunc was used to register profiling hooks for glx.swapComplete
as we have sysprof nowadays and as that code path is x11 specific
anyways, let us drop it

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3201>
2024-02-20 13:51:30 +00:00
Julian Sparber
c1ff00c01b notification: Use the same Source for showing system notifications
This drops all subclasses of `MessageTray.Source` that were used to
display system notifications. Now the `Source` returned from
`MessageTray.getSystemSource()` is used.
Ensure also that properties and methods that where set on the `Source`
are moved to the `Notification` object itself.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3156>
2024-02-06 17:25:01 +00:00
Florian Müllner
79b0c9c726 util: Handle .rc in version comparisons
We somehow missed that the new version scheme include '.rc' when
adding the comparison function, whoops.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3130>
2024-01-26 13:20:07 +00:00
Florian Müllner
b02460fa63 tests: Fix check for global scope pollution
Since commit c570011 dropped the `with` statement, this bit of
the test has only checked for writes to a specific variable
in the file.

There is no direct replacement for `with` here, the best we can
do (I think) is comparing property names on the global objects
before and after the `eval()` call.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3132>
2024-01-26 13:12:40 +00:00
Robert Mader
5ab3177acd tests/build: Silence meson deprecation warning
This produced the following warning:
```
DEPRECATION: Project uses feature that was always broken, and is now
deprecated since '1.3.0': str.format: Value other than strings,
integers, bools, options, dictionaries and lists thereof..
```

The resulting value of `SHELL_BACKGROUND_IMAGE` was indeed bogus, not
containing a proper file path.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3123>
2024-01-18 14:25:36 +01:00
Florian Müllner
3099bfc571 tests: Add fittsy test
Both the dash and top bar items are expected to extend to the
screen edge, to make them easier click targets according to
Fitts' law.

This has the tendency to break fairly regularly, so add a small
test that checks the Fittsiness of the show-apps and activities
buttons to catch regressions.

Related: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7318
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3111>
2024-01-12 20:29:10 +00:00
Florian Müllner
9546860d05 tests/unit: Access shell sources from resource
Unit tests currently load shell sources directly from the
filesystem.

This is currently blocking generated sources - namely config.js - to
ESM, because a relative import from the source dir will fail to
locate the file in the build dir.

Address this by using the same GResource as gnome-shell instead of
direct filesystem access, as the resource will always include all
sources files at the expected location.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2880>
2023-08-10 17:42:23 +00:00
Evan Welsh
a751e213f6 js: Port to modules
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1499>
2023-08-06 13:02:49 +02:00
Florian Müllner
a332771562 injectionManager: Support overriding vfuncs
Overriding vfuncs can be useful, in particular when we convert
to ES modules, and exported symbols cannot easily be swapped out.

Adapt overrideMethod() to work correctly in that case as well.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2809>
2023-08-05 12:35:30 +02:00
Florian Müllner
f70a75a905 extensionUtils: Add InjectionManager
It is fairly common for extensions to monkey-patch existing
classes. Add a small helper class that makes this a tad bit
more convenient.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2809>
2023-08-05 12:34:41 +02:00
Evan Welsh
3f12f3a87c scripting: Convert to ES module and migrate tests
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
2023-07-15 02:35:56 +00:00
Evan Welsh
9a2c3da868 environment: Port environment.js to be an ES module
Removes the init() function in favor of executing all environment
changes when the file is imported.

Additionally ports all unit tests using imports.gi.environment.init() to
use the updated module.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
2023-07-15 02:35:56 +00:00
Evan Welsh
26fa1046a3 tests: Load unit tests as modules
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
2023-07-15 02:35:56 +00:00
Evan Welsh
c570011376 tests/unit: Fix remaining ESLint errors
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
2023-07-15 02:35:56 +00:00
Florian Müllner
26e018206d tests/shell: Fix remaining ESlint errors
All tests are currently excluded from linting, so errors can sneak
in more easily.

We should change that, so quickly fix up any remaining errors.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
2023-07-15 02:35:56 +00:00
Evan Welsh
9e84891240 insertSorted: Refactor comparator functions to be arrow functions
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
2023-07-15 02:35:56 +00:00
Evan Welsh
df8fb2899d tests: Move assertArrayEquals to shared assertions file
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
2023-07-15 02:35:56 +00:00
Florian Müllner
476bf23041 tests: Use different suites
This makes it easier to only run unit- or automation tests.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2845>
2023-07-14 00:56:26 +02:00
Florian Müllner
b0384bee99 tests/shell: Also import built-in modules as modules
The "System" module is provided by gjs itself, and also available
as module.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2836>
2023-07-11 16:44:11 +02:00