Commit Graph

43 Commits

Author SHA1 Message Date
Evan Welsh
a88e59c1a8 Adopt EventEmitter class instead of injecting Signal methods
Introduce a new class, EventEmitter, which implements signal
handling for pure JavaScript classes. EventEmitter still
utilizes GJS' addSignalMethods internally.

EventEmitter allows static typechecking to understand the
structure of event-emitting JS classes and makes creating
child classes simpler.

The name 'EventEmitter' mirrors a common name for this pattern
in Node and in JS libraries.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2043>
2022-07-04 18:30:49 -04:00
Sebastian Keller
5791e257e7 screenShield: Asyncify _syncInhibitor()
Fixes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4553
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1952>
2021-08-16 02:44:36 +02:00
Hans de Goede
2af7264cff LoginManager: Add canRebootToBootLoaderMenu and setRebootToBootLoaderMenu methods
Add wrappers for the new logind Manager CanRebootToBootLoaderMenu and
SetRebootToBootLoaderMenu dbus methods.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/199
2020-08-06 15:14:42 +02:00
Florian Müllner
764527c8c9 js: Promisify async operations
Promises make asynchronous operations easier to manage, in particular
when used through the async/await syntax that allows for asynchronous
code to closely resemble synchronous one.

gjs has included a Gio._promisify() helper for a while now, which
monkey-patches methods that follow GIO's async pattern to return a
Promise when called without a callback argument.

Use that to get rid of all those GAsyncReadyCallbacks!

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1126
2020-03-31 05:43:40 +00:00
Florian Müllner
61210fdae1 cleanup: Use JSDoc for documentation comments
It's a better fit than gtk-doc, and eslint can validate that they
are complete and use correct syntax.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
2019-11-11 19:25:14 +00:00
Florian Müllner
c860409da5 cleanup: Use object shorthand where possible
ES6 allows to omit property names where they match the name of the
assigned variable, which makes code less redunant and thus cleaner.
We will soon enforce that in our eslint rules, so make sure we use
the shorthand wherever possible.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
2019-11-11 19:25:14 +00:00
Florian Müllner
9eaa0089d0 cleanup: Fix missing/stray spaces
Those are wrong according to our style guidelines, but the previous
eslint ruleset didn't catch them.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
2019-11-11 19:25:14 +00:00
Florian Müllner
682bd7e97c cleanup: Don't shadow variables
Having variables that share the same name in overlapping scopes is
confusing and error-prone, and is best avoided.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
2019-11-11 19:25:14 +00:00
Florian Müllner
e357559582 cleanup: Mark globals used from other modules as exported
eslint cannot figure out that those symbols are used from other modules
via imports, so they trigger unused-variable errors. To fix, explicitly
mark those symbols as exported.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/627
2019-07-24 00:28:45 +02:00
Florian Müllner
71759a0769 cleanup: Mark unused (but useful) variables as ignored
While we aren't using those destructured variables, they are still useful
to document the meaning of those elements. We don't want eslint to keep
warning about them though, so mark them accordingly.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/627
2019-07-24 00:28:45 +02:00
Florian Müllner
2f97a1a55d cleanup: Mark unused arguments as unused
This will stop eslint from warning about them, while keeping their
self-documenting benefit.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/627
2019-07-24 00:28:45 +02:00
Florian Müllner
f250643385 style: Use space after catch
We are currently inconsistent with whether or not to put a space
after catch clauses. While the predominant style is to omit it,
that's inconsistent with the style we use for any other statement.
There's not really a good reason to stick with it, so switch to
the style gjs/eslint default to.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/607
2019-07-01 23:44:11 +02:00
Iain Lane
0e37cd2ec9
main, LoginManager: Call GDM's RegisterSession()
So that it can know if we started up properly and use that to (e.g.)
kill its greeter.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/570
2019-06-18 09:21:58 +01:00
Florian Müllner
fd50b9a45e cleanup: Use destructuring for imports from GI
This is *much* nicer than repetitive "imports.gi" lines ...

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/399
2019-02-09 07:39:20 +01:00
Florian Müllner
a1534dab02 cleanup: Clean up unused imports
Spotted by eslint.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/399
2019-02-09 05:05:07 +01:00
Florian Müllner
bacfdbbb03 cleanup: Port non-GObject classes to JS6 classes
ES6 finally adds standard class syntax to the language, so we can
replace our custom Lang.Class framework with the new syntax. Any
classes that inherit from GObject will need special treatment,
so limit the port to regular javascript classes for now.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
2019-01-25 14:02:44 +00:00
Florian Müllner
94423151b2 dbus: Move all interface descriptions into the resource
https://gitlab.gnome.org/GNOME/gnome-shell/issues/537
2018-09-17 07:34:49 +00:00
Marco Trevisan (Treviño)
dbf993300a js: use ES6 template strings for dbus interfaces
Use multiline template strings for dbus interfaces as they're easier to maintain
2018-08-27 19:23:00 +02:00
Iain Lane
22392d1328 loginManager: Get the session ID from logind if XDG_SESSION_ID unset
If we're started by systemd, we won't be in the user's display session.
However, this is still the session that will get locked & unlocked. Ask
logind what the 'display' or 'greeter' session is, and watch for the
Unlock signal for that session to know when to unlock.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/137
2018-07-17 17:44:18 +02:00
Florian Müllner
3b1330880f cleanup: Use Function.prototype.bind()
When not using arrow notation with anonymous functions, we use Lang.bind()
to bind `this` to named callbacks. However since ES5, this functionality
is already provided by Function.prototype.bind() - in fact, Lang.bind()
itself uses it when no extra arguments are specified. Just use the built-in
function directly where possible, and use arrow notation in the few places
where we pass additional arguments.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/23
2018-02-21 13:55:02 +00:00
Florian Müllner
213e38c2ef cleanup: Use arrow notation for anonymous functions
Arrow notation is great, use it consistently through-out the code base
to bind `this` to anonymous functions, replacing the more overbose
Lang.bind(this, function() {}).

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/23
2018-02-21 13:55:00 +00:00
Florian Müllner
76f09b1e49 cleanup: Use method syntax
Modern javascript has a short-hand for function properties, embrace
it for better readability and to prepare for an eventual port to
ES6 classes.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/23
2018-02-21 13:54:58 +00:00
Florian Müllner
de4c0bdca6 loginManager: Handle unset XDG_SESSION_ID more gracefully
While certain functionality won't be available when running outside a
(logind) user session, that's still better than crashing ...

