loginManager: Make API promise-based

The LoginManager abstraction is still mostly callback-based, not
least because the methods are thin wrappers around logind D-Bus
calls.

However as gjs' dbus wrapper now generates promised-based wrappers
as well, we can implement a proper async API just as naturally.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2344>
This commit is contained in:
Florian Müllner
2022-06-23 15:45:44 +02:00
committed by Marge Bot
parent db3916434e
commit a3db909383
5 changed files with 127 additions and 126 deletions

View File

@ -106,15 +106,7 @@ var ScreenShield = class extends Signals.EventEmitter {
this._prepareForSleep.bind(this));
this._loginSession = null;
this._loginManager.getCurrentSessionProxy(sessionProxy => {
this._loginSession = sessionProxy;
this._loginSession.connectSignal('Lock',
() => this.lock(false));
this._loginSession.connectSignal('Unlock',
() => this.deactivate(false));
this._loginSession.connect('g-properties-changed', this._syncInhibitor.bind(this));
this._syncInhibitor();
});
this._getLoginSession();
this._settings = new Gio.Settings({ schema_id: SCREENSAVER_SCHEMA });
this._settings.connect(`changed::${LOCK_ENABLED_KEY}`, this._syncInhibitor.bind(this));
@ -152,6 +144,17 @@ var ScreenShield = class extends Signals.EventEmitter {
this._syncInhibitor();
}
async _getLoginSession() {
this._loginSession = await this._loginManager.getCurrentSessionProxy();
this._loginSession.connectSignal('Lock',
() => this.lock(false));
this._loginSession.connectSignal('Unlock',
() => this.deactivate(false));
this._loginSession.connect('g-properties-changed',
() => this._syncInhibitor());
this._syncInhibitor();
}
_setActive(active) {
let prevIsActive = this._isActive;
this._isActive = active;