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>
This commit is contained in:
Sebastian Keller
2021-08-15 02:18:12 +02:00
parent 85075192f3
commit 5791e257e7
2 changed files with 23 additions and 31 deletions

View File

@ -203,7 +203,7 @@ var ScreenShield = class {
return this._isModal;
}
_syncInhibitor() {
async _syncInhibitor() {
const lockEnabled = this._settings.get_boolean(LOCK_ENABLED_KEY);
const lockLocked = this._lockSettings.get_boolean(DISABLE_LOCK_KEY);
const inhibit = !!this._loginSession && this._loginSession.Active &&
@ -215,22 +215,18 @@ var ScreenShield = class {
this._inhibited = inhibit;
if (inhibit) {
this._loginManager.inhibit(_('GNOME needs to lock the screen'),
inhibitor => {
if (inhibitor) {
if (this._inhibitor)
inhibitor.close(null);
else
this._inhibitor = inhibitor;
}
this._inhibitCancellable?.cancel();
this._inhibitCancellable = new Gio.Cancellable();
// Handle uninhibits that happened after the start
if (!this._inhibited) {
this._inhibitor?.close(null);
this._inhibitor = null;
}
});
if (inhibit) {
try {
this._inhibitor = await this._loginManager.inhibit(
_('GNOME needs to lock the screen'),
this._inhibitCancellable);
} catch (e) {
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
log('Failed to inhibit suspend: %s'.format(e.message));
}
} else {
this._inhibitor?.close(null);
this._inhibitor = null;