js: Use (dis)connectObject()
Start using the new methods to simplify signal cleanup. For now, focus on replacing existing cleanups; in most cases this means signals connected in the constructor and disconnected on destroy, but also other cases with a similarly defined lifetime (say: from show to hide). This doesn't change signal connections that only exist for a short time (say: once), handlers that are connected on-demand (say: the first time a particular method is called), or connections that aren't tracked (read: disconnected) at all. We will eventually replace the latter with connectObject() as well - especially from actor subclasses - but the changeset is already big enough as-is :-) Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
This commit is contained in:

committed by
Marge Bot

parent
f45ccc9143
commit
26235bbe54
@ -69,10 +69,10 @@ var GeoclueAgent = GObject.registerClass({
|
||||
super._init();
|
||||
|
||||
this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA });
|
||||
this._settings.connect(`changed::${ENABLED}`,
|
||||
() => this.notify('enabled'));
|
||||
this._settings.connect(`changed::${MAX_ACCURACY_LEVEL}`,
|
||||
this._onMaxAccuracyLevelChanged.bind(this));
|
||||
this._settings.connectObject(
|
||||
`changed::${ENABLED}`, () => this.notify('enabled'),
|
||||
`changed::${MAX_ACCURACY_LEVEL}`, () => this._onMaxAccuracyLevelChanged(),
|
||||
this);
|
||||
|
||||
this._agent = Gio.DBusExportedObject.wrapJSObject(AgentIface, this);
|
||||
this._agent.export(Gio.DBus.system, '/org/freedesktop/GeoClue2/Agent');
|
||||
@ -149,8 +149,8 @@ var GeoclueAgent = GObject.registerClass({
|
||||
}
|
||||
|
||||
this._managerProxy = proxy;
|
||||
this._propertiesChangedId = this._managerProxy.connect('g-properties-changed',
|
||||
this._onGeocluePropsChanged.bind(this));
|
||||
this._managerProxy.connectObject('g-properties-changed',
|
||||
this._onGeocluePropsChanged.bind(this), this);
|
||||
|
||||
this.notify('in-use');
|
||||
|
||||
@ -166,10 +166,7 @@ var GeoclueAgent = GObject.registerClass({
|
||||
}
|
||||
|
||||
_onGeoclueVanished() {
|
||||
if (this._propertiesChangedId) {
|
||||
this._managerProxy.disconnect(this._propertiesChangedId);
|
||||
this._propertiesChangedId = 0;
|
||||
}
|
||||
this._managerProxy.disconnectObject(this);
|
||||
this._managerProxy = null;
|
||||
|
||||
this.notify('in-use');
|
||||
@ -238,22 +235,14 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
|
||||
this.menu.addMenuItem(this._item);
|
||||
|
||||
this._agentSignals = [
|
||||
this._agent.connect('notify::enabled', () => this._sync()),
|
||||
this._agent.connect('notify::in-use', () => this._sync()),
|
||||
];
|
||||
|
||||
this.connect('destroy', this._onDestroy.bind(this));
|
||||
this._agent.connectObject(
|
||||
'notify::enabled', () => this._sync(),
|
||||
'notify::in-use', () => this._sync(), this);
|
||||
|
||||
Main.sessionMode.connect('updated', this._onSessionUpdated.bind(this));
|
||||
this._onSessionUpdated();
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
this._agentSignals.forEach(id => this._agent.disconnect(id));
|
||||
this._agentSignals = [];
|
||||
}
|
||||
|
||||
_onSessionUpdated() {
|
||||
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
||||
this.menu.setSensitive(sensitive);
|
||||
|
Reference in New Issue
Block a user