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:

committed by
Georges Basile Stavracas Neto

parent
99ce3deeb0
commit
bacfdbbb03
@ -3,7 +3,6 @@
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const GLib = imports.gi.GLib;
|
||||
const Gio = imports.gi.Gio;
|
||||
const Lang = imports.lang;
|
||||
|
||||
const Dialog = imports.ui.dialog;
|
||||
const Main = imports.ui.main;
|
||||
@ -47,12 +46,9 @@ const GeoclueManager = Gio.DBusProxy.makeProxyWrapper(GeoclueIface);
|
||||
|
||||
var AgentIface = loadInterfaceXML('org.freedesktop.GeoClue2.Agent');
|
||||
|
||||
var Indicator = new Lang.Class({
|
||||
Name: 'LocationIndicator',
|
||||
Extends: PanelMenu.SystemIndicator,
|
||||
|
||||
_init() {
|
||||
this.parent();
|
||||
var Indicator = class extends PanelMenu.SystemIndicator {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA });
|
||||
this._settings.connect('changed::' + ENABLED,
|
||||
@ -85,11 +81,11 @@ var Indicator = new Lang.Class({
|
||||
this._onMaxAccuracyLevelChanged();
|
||||
this._connectToGeoclue();
|
||||
this._connectToPermissionStore();
|
||||
},
|
||||
}
|
||||
|
||||
get MaxAccuracyLevel() {
|
||||
return this._getMaxAccuracyLevel();
|
||||
},
|
||||
}
|
||||
|
||||
AuthorizeAppAsync(params, invocation) {
|
||||
let [desktopId, reqAccuracyLevel] = params;
|
||||
@ -104,7 +100,7 @@ var Indicator = new Lang.Class({
|
||||
invocation.return_value(GLib.Variant.new('(bu)',
|
||||
[ret, accuracyLevel]));
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
_syncIndicator() {
|
||||
if (this._managerProxy == null) {
|
||||
@ -116,7 +112,7 @@ var Indicator = new Lang.Class({
|
||||
this._indicator.visible = this._managerProxy.InUse;
|
||||
this._item.actor.visible = this._indicator.visible;
|
||||
this._updateMenuLabels();
|
||||
},
|
||||
}
|
||||
|
||||
_connectToGeoclue() {
|
||||
if (this._managerProxy != null || this._connecting)
|
||||
@ -128,7 +124,7 @@ var Indicator = new Lang.Class({
|
||||
'/org/freedesktop/GeoClue2/Manager',
|
||||
this._onManagerProxyReady.bind(this));
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
_onManagerProxyReady(proxy, error) {
|
||||
if (error != null) {
|
||||
@ -144,7 +140,7 @@ var Indicator = new Lang.Class({
|
||||
this._syncIndicator();
|
||||
|
||||
this._managerProxy.AddAgentRemote('gnome-shell', this._onAgentRegistered.bind(this));
|
||||
},
|
||||
}
|
||||
|
||||
_onAgentRegistered(result, error) {
|
||||
this._connecting = false;
|
||||
@ -152,7 +148,7 @@ var Indicator = new Lang.Class({
|
||||
|
||||
if (error != null)
|
||||
log(error.message);
|
||||
},
|
||||
}
|
||||
|
||||
_onGeoclueVanished() {
|
||||
if (this._propertiesChangedId) {
|
||||
@ -162,17 +158,17 @@ var Indicator = new Lang.Class({
|
||||
this._managerProxy = null;
|
||||
|
||||
this._syncIndicator();
|
||||
},
|
||||
}
|
||||
|
||||
_onOnOffAction() {
|
||||
let enabled = this._settings.get_boolean(ENABLED);
|
||||
this._settings.set_boolean(ENABLED, !enabled);
|
||||
},
|
||||
}
|
||||
|
||||
_onSessionUpdated() {
|
||||
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
||||
this.menu.setSensitive(sensitive);
|
||||
},
|
||||
}
|
||||
|
||||
_updateMenuLabels() {
|
||||
if (this._settings.get_boolean(ENABLED)) {
|
||||
@ -183,7 +179,7 @@ var Indicator = new Lang.Class({
|
||||
this._item.label.text = _("Location Disabled");
|
||||
this._onOffAction.label.text = _("Enable");
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_onMaxAccuracyLevelChanged() {
|
||||
this._updateMenuLabels();
|
||||
@ -192,7 +188,7 @@ var Indicator = new Lang.Class({
|
||||
// before we emit the notify for this property change.
|
||||
if (!this._connectToGeoclue())
|
||||
this._notifyMaxAccuracyLevel();
|
||||
},
|
||||
}
|
||||
|
||||
_getMaxAccuracyLevel() {
|
||||
if (this._settings.get_boolean(ENABLED)) {
|
||||
@ -203,23 +199,23 @@ var Indicator = new Lang.Class({
|
||||
} else {
|
||||
return GeoclueAccuracyLevel.NONE;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_notifyMaxAccuracyLevel() {
|
||||
let variant = new GLib.Variant('u', this._getMaxAccuracyLevel());
|
||||
this._agent.emit_property_changed('MaxAccuracyLevel', variant);
|
||||
},
|
||||
}
|
||||
|
||||
_onGeocluePropsChanged(proxy, properties) {
|
||||
let unpacked = properties.deep_unpack();
|
||||
if ("InUse" in unpacked)
|
||||
this._syncIndicator();
|
||||
},
|
||||
}
|
||||
|
||||
_connectToPermissionStore() {
|
||||
this._permStoreProxy = null;
|
||||
new PermissionStore.PermissionStore(this._onPermStoreProxyReady.bind(this));
|
||||
},
|
||||
}
|
||||
|
||||
_onPermStoreProxyReady(proxy, error) {
|
||||
if (error != null) {
|
||||
@ -228,20 +224,15 @@ var Indicator = new Lang.Class({
|
||||
}
|
||||
|
||||
this._permStoreProxy = proxy;
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function clamp(value, min, max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
var AppAuthorizer = new Lang.Class({
|
||||
Name: 'LocationAppAuthorizer',
|
||||
|
||||
_init(desktopId,
|
||||
reqAccuracyLevel,
|
||||
permStoreProxy,
|
||||
maxAccuracyLevel) {
|
||||
var AppAuthorizer = class {
|
||||
constructor(desktopId, reqAccuracyLevel, permStoreProxy, maxAccuracyLevel) {
|
||||
this.desktopId = desktopId;
|
||||
this.reqAccuracyLevel = reqAccuracyLevel;
|
||||
this._permStoreProxy = permStoreProxy;
|
||||
@ -249,7 +240,7 @@ var AppAuthorizer = new Lang.Class({
|
||||
this._permissions = {};
|
||||
|
||||
this._accuracyLevel = GeoclueAccuracyLevel.NONE;
|
||||
},
|
||||
}
|
||||
|
||||
authorize(onAuthDone) {
|
||||
this._onAuthDone = onAuthDone;
|
||||
@ -265,7 +256,7 @@ var AppAuthorizer = new Lang.Class({
|
||||
this._permStoreProxy.LookupRemote(APP_PERMISSIONS_TABLE,
|
||||
APP_PERMISSIONS_ID,
|
||||
this._onPermLookupDone.bind(this));
|
||||
},
|
||||
}
|
||||
|
||||
_onPermLookupDone(result, error) {
|
||||
if (error != null) {
|
||||
@ -298,7 +289,7 @@ var AppAuthorizer = new Lang.Class({
|
||||
GeoclueAccuracyLevel.NONE;
|
||||
this._completeAuth();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_userAuthorizeApp() {
|
||||
let name = this._app.get_name();
|
||||
@ -306,7 +297,7 @@ var AppAuthorizer = new Lang.Class({
|
||||
let reason = appInfo.get_locale_string("X-Geoclue-Reason");
|
||||
|
||||
this._showAppAuthDialog(name, reason);
|
||||
},
|
||||
}
|
||||
|
||||
_showAppAuthDialog(name, reason) {
|
||||
this._dialog = new GeolocationDialog(name,
|
||||
@ -320,7 +311,7 @@ var AppAuthorizer = new Lang.Class({
|
||||
});
|
||||
|
||||
this._dialog.open();
|
||||
},
|
||||
}
|
||||
|
||||
_completeAuth() {
|
||||
if (this._accuracyLevel != GeoclueAccuracyLevel.NONE) {
|
||||
@ -331,7 +322,7 @@ var AppAuthorizer = new Lang.Class({
|
||||
this._saveToPermissionStore();
|
||||
|
||||
this._onAuthDone(this._accuracyLevel);
|
||||
},
|
||||
}
|
||||
|
||||
_saveToPermissionStore() {
|
||||
if (this._permStoreProxy == null)
|
||||
@ -352,15 +343,12 @@ var AppAuthorizer = new Lang.Class({
|
||||
if (error != null)
|
||||
log(error.message);
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var GeolocationDialog = new Lang.Class({
|
||||
Name: 'GeolocationDialog',
|
||||
Extends: ModalDialog.ModalDialog,
|
||||
|
||||
_init(name, subtitle, reqAccuracyLevel) {
|
||||
this.parent({ styleClass: 'geolocation-dialog' });
|
||||
var GeolocationDialog = class extends ModalDialog.ModalDialog {
|
||||
constructor(name, subtitle, reqAccuracyLevel) {
|
||||
super({ styleClass: 'geolocation-dialog' });
|
||||
this.reqAccuracyLevel = reqAccuracyLevel;
|
||||
|
||||
let icon = new Gio.ThemedIcon({ name: 'find-location-symbolic' });
|
||||
@ -380,16 +368,16 @@ var GeolocationDialog = new Lang.Class({
|
||||
action: this._onGrantClicked.bind(this) });
|
||||
|
||||
this.setInitialKeyFocus(button);
|
||||
},
|
||||
}
|
||||
|
||||
_onGrantClicked() {
|
||||
this.emit('response', this.reqAccuracyLevel);
|
||||
this.close();
|
||||
},
|
||||
}
|
||||
|
||||
_onDenyClicked() {
|
||||
this.emit('response', GeoclueAccuracyLevel.NONE);
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
Signals.addSignalMethods(GeolocationDialog.prototype);
|
||||
|
Reference in New Issue
Block a user