cleanup: Port GObject classes to JS6 classes

GJS added API for defining GObject classes with ES6 class syntax
last cycle, use it to port the remaining Lang.Class classes to
the new syntax.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
This commit is contained in:
Florian Müllner
2017-10-31 02:23:39 +01:00
committed by Georges Basile Stavracas Neto
parent bacfdbbb03
commit e68dfed1f7
43 changed files with 1036 additions and 1235 deletions

View File

@ -3,7 +3,6 @@ const Clutter = imports.gi.Clutter;
const Gdm = imports.gi.Gdm;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Meta = imports.gi.Meta;
const GObject = imports.gi.GObject;
@ -44,9 +43,7 @@ function getDefault() {
return _singleton;
}
const SystemActions = new Lang.Class({
Name: 'SystemActions',
Extends: GObject.Object,
const SystemActions = GObject.registerClass({
Properties: {
'can-power-off': GObject.ParamSpec.boolean('can-power-off',
'can-power-off',
@ -83,10 +80,10 @@ const SystemActions = new Lang.Class({
'orientation-lock-icon',
GObject.ParamFlags.READWRITE,
null)
},
}
}, class SystemActions extends GObject.Object {
_init() {
this.parent();
super._init();
this._canHavePowerOff = true;
this._canHaveSuspend = true;
@ -186,35 +183,35 @@ const SystemActions = new Lang.Class({
Main.sessionMode.connect('updated', () => { this._sessionUpdated(); });
this._sessionUpdated();
},
}
get can_power_off() {
return this._actions.get(POWER_OFF_ACTION_ID).available;
},
}
get can_suspend() {
return this._actions.get(SUSPEND_ACTION_ID).available;
},
}
get can_lock_screen() {
return this._actions.get(LOCK_SCREEN_ACTION_ID).available;
},
}
get can_switch_user() {
return this._actions.get(SWITCH_USER_ACTION_ID).available;
},
}
get can_logout() {
return this._actions.get(LOGOUT_ACTION_ID).available;
},
}
get can_lock_orientation() {
return this._actions.get(LOCK_ORIENTATION_ACTION_ID).available;
},
}
get orientation_lock_icon() {
return this._actions.get(LOCK_ORIENTATION_ACTION_ID).iconName;
},
}
_sensorProxyAppeared() {
this._sensorProxy = new SensorProxy(Gio.DBus.system, SENSOR_BUS_NAME, SENSOR_OBJECT_PATH,
@ -227,7 +224,7 @@ const SystemActions = new Lang.Class({
() => { this._updateOrientationLock(); });
this._updateOrientationLock();
});
},
}
_updateOrientationLock() {
let available = false;
@ -238,7 +235,7 @@ const SystemActions = new Lang.Class({
this._actions.get(LOCK_ORIENTATION_ACTION_ID).available = available;
this.notify('can-lock-orientation');
},
}
_updateOrientationLockIcon() {
let locked = this._orientationSettings.get_boolean('orientation-lock');
@ -247,14 +244,14 @@ const SystemActions = new Lang.Class({
this._actions.get(LOCK_ORIENTATION_ACTION_ID).iconName = iconName;
this.notify('orientation-lock-icon');
},
}
_sessionUpdated() {
this._updateLockScreen();
this._updatePowerOff();
this._updateSuspend();
this._updateMultiUser();
},
}
forceUpdate() {
// Whether those actions are available or not depends on both lockdown
@ -262,7 +259,7 @@ const SystemActions = new Lang.Class({
// latter, so their value may be outdated; force an update now
this._updateHaveShutdown();
this._updateHaveSuspend();
},
}
getMatchingActions(terms) {
// terms is a list of strings
@ -275,15 +272,15 @@ const SystemActions = new Lang.Class({
results.push(key);
return results;
},
}
getName(id) {
return this._actions.get(id).name;
},
}
getIconName(id) {
return this._actions.get(id).iconName;
},
}
activateAction(id) {
switch (id) {
@ -306,14 +303,14 @@ const SystemActions = new Lang.Class({
this.activateLockOrientation();
break;
}
},
}
_updateLockScreen() {
let showLock = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
this._actions.get(LOCK_SCREEN_ACTION_ID).available = showLock && allowLockScreen && LoginManager.canLock();
this.notify('can-lock-screen');
},
}
_updateHaveShutdown() {
this._session.CanShutdownRemote((result, error) => {
@ -323,7 +320,7 @@ const SystemActions = new Lang.Class({
this._canHavePowerOff = result[0];
this._updatePowerOff();
});
},
}
_updatePowerOff() {
let disabled = Main.sessionMode.isLocked ||
@ -331,7 +328,7 @@ const SystemActions = new Lang.Class({
this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY));
this._actions.get(POWER_OFF_ACTION_ID).available = this._canHavePowerOff && !disabled;
this.notify('can-power-off');
},
}
_updateHaveSuspend() {
this._loginManager.canSuspend(
@ -340,7 +337,7 @@ const SystemActions = new Lang.Class({
this._suspendNeedsAuth = needsAuth;
this._updateSuspend();
});
},
}
_updateSuspend() {
let disabled = (Main.sessionMode.isLocked &&
@ -349,12 +346,12 @@ const SystemActions = new Lang.Class({
this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY));
this._actions.get(SUSPEND_ACTION_ID).available = this._canHaveSuspend && !disabled;
this.notify('can-suspend');
},
}
_updateMultiUser() {
this._updateLogout();
this._updateSwitchUser();
},
}
_updateSwitchUser() {
let allowSwitch = !this._lockdownSettings.get_boolean(DISABLE_USER_SWITCH_KEY);
@ -366,7 +363,7 @@ const SystemActions = new Lang.Class({
this.notify('can-switch-user');
return visible;
},
}
_updateLogout() {
let user = this._userManager.get_user(GLib.get_user_name());
@ -384,7 +381,7 @@ const SystemActions = new Lang.Class({
this.notify('can-logout');
return visible;
},
}
activateLockOrientation() {
if (!this._actions.get(LOCK_ORIENTATION_ACTION_ID).available)
@ -392,14 +389,14 @@ const SystemActions = new Lang.Class({
let locked = this._orientationSettings.get_boolean('orientation-lock');
this._orientationSettings.set_boolean('orientation-lock', !locked);
},
}
activateLockScreen() {
if (!this._actions.get(LOCK_SCREEN_ACTION_ID).available)
throw new Error('The lock-screen action is not available!');
Main.screenShield.lock(true);
},
}
activateSwitchUser() {
if (!this._actions.get(SWITCH_USER_ACTION_ID).available)
@ -412,7 +409,7 @@ const SystemActions = new Lang.Class({
Gdm.goto_login_session_sync(null);
return false;
});
},
}
activateLogout() {
if (!this._actions.get(LOGOUT_ACTION_ID).available)
@ -420,14 +417,14 @@ const SystemActions = new Lang.Class({
Main.overview.hide();
this._session.LogoutRemote(0);
},
}
activatePowerOff() {
if (!this._actions.get(POWER_OFF_ACTION_ID).available)
throw new Error('The power-off action is not available!');
this._session.ShutdownRemote(0);
},
}
activateSuspend() {
if (!this._actions.get(SUSPEND_ACTION_ID).available)