https://bugzilla.gnome.org/show_bug.cgi?id=788046
2017-09-22 18:46:01 +02:00
Florian Müllner
2582d16ca7 Define classes with 'var' instead of 'const'
Any symbols (including class properties) that should be visible
outside the module it's defined in need to be defined as global.
For now gjs still allows the access for 'const', but get rid of
the warnings spill now by changing it.

https://bugzilla.gnome.org/show_bug.cgi?id=785084
2017-07-18 21:52:06 +02:00
Florian Müllner
1cb644529f loginManager: Extend canSuspend() callback
The underlying logind API does not only indicate whether suspend is
available, but also whether the user is eligible for executing the
operation without further authentication. This information can be
relevant, so pass it to the callback.

https://bugzilla.gnome.org/show_bug.cgi?id=725960
2016-05-27 17:04:46 +02:00
Victor Toso
ddea54a539 ScreenShield: set LockedHint property from systemd
Logind recently got support for a hint property in Session Object to
inform if session is Locked or not. It is up to desktop environments
to keep this property up to date.

https://bugzilla.gnome.org/show_bug.cgi?id=764773
2016-05-12 15:24:06 +02:00
Mario Sanchez Prada
be78f0f36a misc: Add missing check on reply from systemd's CanSuspend D-Bus method
According to systemd logind's documentation, the CanSuspend() method
"returns 'na' in case "the operation is not available because hardware,
kernel or drivers do not support it", while "'no' is returned if the
operation is available but the user is not allowed to execute it".

See http://www.freedesktop.org/wiki/Software/systemd/logind

Thus, we need to return true here when the reply for the CanSuspend
method is neither 'no' nor 'na', or we would providing false positives
in cases where suspension is simply unsupported.

https://bugzilla.gnome.org/show_bug.cgi?id=748338
2015-04-22 23:17:45 +01:00
Florian Müllner
a244c1e987 loginManager: Kill ConsoleKit support
The code path is completely unmaintained and untested (and probably
unused as well, considering that nobody has complained about accessing
the session object's Active property which does not exist in the
ConsoleKit case).
Most of our ConsoleKit code is already a dummy anyway, just do the
same for the remaining functionality.

https://bugzilla.gnome.org/show_bug.cgi?id=686626
2014-04-25 15:53:45 +02:00
Jasper St. Pierre
70d75ca311 loginManager: Don't pass too many args to steal_fds 2014-04-15 17:53:37 -04:00
Jasper St. Pierre
be291ee4f9 loginScreen: reset greeter when coming back to login screen
When a user logs in to a wayland session, we keep the login screen
running on the X server with the login screen running in a deactivated mode.

This commit makes sure it get reactivated when the user comes back to
the VT (from user switching, logout or just ctrl-alt-f1).

