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
@ -112,7 +112,6 @@ var NMConnectionItem = class {
|
||||
this._section = section;
|
||||
this._connection = connection;
|
||||
this._activeConnection = null;
|
||||
this._activeConnectionChangedId = 0;
|
||||
|
||||
this._buildUI();
|
||||
this._sync();
|
||||
@ -127,11 +126,7 @@ var NMConnectionItem = class {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._activeConnectionChangedId) {
|
||||
this._activeConnection.disconnect(this._activeConnectionChangedId);
|
||||
this._activeConnectionChangedId = 0;
|
||||
}
|
||||
|
||||
this._activeConnection?.disconnectObject(this);
|
||||
this.labelItem.destroy();
|
||||
this.radioItem.destroy();
|
||||
}
|
||||
@ -188,17 +183,12 @@ var NMConnectionItem = class {
|
||||
}
|
||||
|
||||
setActiveConnection(activeConnection) {
|
||||
if (this._activeConnectionChangedId > 0) {
|
||||
this._activeConnection.disconnect(this._activeConnectionChangedId);
|
||||
this._activeConnectionChangedId = 0;
|
||||
}
|
||||
this._activeConnection?.disconnectObject(this);
|
||||
|
||||
this._activeConnection = activeConnection;
|
||||
|
||||
if (this._activeConnection) {
|
||||
this._activeConnectionChangedId = this._activeConnection.connect('notify::state',
|
||||
this._connectionStateChanged.bind(this));
|
||||
}
|
||||
this._activeConnection?.connectObject('notify::state',
|
||||
this._connectionStateChanged.bind(this), this);
|
||||
|
||||
this._sync();
|
||||
}
|
||||
@ -222,15 +212,12 @@ var NMConnectionSection = class NMConnectionSection {
|
||||
this.item.menu.addMenuItem(this._labelSection);
|
||||
this.item.menu.addMenuItem(this._radioSection);
|
||||
|
||||
this._notifyConnectivityId = this._client.connect('notify::connectivity', this._iconChanged.bind(this));
|
||||
this._client.connectObject('notify::connectivity',
|
||||
this._iconChanged.bind(this), this);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._notifyConnectivityId != 0) {
|
||||
this._client.disconnect(this._notifyConnectivityId);
|
||||
this._notifyConnectivityId = 0;
|
||||
}
|
||||
|
||||
this._client.disconnectObject(this);
|
||||
this.item.destroy();
|
||||
}
|
||||
|
||||
@ -348,8 +335,10 @@ var NMConnectionDevice = class NMConnectionDevice extends NMConnectionSection {
|
||||
this._autoConnectItem = this.item.menu.addAction(_("Connect"), this._autoConnect.bind(this));
|
||||
this._deactivateItem = this._radioSection.addAction(_("Turn Off"), this.deactivateConnection.bind(this));
|
||||
|
||||
this._stateChangedId = this._device.connect('state-changed', this._deviceStateChanged.bind(this));
|
||||
this._activeConnectionChangedId = this._device.connect('notify::active-connection', this._activeConnectionChanged.bind(this));
|
||||
this._device.connectObject(
|
||||
'state-changed', this._deviceStateChanged.bind(this),
|
||||
'notify::active-connection', this._activeConnectionChanged.bind(this),
|
||||
this);
|
||||
}
|
||||
|
||||
_canReachInternet() {
|
||||
@ -365,14 +354,7 @@ var NMConnectionDevice = class NMConnectionDevice extends NMConnectionSection {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._stateChangedId) {
|
||||
GObject.signal_handler_disconnect(this._device, this._stateChangedId);
|
||||
this._stateChangedId = 0;
|
||||
}
|
||||
if (this._activeConnectionChangedId) {
|
||||
GObject.signal_handler_disconnect(this._device, this._activeConnectionChangedId);
|
||||
this._activeConnectionChangedId = 0;
|
||||
}
|
||||
this._device.disconnectObject(this);
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
@ -560,15 +542,12 @@ var NMDeviceModem = class extends NMConnectionDevice {
|
||||
else if (capabilities & NM.DeviceModemCapabilities.LTE)
|
||||
this._mobileDevice = new ModemManager.ModemGsm(device.udi);
|
||||
|
||||
if (this._mobileDevice) {
|
||||
this._operatorNameId = this._mobileDevice.connect('notify::operator-name', this._sync.bind(this));
|
||||
this._signalQualityId = this._mobileDevice.connect('notify::signal-quality', () => {
|
||||
this._iconChanged();
|
||||
});
|
||||
}
|
||||
this._mobileDevice?.connectObject(
|
||||
'notify::operator-name', this._sync.bind(this),
|
||||
'notify::signal-quality', () => this._iconChanged(), this);
|
||||
|
||||
this._sessionUpdatedId =
|
||||
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
||||
Main.sessionMode.connectObject('updated',
|
||||
this._sessionUpdated.bind(this), this);
|
||||
this._sessionUpdated();
|
||||
}
|
||||
|
||||
@ -596,18 +575,8 @@ var NMDeviceModem = class extends NMConnectionDevice {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._operatorNameId) {
|
||||
this._mobileDevice.disconnect(this._operatorNameId);
|
||||
this._operatorNameId = 0;
|
||||
}
|
||||
if (this._signalQualityId) {
|
||||
this._mobileDevice.disconnect(this._signalQualityId);
|
||||
this._signalQualityId = 0;
|
||||
}
|
||||
if (this._sessionUpdatedId) {
|
||||
Main.sessionMode.disconnect(this._sessionUpdatedId);
|
||||
this._sessionUpdatedId = 0;
|
||||
}
|
||||
this._mobileDevice?.disconnectObject(this);
|
||||
Main.sessionMode.disconnectObject(this);
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
@ -775,12 +744,12 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
|
||||
this._client = client;
|
||||
this._device = device;
|
||||
|
||||
this._wirelessEnabledChangedId = this._client.connect('notify::wireless-enabled',
|
||||
this._syncView.bind(this));
|
||||
this._client.connectObject('notify::wireless-enabled',
|
||||
this._syncView.bind(this), this);
|
||||
|
||||
this._rfkill = Rfkill.getRfkillManager();
|
||||
this._airplaneModeChangedId = this._rfkill.connect('airplane-mode-changed',
|
||||
this._syncView.bind(this));
|
||||
this._rfkill.connectObject('airplane-mode-changed',
|
||||
this._syncView.bind(this), this);
|
||||
|
||||
this._networks = [];
|
||||
this._buildLayout();
|
||||
@ -789,9 +758,10 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
|
||||
this._connections = connections.filter(
|
||||
connection => device.connection_valid(connection));
|
||||
|
||||
this._apAddedId = device.connect('access-point-added', this._accessPointAdded.bind(this));
|
||||
this._apRemovedId = device.connect('access-point-removed', this._accessPointRemoved.bind(this));
|
||||
this._activeApChangedId = device.connect('notify::active-access-point', this._activeApChanged.bind(this));
|
||||
device.connectObject(
|
||||
'access-point-added', this._accessPointAdded.bind(this),
|
||||
'access-point-removed', this._accessPointRemoved.bind(this),
|
||||
'notify::active-access-point', this._activeApChanged.bind(this), this);
|
||||
|
||||
// accessPointAdded will also create dialog items
|
||||
let accessPoints = device.get_access_points() || [];
|
||||
@ -820,27 +790,6 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
if (this._apAddedId) {
|
||||
GObject.Object.prototype.disconnect.call(this._device, this._apAddedId);
|
||||
this._apAddedId = 0;
|
||||
}
|
||||
if (this._apRemovedId) {
|
||||
GObject.Object.prototype.disconnect.call(this._device, this._apRemovedId);
|
||||
this._apRemovedId = 0;
|
||||
}
|
||||
if (this._activeApChangedId) {
|
||||
GObject.Object.prototype.disconnect.call(this._device, this._activeApChangedId);
|
||||
this._activeApChangedId = 0;
|
||||
}
|
||||
if (this._wirelessEnabledChangedId) {
|
||||
this._client.disconnect(this._wirelessEnabledChangedId);
|
||||
this._wirelessEnabledChangedId = 0;
|
||||
}
|
||||
if (this._airplaneModeChangedId) {
|
||||
this._rfkill.disconnect(this._airplaneModeChangedId);
|
||||
this._airplaneModeChangedId = 0;
|
||||
}
|
||||
|
||||
if (this._scanTimeoutId) {
|
||||
GLib.source_remove(this._scanTimeoutId);
|
||||
this._scanTimeoutId = 0;
|
||||
@ -1043,8 +992,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
|
||||
|
||||
_notifySsidCb(accessPoint) {
|
||||
if (accessPoint.get_ssid() != null) {
|
||||
accessPoint.disconnect(accessPoint._notifySsidId);
|
||||
accessPoint._notifySsidId = 0;
|
||||
accessPoint.disconnectObject(this);
|
||||
this._accessPointAdded(this._device, accessPoint);
|
||||
}
|
||||
}
|
||||
@ -1168,7 +1116,8 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
|
||||
if (accessPoint.get_ssid() == null) {
|
||||
// This access point is not visible yet
|
||||
// Wait for it to get a ssid
|
||||
accessPoint._notifySsidId = accessPoint.connect('notify::ssid', this._notifySsidCb.bind(this));
|
||||
accessPoint.connectObject('notify::ssid',
|
||||
this._notifySsidCb.bind(this), this);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1309,11 +1258,14 @@ var NMDeviceWireless = class {
|
||||
|
||||
this.item.menu.addSettingsAction(_("Wi-Fi Settings"), 'gnome-wifi-panel.desktop');
|
||||
|
||||
this._wirelessEnabledChangedId = this._client.connect('notify::wireless-enabled', this._sync.bind(this));
|
||||
this._wirelessHwEnabledChangedId = this._client.connect('notify::wireless-hardware-enabled', this._sync.bind(this));
|
||||
this._activeApChangedId = this._device.connect('notify::active-access-point', this._activeApChanged.bind(this));
|
||||
this._stateChangedId = this._device.connect('state-changed', this._deviceStateChanged.bind(this));
|
||||
this._notifyConnectivityId = this._client.connect('notify::connectivity', this._iconChanged.bind(this));
|
||||
this._client.connectObject(
|
||||
'notify::wireless-enabled', this._sync.bind(this),
|
||||
'notify::wireless-hardware-enabled', this._sync.bind(this),
|
||||
'notify::connectivity', this._iconChanged.bind(this), this);
|
||||
|
||||
this._device.connectObject(
|
||||
'notify::active-access-point', this._activeApChanged.bind(this),
|
||||
'state-changed', this._deviceStateChanged.bind(this), this);
|
||||
|
||||
this._sync();
|
||||
}
|
||||
@ -1328,34 +1280,14 @@ var NMDeviceWireless = class {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._activeApChangedId) {
|
||||
GObject.signal_handler_disconnect(this._device, this._activeApChangedId);
|
||||
this._activeApChangedId = 0;
|
||||
}
|
||||
if (this._stateChangedId) {
|
||||
GObject.signal_handler_disconnect(this._device, this._stateChangedId);
|
||||
this._stateChangedId = 0;
|
||||
}
|
||||
if (this._strengthChangedId > 0) {
|
||||
this._activeAccessPoint.disconnect(this._strengthChangedId);
|
||||
this._strengthChangedId = 0;
|
||||
}
|
||||
if (this._wirelessEnabledChangedId) {
|
||||
this._client.disconnect(this._wirelessEnabledChangedId);
|
||||
this._wirelessEnabledChangedId = 0;
|
||||
}
|
||||
if (this._wirelessHwEnabledChangedId) {
|
||||
this._client.disconnect(this._wirelessHwEnabledChangedId);
|
||||
this._wirelessHwEnabledChangedId = 0;
|
||||
}
|
||||
this._device.disconnectObject(this);
|
||||
this._activeAccessPoint?.disconnectObject(this);
|
||||
this._client.disconnectObject(this);
|
||||
|
||||
if (this._dialog) {
|
||||
this._dialog.destroy();
|
||||
this._dialog = null;
|
||||
}
|
||||
if (this._notifyConnectivityId) {
|
||||
this._client.disconnect(this._notifyConnectivityId);
|
||||
this._notifyConnectivityId = 0;
|
||||
}
|
||||
|
||||
this.item.destroy();
|
||||
}
|
||||
@ -1395,17 +1327,12 @@ var NMDeviceWireless = class {
|
||||
}
|
||||
|
||||
_activeApChanged() {
|
||||
if (this._activeAccessPoint) {
|
||||
this._activeAccessPoint.disconnect(this._strengthChangedId);
|
||||
this._strengthChangedId = 0;
|
||||
}
|
||||
this._activeAccessPoint?.disconnectObject(this);
|
||||
|
||||
this._activeAccessPoint = this._device.active_access_point;
|
||||
|
||||
if (this._activeAccessPoint) {
|
||||
this._strengthChangedId = this._activeAccessPoint.connect('notify::strength',
|
||||
this._strengthChanged.bind(this));
|
||||
}
|
||||
this._activeAccessPoint?.connectObject('notify::strength',
|
||||
this._strengthChanged.bind(this), this);
|
||||
|
||||
this._sync();
|
||||
}
|
||||
@ -1568,17 +1495,12 @@ var NMVpnConnectionItem = class extends NMConnectionItem {
|
||||
}
|
||||
|
||||
setActiveConnection(activeConnection) {
|
||||
if (this._activeConnectionChangedId > 0) {
|
||||
this._activeConnection.disconnect(this._activeConnectionChangedId);
|
||||
this._activeConnectionChangedId = 0;
|
||||
}
|
||||
this._activeConnection?.disconnectObject(this);
|
||||
|
||||
this._activeConnection = activeConnection;
|
||||
|
||||
if (this._activeConnection) {
|
||||
this._activeConnectionChangedId = this._activeConnection.connect('vpn-state-changed',
|
||||
this._connectionStateChanged.bind(this));
|
||||
}
|
||||
this._activeConnection?.connectObject('vpn-state-changed',
|
||||
this._connectionStateChanged.bind(this), this);
|
||||
|
||||
this._sync();
|
||||
}
|
||||
@ -1766,8 +1688,6 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
this._connectivityQueue = [];
|
||||
|
||||
this._mainConnection = null;
|
||||
this._mainConnectionIconChangedId = 0;
|
||||
this._mainConnectionStateChangedId = 0;
|
||||
|
||||
this._notification = null;
|
||||
|
||||
@ -1919,8 +1839,8 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
}
|
||||
|
||||
_addDeviceWrapper(wrapper) {
|
||||
wrapper._activationFailedId = wrapper.connect('activation-failed',
|
||||
this._onActivationFailed.bind(this));
|
||||
wrapper.connectObject('activation-failed',
|
||||
this._onActivationFailed.bind(this), this);
|
||||
|
||||
let section = this._devices[wrapper.category].section;
|
||||
section.addMenuItem(wrapper.item);
|
||||
@ -1946,7 +1866,7 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
}
|
||||
|
||||
_removeDeviceWrapper(wrapper) {
|
||||
wrapper.disconnect(wrapper._activationFailedId);
|
||||
wrapper.disconnectObject(this);
|
||||
wrapper.destroy();
|
||||
|
||||
let devices = this._devices[wrapper.category].devices;
|
||||
@ -1973,22 +1893,16 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
}
|
||||
|
||||
_syncMainConnection() {
|
||||
if (this._mainConnectionIconChangedId > 0) {
|
||||
this._mainConnection._primaryDevice.disconnect(this._mainConnectionIconChangedId);
|
||||
this._mainConnectionIconChangedId = 0;
|
||||
}
|
||||
|
||||
if (this._mainConnectionStateChangedId > 0) {
|
||||
this._mainConnection.disconnect(this._mainConnectionStateChangedId);
|
||||
this._mainConnectionStateChangedId = 0;
|
||||
}
|
||||
this._mainConnection?._primaryDevice?.disconnectObject(this);
|
||||
this._mainConnection?.disconnectObject(this);
|
||||
|
||||
this._mainConnection = this._getMainConnection();
|
||||
|
||||
if (this._mainConnection) {
|
||||
if (this._mainConnection._primaryDevice)
|
||||
this._mainConnectionIconChangedId = this._mainConnection._primaryDevice.connect('icon-changed', this._updateIcon.bind(this));
|
||||
this._mainConnectionStateChangedId = this._mainConnection.connect('notify::state', this._mainConnectionStateChanged.bind(this));
|
||||
this._mainConnection._primaryDevice?.connectObject('icon-changed',
|
||||
this._updateIcon.bind(this), this);
|
||||
this._mainConnection.connectObject('notify::state',
|
||||
this._mainConnectionStateChanged.bind(this), this);
|
||||
this._mainConnectionStateChanged();
|
||||
}
|
||||
|
||||
@ -2028,12 +1942,13 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
_addConnection(connection) {
|
||||
if (this._ignoreConnection(connection))
|
||||
return;
|
||||
if (connection._updatedId) {
|
||||
if (this._connections.includes(connection)) {
|
||||
// connection was already seen
|
||||
return;
|
||||
}
|
||||
|
||||
connection._updatedId = connection.connect('changed', this._updateConnection.bind(this));
|
||||
connection.connectObject('changed',
|
||||
this._updateConnection.bind(this), this);
|
||||
|
||||
this._updateConnection(connection);
|
||||
this._connections.push(connection);
|
||||
@ -2068,8 +1983,7 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
}
|
||||
}
|
||||
|
||||
connection.disconnect(connection._updatedId);
|
||||
connection._updatedId = 0;
|
||||
connection.disconnectObject(this);
|
||||
}
|
||||
|
||||
_updateConnection(connection) {
|
||||
|
Reference in New Issue
Block a user