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
This commit is contained in:
Florian Müllner
2017-10-31 02:19:44 +01:00
committed by Georges Basile Stavracas Neto
parent 99ce3deeb0
commit bacfdbbb03
102 changed files with 3454 additions and 4183 deletions

View File

@ -3,7 +3,6 @@
const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Signals = imports.signals;
const St = imports.gi.St;
@ -119,10 +118,8 @@ function cloneAndFadeOutActor(actor) {
return hold;
}
var ShellUserVerifier = new Lang.Class({
Name: 'ShellUserVerifier',
_init(client, params) {
var ShellUserVerifier = class {
constructor(client, params) {
params = Params.parse(params, { reauthenticationOnly: false });
this._reauthOnly = params.reauthenticationOnly;
@ -165,7 +162,7 @@ var ShellUserVerifier = new Lang.Class({
this._oVirtUserAuthenticatedId = this._oVirtCredentialsManager.connect('user-authenticated',
this._oVirtUserAuthenticated.bind(this));
},
}
begin(userName, hold) {
this._cancellable = new Gio.Cancellable();
@ -183,7 +180,7 @@ var ShellUserVerifier = new Lang.Class({
} else {
this._client.get_user_verifier(this._cancellable, this._userVerifierGot.bind(this));
}
},
}
cancel() {
if (this._cancellable)
@ -193,14 +190,14 @@ var ShellUserVerifier = new Lang.Class({
this._userVerifier.call_cancel_sync(null);
this.clear();
}
},
}
_clearUserVerifier() {
if (this._userVerifier) {
this._userVerifier.run_dispose();
this._userVerifier = null;
}
},
}
clear() {
if (this._cancellable) {
@ -210,7 +207,7 @@ var ShellUserVerifier = new Lang.Class({
this._clearUserVerifier();
this._clearMessageQueue();
},
}
destroy() {
this.clear();
@ -224,7 +221,7 @@ var ShellUserVerifier = new Lang.Class({
this._oVirtCredentialsManager.disconnect(this._oVirtUserAuthenticatedId);
this._oVirtCredentialsManager = null;
},
}
answerQuery(serviceName, answer) {
if (!this.hasPendingMessages) {
@ -235,12 +232,12 @@ var ShellUserVerifier = new Lang.Class({
this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null);
});
}
},
}
_getIntervalForMessage(message) {
// We probably could be smarter here
return message.length * USER_READ_TIME;
},
}
finishMessageQueue() {
if (!this.hasPendingMessages)
@ -250,7 +247,7 @@ var ShellUserVerifier = new Lang.Class({
this.hasPendingMessages = false;
this.emit('no-more-messages');
},
}
_queueMessageTimeout() {
if (this._messageQueue.length == 0) {
@ -273,7 +270,7 @@ var ShellUserVerifier = new Lang.Class({
return GLib.SOURCE_REMOVE;
});
GLib.Source.set_name_by_id(this._messageQueueTimeoutId, '[gnome-shell] this._queueMessageTimeout');
},
}
_queueMessage(message, messageType) {
let interval = this._getIntervalForMessage(message);
@ -281,7 +278,7 @@ var ShellUserVerifier = new Lang.Class({
this.hasPendingMessages = true;
this._messageQueue.push({ text: message, type: messageType, interval: interval });
this._queueMessageTimeout();
},
}
_clearMessageQueue() {
this.finishMessageQueue();
@ -291,7 +288,7 @@ var ShellUserVerifier = new Lang.Class({
this._messageQueueTimeoutId = 0;
}
this.emit('show-message', null, MessageType.NONE);
},
}
_checkForFingerprintReader() {
this._haveFingerprintReader = false;
@ -309,12 +306,12 @@ var ShellUserVerifier = new Lang.Class({
this._updateDefaultService();
}
});
},
}
_oVirtUserAuthenticated(token) {
this._preemptingService = OVIRT_SERVICE_NAME;
this.emit('ovirt-user-authenticated');
},
}
_checkForSmartcard() {
let smartcardDetected;
@ -336,7 +333,7 @@ var ShellUserVerifier = new Lang.Class({
this.emit('smartcard-status-changed');
}
},
}
_reportInitError(where, error) {
logError(error, where);
@ -344,7 +341,7 @@ var ShellUserVerifier = new Lang.Class({
this._queueMessage(_("Authentication error"), MessageType.ERROR);
this._verificationFailed(false);
},
}
_reauthenticationChannelOpened(client, result) {
try {
@ -371,7 +368,7 @@ var ShellUserVerifier = new Lang.Class({
this._connectSignals();
this._beginVerification();
this._hold.release();
},
}
_userVerifierGot(client, result) {
try {
@ -387,7 +384,7 @@ var ShellUserVerifier = new Lang.Class({
this._connectSignals();
this._beginVerification();
this._hold.release();
},
}
_connectSignals() {
this._userVerifier.connect('info', this._onInfo.bind(this));
@ -397,22 +394,22 @@ var ShellUserVerifier = new Lang.Class({
this._userVerifier.connect('conversation-stopped', this._onConversationStopped.bind(this));
this._userVerifier.connect('reset', this._onReset.bind(this));
this._userVerifier.connect('verification-complete', this._onVerificationComplete.bind(this));
},
}
_getForegroundService() {
if (this._preemptingService)
return this._preemptingService;
return this._defaultService;
},
}
serviceIsForeground(serviceName) {
return serviceName == this._getForegroundService();
},
}
serviceIsDefault(serviceName) {
return serviceName == this._defaultService;
},
}
_updateDefaultService() {
if (this._settings.get_boolean(PASSWORD_AUTHENTICATION_KEY))
@ -426,7 +423,7 @@ var ShellUserVerifier = new Lang.Class({
log("no authentication service is enabled, using password authentication");
this._defaultService = PASSWORD_SERVICE_NAME;
}
},
}
_startService(serviceName) {
this._hold.acquire();
@ -462,14 +459,14 @@ var ShellUserVerifier = new Lang.Class({
this._hold.release();
});
}
},
}
_beginVerification() {
this._startService(this._getForegroundService());
if (this._userName && this._haveFingerprintReader && !this.serviceIsForeground(FINGERPRINT_SERVICE_NAME))
this._startService(FINGERPRINT_SERVICE_NAME);
},
}
_onInfo(client, serviceName, info) {
if (this.serviceIsForeground(serviceName)) {
@ -484,21 +481,21 @@ var ShellUserVerifier = new Lang.Class({
// to indicate the user can swipe their finger instead
this._queueMessage(_("(or swipe finger)"), MessageType.HINT);
}
},
}
_onProblem(client, serviceName, problem) {
if (!this.serviceIsForeground(serviceName))
return;
this._queueMessage(problem, MessageType.ERROR);
},
}
_onInfoQuery(client, serviceName, question) {
if (!this.serviceIsForeground(serviceName))
return;
this.emit('ask-question', serviceName, question, '');
},
}
_onSecretInfoQuery(client, serviceName, secretQuestion) {
if (!this.serviceIsForeground(serviceName))
@ -511,7 +508,7 @@ var ShellUserVerifier = new Lang.Class({
}
this.emit('ask-question', serviceName, secretQuestion, '\u25cf');
},
}
_onReset() {
// Clear previous attempts to authenticate
@ -519,20 +516,20 @@ var ShellUserVerifier = new Lang.Class({
this._updateDefaultService();
this.emit('reset');
},
}
_onVerificationComplete() {
this.emit('verification-complete');
},
}
_cancelAndReset() {
this.cancel();
this._onReset();
},
}
_retry() {
this.begin(this._userName, new Batch.Hold());
},
}
_verificationFailed(retry) {
// For Not Listed / enterprise logins, immediately reset
@ -567,7 +564,7 @@ var ShellUserVerifier = new Lang.Class({
}
this.emit('verification-failed', canRetry);
},
}
_onConversationStopped(client, serviceName) {
// If the login failed with the preauthenticated oVirt credentials
@ -586,6 +583,6 @@ var ShellUserVerifier = new Lang.Class({
if (this.serviceIsForeground(serviceName)) {
this._verificationFailed(true);
}
},
});
}
};
Signals.addSignalMethods(ShellUserVerifier.prototype);