https://bugzilla.gnome.org/show_bug.cgi?id=726989
2014-03-25 10:41:12 -04:00
Tim Lunn
b908a3d70a Stringify the xml definitions for E4X removal
https://bugzilla.gnome.org/show_bug.cgi?id=691409
2013-10-25 08:57:27 +11:00
Ray Strode
609a31ea46 loginManager: fix versionCompare function
It's important to compare the version components as integers,
not strings, so "10" evaulates as greater than "5"

This fixes the login screen in gnome 3.10.

https://bugzilla.gnome.org/show_bug.cgi?id=708691
2013-09-24 14:22:09 -04:00
Jasper St. Pierre
ce768241da loginManager: Remove login manager versions of PowerOff/Reboot
These don't go through gnome-session, so they don't properly update
its state machine. We should use these in the future when we want to
use logind user sessions, but for now, they're just a trap.

https://bugzilla.gnome.org/show_bug.cgi?id=706612
2013-08-22 16:40:52 -04:00
Martin Pitt
a7cd4657f5 loginManager.js: Check for logind, not for systemd
It is possible to build systemd without logind, in which case
/sys/fs/cgroup/systemd would still exist. Check for /run/systemd/seats instead,
as recommended by systemd upstream.

For details, see:
<https://mail.gnome.org/archives/desktop-devel-list/2013-March/msg00092.html>

https://bugzilla.gnome.org/show_bug.cgi?id=696252
2013-03-29 11:00:52 +01:00
Cosimo Cecchi
869e1dc241 loginManager: listen to the correct object path
Use GetSession() to get the valid object path for the current
XDG_SESSION_ID.

https://bugzilla.gnome.org/show_bug.cgi?id=696287
2013-03-25 20:53:13 -04:00
Florian Müllner
9a83662a18 loginManager: Move UnlockDialog.isSupported() here
With fallback mode dropped, we can no longer rely on gnome-screensaver
to be installed, so we'll have cases where we are unable to lock the
screen. The user menu should not show the "Lock" item in this case,
but as UnlockDialog includes UserMenu, we cannot use the existing check
without creating a circular dependency; move the function to a more
generic place to fix.

https://bugzilla.gnome.org/show_bug.cgi?id=693403
2013-03-06 16:22:07 +01:00
Adel Gadllah
b2fb84e361 Don't ask for a password on shutdown
Show a warning and the list of active users instead when
multiple sessions are present.

https://bugzilla.gnome.org/show_bug.cgi?id=693385
2013-02-11 19:39:00 +01:00
Florian Müllner
1bf996c705 loginManager: Fix canSuspend in non-logind path
It is supposed to be a NOP, but commit b91d9c2867 got it wrong.

https://bugzilla.gnome.org/show_bug.cgi?id=693162
2013-02-08 17:29:33 +01:00
Florian Müllner
8747c0c58d loginManager: Add inhibitor API
If screen locking is enabled, the screen shield should drop down
on suspend. Currently this is achieved by either explicitly locking
the screen (when selecting "Suspend" from the user menu) or by
relying on g-s-d delaying the suspension enough time for the shield
to get into place (lid close, power button).
Systemd inhibitors offer a safer way to ensure that the screen is
locked before going to sleep, so add a small abstraction for them
in the loginManager - with inhibitors being a systemd-only feature,
the ConsoleKit path only has a dummy implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=686482
2013-02-06 01:01:52 +01:00
Florian Müllner
b91d9c2867 loginManager: Make suspend() a NOP in the ConsoleKit path
UPower will remove its suspend support eventually, and g-s-d already
depends on logind for power management.

https://bugzilla.gnome.org/show_bug.cgi?id=693162
2013-02-06 01:01:52 +01:00
Florian Müllner
e0c5a61be5 loginManager: Remove sessionActive property
It is unused after switching to GnomeSession:SessionIsActive, so
remove it together with shell_session_is_active_for_systemd().

https://bugzilla.gnome.org/show_bug.cgi?id=693161
2013-02-05 00:01:33 +01:00
Florian Müllner
1f183b8a4e loginManager: Add support for suspend()
Logind provides a Suspend method, which we should use instead of
the UPower API when available. Expose this in loginManager, using
the UPower API for the ConsoleKit implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=686482
2012-10-23 21:14:10 +02:00
Giovanni Campagna
9a7914eee9 Consolidate systemd and consolekit in a common abstract class
Various code around had different paths for ConsoleKit and
logind. Consolidate it by making an abstract class that all
callers can use, which hides the implementation details of the
two daemons.

https://bugzilla.gnome.org/show_bug.cgi?id=682096
2012-08-18 18:09:55 +02:00