unlockDialog: Use inheritance instead of composition

The screen shield creates the unlock dialog based on the session mode.

However since commit 0c0d76f7d6 turned LoginDialog into an actor
subclass (while UnlockDialog kept using the delegate pattern), it is
no longer possible to handle both objects the same way without warnings.

Allow this again by turning UnlockDialog into an actor subclass as well.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/736
This commit is contained in:
Florian Müllner 2019-09-20 13:17:40 +02:00 committed by Georges Basile Stavracas Neto
parent 7b45ffa511
commit 856c32db91

View File

@ -2,8 +2,7 @@
/* exported UnlockDialog */
const { AccountsService, Atk, Clutter,
Gdm, Gio, GLib, Meta, Shell, St } = imports.gi;
const Signals = imports.signals;
Gdm, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
const Layout = imports.ui.layout;
const Main = imports.ui.main;
@ -13,15 +12,19 @@ const AuthPrompt = imports.gdm.authPrompt;
// The timeout before going back automatically to the lock screen (in seconds)
const IDLE_TIMEOUT = 2 * 60;
var UnlockDialog = class {
constructor(parentActor) {
this.actor = new St.Widget({ accessible_role: Atk.Role.WINDOW,
style_class: 'login-dialog',
layout_manager: new Clutter.BoxLayout(),
visible: false });
var UnlockDialog = GObject.registerClass({
Signals: { 'failed': {} },
}, class UnlockDialog extends St.Widget {
_init(parentActor) {
super._init({
accessible_role: Atk.Role.WINDOW,
style_class: 'login-dialog',
layout_manager: new Clutter.BoxLayout(),
visible: false,
});
this.actor.add_constraint(new Layout.MonitorConstraint({ primary: true }));
parentActor.add_child(this.actor);
this.add_constraint(new Layout.MonitorConstraint({ primary: true }));
parentActor.add_child(this);
this._userManager = AccountsService.UserManager.get_default();
this._userName = GLib.get_user_name();
@ -32,7 +35,7 @@ var UnlockDialog = class {
y_align: Clutter.ActorAlign.CENTER,
x_expand: true,
y_expand: true });
this.actor.add_child(this._promptBox);
this.add_child(this._promptBox);
this._authPrompt = new AuthPrompt.AuthPrompt(new Gdm.Client(), AuthPrompt.AuthPromptMode.UNLOCK_ONLY);
this._authPrompt.connect('failed', this._fail.bind(this));
@ -64,10 +67,12 @@ var UnlockDialog = class {
this._authPrompt.reset();
this._updateSensitivity(true);
Main.ctrlAltTabManager.addGroup(this.actor, _("Unlock Window"), 'dialog-password-symbolic');
Main.ctrlAltTabManager.addGroup(this, _("Unlock Window"), 'dialog-password-symbolic');
this._idleMonitor = Meta.IdleMonitor.get_core();
this._idleWatchId = this._idleMonitor.add_idle_watch(IDLE_TIMEOUT * 1000, this._escape.bind(this));
this.connect('destroy', this._onDestroy.bind(this));
}
_updateSensitivity(sensitive) {
@ -106,9 +111,8 @@ var UnlockDialog = class {
this._authPrompt.cancel();
}
destroy() {
_onDestroy() {
this.popModal();
this.actor.destroy();
if (this._idleWatchId) {
this._idleMonitor.remove_watch(this._idleWatchId);
@ -131,13 +135,16 @@ var UnlockDialog = class {
}
open(timestamp) {
this.actor.show();
this.show();
if (this._isModal)
return true;
if (!Main.pushModal(this.actor, { timestamp: timestamp,
actionMode: Shell.ActionMode.UNLOCK_SCREEN }))
let modalParams = {
timestamp,
actionMode: Shell.ActionMode.UNLOCK_SCREEN,
};
if (!Main.pushModal(this, modalParams))
return false;
this._isModal = true;
@ -147,9 +154,8 @@ var UnlockDialog = class {
popModal(timestamp) {
if (this._isModal) {
Main.popModal(this.actor, timestamp);
Main.popModal(this, timestamp);
this._isModal = false;
}
}
};
Signals.addSignalMethods(UnlockDialog.prototype);
});