From d245f4fbf03a1919ef6e4986e97bb30eb6cd33ba Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:37:33 -0300 Subject: [PATCH 01/25] a11y: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/accessibility.js | 38 ++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/js/ui/status/accessibility.js b/js/ui/status/accessibility.js index 04406e2255..fc6c215fbf 100644 --- a/js/ui/status/accessibility.js +++ b/js/ui/status/accessibility.js @@ -42,7 +42,10 @@ class ATIndicator extends PanelMenu.Button { this.add_child(this._hbox); this._a11ySettings = new Gio.Settings({ schema_id: A11Y_SCHEMA }); - this._a11ySettings.connect('changed::%s'.format(KEY_ALWAYS_SHOW), this._queueSyncMenuVisibility.bind(this)); + this._a11ySettingsChangedId = this._a11ySettings.connect('changed::%s'.format(KEY_ALWAYS_SHOW), + this._queueSyncMenuVisibility.bind(this)); + + this._settingsChangedIds = []; let highContrast = this._buildHCItem(); this.menu.addMenuItem(highContrast); @@ -80,6 +83,27 @@ class ATIndicator extends PanelMenu.Button { this._syncMenuVisibility(); } + _onDestroy() { + super._onDestroy(); + + if (this._a11ySettingsChangedId) { + this._a11ySettings.disconnect(this._a11ySettingsChangedId); + this._a11ySettingsChangedId = null; + } + + this._settingsChangedIds.forEach(pair => { + let settings = pair[0]; + let sourceId = pair[1]; + settings.disconnect(sourceId); + }); + this._settingsChangedIds = []; + + if (this._syncMenuVisibilityIdle) { + GLib.source_remove(this._syncMenuVisibilityIdle); + this._syncMenuVisibilityIdle = 0; + } + } + _syncMenuVisibility() { this._syncMenuVisibilityIdle = 0; @@ -118,11 +142,12 @@ class ATIndicator extends PanelMenu.Button { settings.is_writable(key), enabled => settings.set_boolean(key, enabled)); - settings.connect('changed::%s'.format(key), () => { + let changedId = settings.connect('changed::%s'.format(key), () => { widget.setToggleState(settings.get_boolean(key)); this._queueSyncMenuVisibility(); }); + this._settingsChangedIds.push([settings, changedId]); return widget; } @@ -150,7 +175,7 @@ class ATIndicator extends PanelMenu.Button { } }); - interfaceSettings.connect('changed::%s'.format(KEY_GTK_THEME), () => { + let changedId = interfaceSettings.connect('changed::%s'.format(KEY_GTK_THEME), () => { let value = interfaceSettings.get_string(KEY_GTK_THEME); if (value == HIGH_CONTRAST_THEME) { highContrast.setToggleState(true); @@ -161,12 +186,14 @@ class ATIndicator extends PanelMenu.Button { this._queueSyncMenuVisibility(); }); + this._settingsChangedIds.push([interfaceSettings, changedId]); - interfaceSettings.connect('changed::%s'.format(KEY_ICON_THEME), () => { + changedId = interfaceSettings.connect('changed::%s'.format(KEY_ICON_THEME), () => { let value = interfaceSettings.get_string(KEY_ICON_THEME); if (value != HIGH_CONTRAST_THEME) iconTheme = value; }); + this._settingsChangedIds.push([interfaceSettings, changedId]); return highContrast; } @@ -187,13 +214,14 @@ class ATIndicator extends PanelMenu.Button { } }); - settings.connect('changed::%s'.format(KEY_TEXT_SCALING_FACTOR), () => { + let changedId = settings.connect('changed::%s'.format(KEY_TEXT_SCALING_FACTOR), () => { factor = settings.get_double(KEY_TEXT_SCALING_FACTOR); let active = factor > 1.0; widget.setToggleState(active); this._queueSyncMenuVisibility(); }); + this._settingsChangedIds.push([settings, changedId]); return widget; } -- GitLab From cae10afedb3fa87b23d9476f7a25c126aa045293 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:40:34 -0300 Subject: [PATCH 02/25] bluetooth: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/bluetooth.js | 56 ++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index 8510944f59..a7b0cea46d 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -26,16 +26,18 @@ class Indicator extends PanelMenu.SystemIndicator { this._indicator.icon_name = 'bluetooth-active-symbolic'; this._hadSetupDevices = global.settings.get_boolean(HAD_BLUETOOTH_DEVICES_SETUP); + this._cancellable = new Gio.Cancellable(); this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { log(error.message); return; } - this._sync(); - }); - this._proxy.connect('g-properties-changed', this._queueSync.bind(this)); + }, + this._cancellable); + this._proxyPropertiesChangedId = this._proxy.connect('g-properties-changed', + this._queueSync.bind(this)); this._item = new PopupMenu.PopupSubMenuMenuItem(_("Bluetooth"), true); this._item.icon.icon_name = 'bluetooth-active-symbolic'; @@ -54,11 +56,51 @@ class Indicator extends PanelMenu.SystemIndicator { this._client = new GnomeBluetooth.Client(); this._model = this._client.get_model(); - this._model.connect('row-deleted', this._queueSync.bind(this)); - this._model.connect('row-changed', this._queueSync.bind(this)); - this._model.connect('row-inserted', this._sync.bind(this)); - Main.sessionMode.connect('updated', this._sync.bind(this)); + this._rowDeletedId = this._model.connect('row-deleted', this._queueSync.bind(this)); + this._rowChangedId = this._model.connect('row-changed', this._queueSync.bind(this)); + this._rowInsertedId = this._model.connect('row-inserted', this._sync.bind(this)); + + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sync.bind(this)); this._sync(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + + if (this._proxyPropertiesChangedId) { + this._proxy.disconnect(this._proxyPropertiesChangedId); + this._proxyPropertiesChangedId = null; + } + + if (this._rowDeletedId) { + this._model.disconnect(this._rowDeletedId); + this._rowDeletedId = 0; + } + + if (this._rowChangedId) { + this._model.disconnect(this._rowChangedId); + this._rowChangedId = 0; + } + + if (this._rowInsertedId) { + this._model.disconnect(this._rowInsertedId); + this._rowInsertedId = 0; + } + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } + + if (this._syncId) { + GLib.source_remove(this._syncId); + this._syncId = 0; + } } _setHadSetupDevices(value) { -- GitLab From 45dabbed81f2190098bb8eadc33b9ba56a216b73 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 03/25] brightness: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/brightness.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/js/ui/status/brightness.js b/js/ui/status/brightness.js index 17247880f5..0c2e8e485e 100644 --- a/js/ui/status/brightness.js +++ b/js/ui/status/brightness.js @@ -19,16 +19,18 @@ var Indicator = GObject.registerClass( class Indicator extends PanelMenu.SystemIndicator { _init() { super._init(); + this._cancellable = new Gio.Cancellable(); this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { log(error.message); return; } - - this._proxy.connect('g-properties-changed', this._sync.bind(this)); this._sync(); - }); + }, + this._cancellable); + this._proxyPropertiesChangedId = this._proxy.connect('g-properties-changed', + this._sync.bind(this)); this._item = new PopupMenu.PopupBaseMenuItem({ activate: false }); this.menu.addMenuItem(this._item); @@ -51,6 +53,20 @@ class Indicator extends PanelMenu.SystemIndicator { this._item.connect('scroll-event', (actor, event) => { return this._slider.emit('scroll-event', event); }); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + + if (this._proxyPropertiesChangedId) { + this._proxy.disconnect(this._proxyPropertiesChangedId); + this._proxyPropertiesChangedId = 0; + } } _sliderChanged() { -- GitLab From 0b331ea08c6b541edc9818e82dcef13342b7142b Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 04/25] dwellClick: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/dwellClick.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/js/ui/status/dwellClick.js b/js/ui/status/dwellClick.js index ce13f73bae..a7a32fb568 100644 --- a/js/ui/status/dwellClick.js +++ b/js/ui/status/dwellClick.js @@ -45,11 +45,13 @@ class DwellClickIndicator extends PanelMenu.Button { this.add_child(this._hbox); this._a11ySettings = new Gio.Settings({ schema_id: MOUSE_A11Y_SCHEMA }); - this._a11ySettings.connect('changed::%s'.format(KEY_DWELL_CLICK_ENABLED), this._syncMenuVisibility.bind(this)); - this._a11ySettings.connect('changed::%s'.format(KEY_DWELL_MODE), this._syncMenuVisibility.bind(this)); + this._clickEnabledChangedId = this._a11ySettings.connect('changed::%s'.format(KEY_DWELL_CLICK_ENABLED), + this._syncMenuVisibility.bind(this)); + this._modeChangedId = this._a11ySettings.connect('changed::%s'.format(KEY_DWELL_MODE), + this._syncMenuVisibility.bind(this)); this._seat = Clutter.get_default_backend().get_default_seat(); - this._seat.connect('ptr-a11y-dwell-click-type-changed', this._updateClickType.bind(this)); + this._seatClickTypeChanged = this._seat.connect('ptr-a11y-dwell-click-type-changed', this._updateClickType.bind(this)); this._addDwellAction(DWELL_CLICK_MODES.primary); this._addDwellAction(DWELL_CLICK_MODES.double); @@ -60,6 +62,23 @@ class DwellClickIndicator extends PanelMenu.Button { this._syncMenuVisibility(); } + _onDestroy() { + super._onDestroy(); + + if (this._clickEnabledChangedId) { + this._a11ySettings.disconnect(this._clickEnabledChangedId); + this._clickEnabledChangedId = 0; + } + if (this._modeChangedId) { + this._a11ySettings.disconnect(this._modeChangedId); + this._modeChangedId = 0; + } + if (this._seatClickTypeChanged) { + this._seat.disconnect(this._seatClickTypeChanged); + this._seatClickTypeChanged = 0; + } + } + _syncMenuVisibility() { this.visible = this._a11ySettings.get_boolean(KEY_DWELL_CLICK_ENABLED) && -- GitLab From a682cc033c2d8c67801c7a40344e576121efef8f Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 05/25] keyboard: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/keyboard.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js index 43fd89db2e..a804edb1b9 100644 --- a/js/ui/status/keyboard.js +++ b/js/ui/status/keyboard.js @@ -825,8 +825,6 @@ class InputSourceIndicator extends PanelMenu.Button { _init() { super._init(0.5, _("Keyboard")); - this.connect('destroy', this._onDestroy.bind(this)); - this._menuItems = {}; this._indicatorLabels = {}; @@ -847,7 +845,7 @@ class InputSourceIndicator extends PanelMenu.Button { this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this._showLayoutItem = this.menu.addAction(_("Show Keyboard Layout"), this._showLayout.bind(this)); - Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); this._sessionUpdated(); this._inputSourceManager = getInputSourceManager(); @@ -855,10 +853,25 @@ class InputSourceIndicator extends PanelMenu.Button { this._inputSourceManager.connect('sources-changed', this._sourcesChanged.bind(this)); this._inputSourceManagerCurrentSourceChangedId = this._inputSourceManager.connect('current-source-changed', this._currentSourceChanged.bind(this)); + this._inputSourceChangedIds = []; this._inputSourceManager.reload(); } _onDestroy() { + super._onDestroy(); + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } + + this._inputSourceChangedIds.forEach(pair => { + let is = pair[0]; + let sourceId = pair[1]; + is.disconnect(sourceId); + }); + this._inputSourceChangedIds = []; + if (this._inputSourceManager) { this._inputSourceManager.disconnect(this._inputSourceManagerSourcesChangedId); this._inputSourceManager.disconnect(this._inputSourceManagerCurrentSourceChangedId); @@ -895,10 +908,11 @@ class InputSourceIndicator extends PanelMenu.Button { this._menuItems[i] = menuItem; this._indicatorLabels[i] = indicatorLabel; - is.connect('changed', () => { + let changedId = is.connect('changed', () => { menuItem.indicator.set_text(is.shortName); indicatorLabel.set_text(is.shortName); }); + this._inputSourceChangedIds.push([is, changedId]); this.menu.addMenuItem(menuItem, menuIndex++); this._container.add_actor(indicatorLabel); -- GitLab From 64778489a5893ae6cad84f307c0cb017e345a8fc Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 06/25] location: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/location.js | 57 +++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/js/ui/status/location.js b/js/ui/status/location.js index 4250ed0fe9..d1519b4af4 100644 --- a/js/ui/status/location.js +++ b/js/ui/status/location.js @@ -47,11 +47,13 @@ class Indicator extends PanelMenu.SystemIndicator { _init() { super._init(); + this._cancellable = new Gio.Cancellable(); + this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA }); - this._settings.connect('changed::%s'.format(ENABLED), - this._onMaxAccuracyLevelChanged.bind(this)); - this._settings.connect('changed::%s'.format(MAX_ACCURACY_LEVEL), - this._onMaxAccuracyLevelChanged.bind(this)); + this._enabledChangedId = this._settings.connect('changed::%s'.format(ENABLED), + this._onMaxAccuracyLevelChanged.bind(this)); + this._maxAccuracyLevelChangedId = this._settings.connect('changed::%s'.format(MAX_ACCURACY_LEVEL), + this._onMaxAccuracyLevelChanged.bind(this)); this._indicator = this._addIndicator(); this._indicator.icon_name = 'find-location-symbolic'; @@ -73,11 +75,50 @@ class Indicator extends PanelMenu.SystemIndicator { 0, this._connectToGeoclue.bind(this), this._onGeoclueVanished.bind(this)); - Main.sessionMode.connect('updated', this._onSessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._onSessionUpdated.bind(this)); this._onSessionUpdated(); this._onMaxAccuracyLevelChanged(); this._connectToGeoclue(); this._connectToPermissionStore(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + + if (this._enabledChangedId) { + this._settings.disconnect(this._enabledChangedId); + this._enabledChangedId = 0; + } + + if (this._maxAccuracyLevelChangedId) { + this._settings.disconnect(this._maxAccuracyLevelChangedId); + this._maxAccuracyLevelChangedId = 0; + } + + if (this._propertiesChangedId) { + this._managerProxy.disconnect(this._propertiesChangedId); + this._propertiesChangedId = 0; + } + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } + + if (this._watchId) { + Gio.bus_unwatch_name(this._watchId); + this._watchId = 0; + } + + if (this._agent) { + this._agent.unexport(); + this._agent = null; + } } get MaxAccuracyLevel() { @@ -119,7 +160,8 @@ class Indicator extends PanelMenu.SystemIndicator { new GeoclueManager(Gio.DBus.system, 'org.freedesktop.GeoClue2', '/org/freedesktop/GeoClue2/Manager', - this._onManagerProxyReady.bind(this)); + this._onManagerProxyReady.bind(this), + this._cancellable); return true; } @@ -212,7 +254,8 @@ class Indicator extends PanelMenu.SystemIndicator { _connectToPermissionStore() { this._permStoreProxy = null; - new PermissionStore.PermissionStore(this._onPermStoreProxyReady.bind(this)); + new PermissionStore.PermissionStore(this._onPermStoreProxyReady.bind(this), + this._cancellable); } _onPermStoreProxyReady(proxy, error) { -- GitLab From a4823a6b3a592bd885dd16dc8367a7b48464e4fb Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 07/25] network: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/network.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 3d4acd5b08..9b34dbb020 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -761,11 +761,12 @@ class NMWirelessDialog extends ModalDialog.ModalDialog { GLib.Source.set_name_by_id(this._scanTimeoutId, '[gnome-shell] this._onScanTimeout'); this._onScanTimeout(); - let id = Main.sessionMode.connect('updated', () => { + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', () => { if (Main.sessionMode.allowSettings) return; - Main.sessionMode.disconnect(id); + Main.sessionMode.disconnect(this._sessionModeUpdatedid); + this._sessionModeUpdatedId = 0; this.close(); }); @@ -798,6 +799,10 @@ class NMWirelessDialog extends ModalDialog.ModalDialog { GLib.source_remove(this._scanTimeoutId); this._scanTimeoutId = 0; } + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedid); + this._sessionModeUpdatedId = 0; + } } _onScanTimeout() { @@ -1655,6 +1660,20 @@ class Indicator extends PanelMenu.SystemIndicator { this._ctypes[NM.SETTING_VPN_SETTING_NAME] = NMConnectionCategory.VPN; this._getClient(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } } async _getClient() { @@ -1704,7 +1723,7 @@ class Indicator extends PanelMenu.SystemIndicator { this._client.connect('connection-added', this._connectionAdded.bind(this)); this._client.connect('connection-removed', this._connectionRemoved.bind(this)); - Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); this._sessionUpdated(); } @@ -2057,6 +2076,7 @@ class Indicator extends PanelMenu.SystemIndicator { if (this._portalHelperProxy) { this._portalHelperProxy.AuthenticateRemote(path, '', timestamp); } else { + this._cancellable = new Gio.Cancellable(); new PortalHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PortalHelper', '/org/gnome/Shell/PortalHelper', (proxy, error) => { if (error) { @@ -2068,7 +2088,8 @@ class Indicator extends PanelMenu.SystemIndicator { proxy.connectSignal('Done', this._portalHelperDone.bind(this)); proxy.AuthenticateRemote(path, '', timestamp); - }); + }, + this._cancellable); } this._connectivityQueue.push(path); -- GitLab From 18e0f2a4ad58dc9b8c10e71abe88967510fe9f30 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 08/25] nightLight: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/nightLight.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/js/ui/status/nightLight.js b/js/ui/status/nightLight.js index c595c3da02..5a3c1ae760 100644 --- a/js/ui/status/nightLight.js +++ b/js/ui/status/nightLight.js @@ -22,16 +22,18 @@ class Indicator extends PanelMenu.SystemIndicator { this._indicator = this._addIndicator(); this._indicator.icon_name = 'night-light-symbolic'; + this._cancellable = new Gio.Cancellable(); this._proxy = new ColorProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { log(error.message); return; } - this._proxy.connect('g-properties-changed', - this._sync.bind(this)); this._sync(); - }); + }, + this._cancellable); + this._proxyPropertiesChangedId = this._proxy.connect('g-properties-changed', + this._sync.bind(this)); this._item = new PopupMenu.PopupSubMenuMenuItem("", true); this._item.icon.icon_name = 'night-light-symbolic'; @@ -45,9 +47,28 @@ class Indicator extends PanelMenu.SystemIndicator { this._item.menu.addSettingsAction(_("Display Settings"), 'gnome-display-panel.desktop'); this.menu.addMenuItem(this._item); - Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); this._sessionUpdated(); this._sync(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + + if (this._proxyPropertiesChangedId) { + this._proxy.disconnect(this._proxyPropertiesChangedId); + this._proxyPropertiesChangedId = 0; + } + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } } _sessionUpdated() { -- GitLab From 07a09296150430853e4004dc2951e780ad8db2ef Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 09/25] power: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/power.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/js/ui/status/power.js b/js/ui/status/power.js index 0e8471fdfa..554503dc8e 100644 --- a/js/ui/status/power.js +++ b/js/ui/status/power.js @@ -23,8 +23,8 @@ class Indicator extends PanelMenu.SystemIndicator { super._init(); this._desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' }); - this._desktopSettings.connect('changed::%s'.format(SHOW_BATTERY_PERCENTAGE), - this._sync.bind(this)); + this._settingsChangedId = this._desktopSettings.connect('changed::%s'.format(SHOW_BATTERY_PERCENTAGE), + this._sync.bind(this)); this._indicator = this._addIndicator(); this._percentageLabel = new St.Label({ y_expand: true, @@ -32,23 +32,49 @@ class Indicator extends PanelMenu.SystemIndicator { this.add_child(this._percentageLabel); this.add_style_class_name('power-status'); + this._cancellable = new Gio.Cancellable(); this._proxy = new PowerManagerProxy(Gio.DBus.system, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { log(error.message); return; } - this._proxy.connect('g-properties-changed', - this._sync.bind(this)); this._sync(); - }); + }, + this._cancellable); + this._proxyPropertiesChangedId = this._proxy.connect('g-properties-changed', + this._sync.bind(this)); this._item = new PopupMenu.PopupSubMenuMenuItem("", true); this._item.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop'); this.menu.addMenuItem(this._item); - Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); this._sessionUpdated(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + + if (this._settingsChangedId) { + this._desktopSettings.disconnect(this._settingsChangedId); + this._settingsChangedId = 0; + } + + if (this._proxyPropertiesChangedId) { + this._proxy.disconnect(this._proxyPropertiesChangedId); + this._proxyPropertiesChangedId = 0; + } + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } } _sessionUpdated() { -- GitLab From 9dcc4e84609d85a6995d70624a9a62b78e01bb9a Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 10/25] remoteAccess: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/remoteAccess.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/ui/status/remoteAccess.js b/js/ui/status/remoteAccess.js index feafe61550..afbd69273f 100644 --- a/js/ui/status/remoteAccess.js +++ b/js/ui/status/remoteAccess.js @@ -11,9 +11,9 @@ class RemoteAccessApplet extends PanelMenu.SystemIndicator { _init() { super._init(); - let controller = global.backend.get_remote_access_controller(); + this._controller = global.backend.get_remote_access_controller(); - if (!controller) + if (!this._controller) return; // We can't possibly know about all types of screen sharing on X11, so @@ -28,9 +28,18 @@ class RemoteAccessApplet extends PanelMenu.SystemIndicator { this._recordingIndicator = null; this._menuSection = null; - controller.connect('new-handle', (o, handle) => { + this._controllerNewHandleId = this._controller.connect('new-handle', (o, handle) => { this._onNewHandle(handle); }); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._controllerNewHandleId) { + this._controller.disconnect(this._controllerNewHandleId); + this._controllerNewHandleId = 0; + } } _ensureControls() { -- GitLab From 188ad0334018b45ab72372aadfbc9818f3c12082 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 11/25] rfkill: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/rfkill.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/js/ui/status/rfkill.js b/js/ui/status/rfkill.js index 9f8b09dd2e..987c0aa150 100644 --- a/js/ui/status/rfkill.js +++ b/js/ui/status/rfkill.js @@ -67,7 +67,7 @@ class Indicator extends PanelMenu.SystemIndicator { super._init(); this._manager = getRfkillManager(); - this._manager.connect('airplane-mode-changed', this._sync.bind(this)); + this._airplaneModeChangedId = this._manager.connect('airplane-mode-changed', this._sync.bind(this)); this._indicator = this._addIndicator(); this._indicator.icon_name = 'airplane-mode-symbolic'; @@ -84,10 +84,24 @@ class Indicator extends PanelMenu.SystemIndicator { this._item.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop'); this.menu.addMenuItem(this._item); - Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); this._sessionUpdated(); this._sync(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._airplaneModeChangedId) { + this._manager.disconnect(this._airplaneModeChangedId); + this._airplaneModeChangedId = 0; + } + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } } _sessionUpdated() { -- GitLab From 86bbf3f159fdee946f662b867f19577c518f48c2 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:49:22 -0300 Subject: [PATCH 12/25] system: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/system.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/js/ui/status/system.js b/js/ui/status/system.js index e64b62cf4e..baee673fb3 100644 --- a/js/ui/status/system.js +++ b/js/ui/status/system.js @@ -39,8 +39,22 @@ class Indicator extends PanelMenu.SystemIndicator { }); this._updateSessionSubMenu(); - Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); this._sessionUpdated(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } + + if (this._orientationLockIconChangedId) { + this._systemActions.disconnect(this._orientationLockIconChangedId); + this._orientationLockIconChangedId = 0; + } } _sessionUpdated() { @@ -73,7 +87,7 @@ class Indicator extends PanelMenu.SystemIndicator { this._orientationLockItem, 'visible', bindFlags); - this._systemActions.connect('notify::orientation-lock-icon', () => { + this._orientationLockIconChangedId = this._systemActions.connect('notify::orientation-lock-icon', () => { let iconName = this._systemActions.orientation_lock_icon; let labelText = this._systemActions.getName("lock-orientation"); -- GitLab From 8bf030ce38502cb844f1abb0f9dafc4b3685b4ac Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 13/25] thunderbolt: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/thunderbolt.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/js/ui/status/thunderbolt.js b/js/ui/status/thunderbolt.js index d98355deeb..ca83f928b1 100644 --- a/js/ui/status/thunderbolt.js +++ b/js/ui/status/thunderbolt.js @@ -141,6 +141,11 @@ var AuthRobot = class { } close() { + if (this._enrollDevicesIdleId) { + GLib.source_remove(this._enrollDevicesIdleId); + this._enrollDevicesIdleId = 0; + } + this.disconnectAll(); this._client = null; } @@ -184,11 +189,13 @@ var AuthRobot = class { return; this._enrolling = true; - GLib.idle_add(GLib.PRIORITY_DEFAULT, - this._enrollDevicesIdle.bind(this)); + this._enrollDevicesIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT, + this._enrollDevicesIdle.bind(this)); } _onEnrollDone(device, error) { + this._enrollDeviceDoneId = 0; + if (error) this.emit('enroll-failed', device, error); @@ -199,12 +206,14 @@ var AuthRobot = class { this._enrolling = this._devicesToEnroll.length > 0; if (this._enrolling) { - GLib.idle_add(GLib.PRIORITY_DEFAULT, - this._enrollDevicesIdle.bind(this)); + this._enrollDevicesIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT, + this._enrollDevicesIdle.bind(this)); } } _enrollDevicesIdle() { + this._enrollDevicesIdleId = 0; + let devices = this._devicesToEnroll; let dev = devices.shift(); @@ -237,12 +246,15 @@ class Indicator extends PanelMenu.SystemIndicator { this._robot.connect('enroll-device', this._onEnrollDevice.bind(this)); this._robot.connect('enroll-failed', this._onEnrollFailed.bind(this)); - Main.sessionMode.connect('updated', this._sync.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sync.bind(this)); + this._sync(); this._source = null; this._perm = null; this._createPermission(); + + this.connect('destroy', this._onDestroy.bind(this)); } async _createPermission() { @@ -256,6 +268,11 @@ class Indicator extends PanelMenu.SystemIndicator { _onDestroy() { this._robot.close(); this._client.close(); + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } } _ensureSource() { -- GitLab From 86b86ce795dba6d9344bd52d2b437e128e10c532 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:42:25 -0300 Subject: [PATCH 14/25] volume: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/volume.js | 79 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/js/ui/status/volume.js b/js/ui/status/volume.js index 7b50658715..2345fdf7fe 100644 --- a/js/ui/status/volume.js +++ b/js/ui/status/volume.js @@ -36,7 +36,8 @@ var StreamSlider = class { this._slider = new Slider.Slider(0); this._soundSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.sound' }); - this._soundSettings.connect('changed::%s'.format(ALLOW_AMPLIFIED_VOLUME_KEY), this._amplifySettingsChanged.bind(this)); + this._settingsChangedId = this._soundSettings.connect('changed::%s'.format(ALLOW_AMPLIFIED_VOLUME_KEY), + this._amplifySettingsChanged.bind(this)); this._amplifySettingsChanged(); this._sliderChangedId = this._slider.connect('notify::value', @@ -65,6 +66,21 @@ var StreamSlider = class { this._icons = []; } + destroy() { + if (this._settingsChangedId) { + this._soundSettings.disconnect(this._settingsChangedId); + this._settingsChangedId = 0; + } + if (this._mutedChangedId) { + this._stream.disconnect(this._mutedChangedId); + this._mutedChangedId = 0; + } + if (this._volumeChangedId) { + this._stream.disconnect(this._volumeChangedId); + this._volumeChangedId = 0; + } + } + get stream() { return this._stream; } @@ -224,6 +240,15 @@ var OutputStreamSlider = class extends StreamSlider { ]; } + destroy() { + if (this._portChangedId) { + this._stream.disconnect(this._portChangedId); + this._portChangedId = 0; + } + + super.destroy(); + } + _connectStream(stream) { super._connectStream(stream); this._portChangedId = stream.connect('notify::port', this._portChanged.bind(this)); @@ -270,8 +295,8 @@ var InputStreamSlider = class extends StreamSlider { constructor(control) { super(control); this._slider.accessible_name = _("Microphone"); - this._control.connect('stream-added', this._maybeShowInput.bind(this)); - this._control.connect('stream-removed', this._maybeShowInput.bind(this)); + this._streamAddedId = this._control.connect('stream-added', this._maybeShowInput.bind(this)); + this._streamRemovedId = this._control.connect('stream-removed', this._maybeShowInput.bind(this)); this._icon.icon_name = 'audio-input-microphone-symbolic'; this._icons = [ 'microphone-sensitivity-muted-symbolic', @@ -281,6 +306,19 @@ var InputStreamSlider = class extends StreamSlider { ]; } + destroy() { + if (this._streamAddedId) { + this._control.disconnect(this._streamAddedId); + this._streamAddedId = 0; + } + if (this._streamRemovedId) { + this._control.disconnect(this._streamRemovedId); + this._streamRemovedId = 0; + } + + super.destroy(); + } + _connectStream(stream) { super._connectStream(stream); this._maybeShowInput(); @@ -318,9 +356,9 @@ var VolumeMenu = class extends PopupMenu.PopupMenuSection { this.hasHeadphones = false; this._control = control; - this._control.connect('state-changed', this._onControlStateChanged.bind(this)); - this._control.connect('default-sink-changed', this._readOutput.bind(this)); - this._control.connect('default-source-changed', this._readInput.bind(this)); + this._stateChangedId = this._control.connect('state-changed', this._onControlStateChanged.bind(this)); + this._defaultSinkChangedId = this._control.connect('default-sink-changed', this._readOutput.bind(this)); + this._defaultSourceChangedId = this._control.connect('default-source-changed', this._readInput.bind(this)); this._output = new OutputStreamSlider(this._control); this._output.connect('stream-updated', () => { @@ -342,6 +380,35 @@ var VolumeMenu = class extends PopupMenu.PopupMenuSection { this._onControlStateChanged(); } + destroy() { + if (this._stateChangedId) { + this._control.disconnect(this._stateChangedId); + this._stateChangedId = 0; + } + + if (this._defaultSinkChangedId) { + this._control.disconnect(this._defaultSinkChangedId); + this._defaultSinkChangedId = 0; + } + + if (this._defaultSourceChangedId) { + this._control.disconnect(this._defaultSourceChangedId); + this._defaultSourceChangedId = 0; + } + + if (this._input) { + this._input.destroy(); + this._input = null; + } + + if (this._output) { + this._output.destroy(); + this._output = null; + } + + super.destroy(); + } + scroll(event) { return this._output.scroll(event); } -- GitLab From 725a17a0bb531bc3442dcd1a415d6cf80755548c Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:53:40 -0300 Subject: [PATCH 15/25] dateMenu: Disconnect signals/sources on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/dateMenu.js | 175 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 147 insertions(+), 28 deletions(-) diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js index 13d1d4019d..ef69b7be5c 100644 --- a/js/ui/dateMenu.js +++ b/js/ui/dateMenu.js @@ -121,9 +121,30 @@ class EventsSection extends St.Button { this.child.add_child(this._eventsList); this._appSys = Shell.AppSystem.get_default(); - this._appSys.connect('installed-changed', + this._installedChangedId = this._appSys.connect('installed-changed', this._appInstalledChanged.bind(this)); this._appInstalledChanged(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._installedChangedId) { + this._appSys.disconnect(this._installedChangedId); + this._installedChangedId = 0; + } + + if (this._eventSource) { + if (this._eventSourceChangedId) { + this._eventSource.disconnect(this._eventSourceChangedId); + this._eventSourceChangedId = 0; + } + if (this._eventSourceHasCalendarsId) { + this._eventSource.disconnect(this._eventSourceHasCalendarsId); + this._eventSourceHasCalendarsId = 0; + } + this._eventSource = null; + } } setDate(date) { @@ -139,9 +160,21 @@ class EventsSection extends St.Button { if (!(eventSource instanceof Calendar.EventSourceBase)) throw new Error('Event source is not valid type'); + if (this._eventSource) { + if (this._eventSourceChangedId) { + this._eventSource.disconnect(this._eventSourceChangedId); + this._eventSourceChangedId = 0; + } + if (this._eventSourceHasCalendarsId) { + this._eventSource.disconnect(this._eventSourceHasCalendarsId); + this._eventSourceHasCalendarsId = 0; + } + } + this._eventSource = eventSource; - this._eventSource.connect('changed', this._reloadEvents.bind(this)); - this._eventSource.connect('notify::has-calendars', + this._eventSourceChangedId = this._eventSource.connect('changed', + this._reloadEvents.bind(this)); + this._eventSourceHasCalendarsId = this._eventSource.connect('notify::has-calendars', this._sync.bind(this)); this._sync(); } @@ -293,24 +326,59 @@ class WorldClocksSection extends St.Button { this.child = this._grid; this._clocksApp = null; + this._cancellable = new Gio.Cancellable(); this._clocksProxy = new ClocksProxy( Gio.DBus.session, 'org.gnome.clocks', '/org/gnome/clocks', this._onProxyReady.bind(this), - null /* cancellable */, + this._cancellable, Gio.DBusProxyFlags.DO_NOT_AUTO_START | Gio.DBusProxyFlags.GET_INVALIDATED_PROPERTIES); this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell.world-clocks', }); - this._settings.connect('changed', this._clocksChanged.bind(this)); + this._clocksChangedId = this._settings.connect('changed', this._clocksChanged.bind(this)); this._clocksChanged(); this._appSystem = Shell.AppSystem.get_default(); - this._appSystem.connect('installed-changed', + this._installedChangedId = this._appSystem.connect('installed-changed', this._sync.bind(this)); this._sync(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + + if (this._proxyPropertiesChangedId) { + this._clocksProxy.disconnect(this._proxyPropertiesChangedId); + this._proxyPropertiesChangedId = 0; + } + + if (this._installedChangedId) { + this._appSys.disconnect(this._installedChangedId); + this._installedChangedId = 0; + } + + if (this._clocksChangedId) { + this._settings.disconnect(this._clocksChangedId); + this._clocksChangedId = 0; + } + + if (this._clockNotifyId) { + this._clock.disconnect(this._clockNotifyId); + this._clockNotifyId = 0; + } + + if (this._tzNotifyId) { + this._clock.disconnect(this._tzNotifyId); + this._tzNotifyId = 0; + } } vfunc_clicked() { @@ -452,7 +520,7 @@ class WorldClocksSection extends St.Button { return; } - this._clocksProxy.connect('g-properties-changed', + this._proxyPropertiesChangedId = this._clocksProxy.connect('g-properties-changed', this._onClocksPropertiesChanged.bind(this)); this._onClocksPropertiesChanged(); } @@ -510,8 +578,17 @@ class WeatherSection extends St.Button { layout.hookup_style(this._forecastGrid); box.add_child(this._forecastGrid); - this._weatherClient.connect('changed', this._sync.bind(this)); + this._weatherChangedId = this._weatherClient.connect('changed', this._sync.bind(this)); this._sync(); + + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._weatherChangedId) { + this._weatherClient.disconnect(this._weatherChangedId); + this._weatherChangedId = 0; + } } vfunc_map() { @@ -669,43 +746,70 @@ class MessagesIndicator extends St.Icon { y_align: Clutter.ActorAlign.CENTER, }); - this._sources = []; + this._sources = {}; this._count = 0; this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.notifications', }); - this._settings.connect('changed::show-banners', this._sync.bind(this)); + this._showBannersChangedId = this._settings.connect('changed::show-banners', this._sync.bind(this)); - Main.messageTray.connect('source-added', this._onSourceAdded.bind(this)); - Main.messageTray.connect('source-removed', this._onSourceRemoved.bind(this)); - Main.messageTray.connect('queue-changed', this._updateCount.bind(this)); + this._sourceAddedId = Main.messageTray.connect('source-added', this._onSourceAdded.bind(this)); + this._sourceRemovedId = Main.messageTray.connect('source-removed', this._onSourceRemoved.bind(this)); + this._queueChangedId = Main.messageTray.connect('queue-changed', this._updateCount.bind(this)); let sources = Main.messageTray.getSources(); sources.forEach(source => this._onSourceAdded(null, source)); this._sync(); - this.connect('destroy', () => { - this._settings.run_dispose(); - this._settings = null; - }); + this.connect('destroy', this._onDestroy.bind(this)); + } + + _onDestroy() { + if (this._showBannersChangedId) { + this._settings.disconnect(this._showBannersChangedId); + this._showBannersChangedId = 0; + } + + if (this._sourceAddedId) { + Main.messageTray.disconnect(this._sourceAddedId); + this._sourceAddedId = 0; + } + if (this._sourceRemovedId) { + Main.messageTray.disconnect(this._sourceRemovedId); + this._sourceRemovedId = 0; + } + if (this._queueChangedId) { + Main.messageTray.disconnect(this._queueChangedId); + this._queueChangedId = 0; + } + + for (let source in this._sources) { + let countChangedId = this._sources[source]; + source.disconnect(countChangedId); + } + this._sources = {}; } _onSourceAdded(tray, source) { - source.connect('notify::count', this._updateCount.bind(this)); - this._sources.push(source); + let countChangedId = source.connect('notify::count', this._updateCount.bind(this)); + this._sources[source] = countChangedId; this._updateCount(); } _onSourceRemoved(tray, source) { - this._sources.splice(this._sources.indexOf(source), 1); + let countChangedId = this._sources[source]; + if (countChangedId) + source.disconnect(countChangedId); + delete this._sources[source]; this._updateCount(); } _updateCount() { let count = 0; - this._sources.forEach(source => (count += source.unseenCount)); + for (let source in this._sources) + count += source.unseenCount; this._count = count - Main.messageTray.queueCount; this._sync(); @@ -872,24 +976,39 @@ class DateMenuButton extends PanelMenu.Button { this._clock = new GnomeDesktop.WallClock(); this._clock.bind_property('clock', this._clockDisplay, 'text', GObject.BindingFlags.SYNC_CREATE); - this._clock.connect('notify::timezone', this._updateTimeZone.bind(this)); + this._tzNotifyId = this._clock.connect('notify::timezone', this._updateTimeZone.bind(this)); - Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); + this._sessionModeUpdatedId = Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); this._sessionUpdated(); } - _getEventSource() { - return new Calendar.DBusEventSource(); + _onDestroy() { + super._onDestroy(); + + if (this._sessionModeUpdatedId) { + Main.sessionMode.disconnect(this._sessionModeUpdatedId); + this._sessionModeUpdatedId = 0; + } + + if (this._tzNotifyId) { + this._clock.disconnect(this._tzNotifyId); + this._tzNotifyId = 0; + } + + if (this._eventSource) { + this._eventSource.destroy(); + this._eventSource = null; + } } _setEventSource(eventSource) { if (this._eventSource) this._eventSource.destroy(); + this._eventSource = eventSource; + this._calendar.setEventSource(eventSource); this._eventsItem.setEventSource(eventSource); - - this._eventSource = eventSource; } _updateTimeZone() { @@ -905,7 +1024,7 @@ class DateMenuButton extends PanelMenu.Button { let eventSource; let showEvents = Main.sessionMode.showCalendarEvents; if (showEvents) - eventSource = this._getEventSource(); + eventSource = new Calendar.DBusEventSource(); else eventSource = new Calendar.EmptyEventSource(); -- GitLab From b0912584ba84d8241748b6ee75a4d5bbe68060e4 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:50:25 -0300 Subject: [PATCH 16/25] appDisplay: Disconnect parental controls signals on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/appDisplay.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 1c25dfe39b..4c527a7ad6 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -188,7 +188,7 @@ var BaseAppView = GObject.registerClass({ // Filter the apps through the user’s parental controls. this._parentalControlsManager = ParentalControlsManager.getDefault(); - this._parentalControlsManager.connect('app-filter-changed', () => { + this._appFilterChangedId = this._parentalControlsManager.connect('app-filter-changed', () => { this._redisplay(); }); @@ -206,6 +206,11 @@ var BaseAppView = GObject.registerClass({ } _onDestroy() { + if (this._appFilterChangedId) { + this._parentalControlsManager.disconnect(this._appFilterChangedId); + this._appFilterChangedId = 0; + } + this._removeDelayedMove(); this._disconnectDnD(); } -- GitLab From 7369c2d2d5f6a4179df2a01e6db3878fc750732a Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Mon, 3 Aug 2020 23:51:11 -0300 Subject: [PATCH 17/25] appDisplay: Do not return async search results if cancelled https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/appDisplay.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 4c527a7ad6..481934f69c 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -1367,7 +1367,8 @@ var AppSearchProvider = class AppSearchProvider { let initializedId = this._parentalControlsManager.connect('app-filter-changed', () => { if (this._parentalControlsManager.initialized) { this._parentalControlsManager.disconnect(initializedId); - this.getInitialResultSet(terms, callback, _cancellable); + if (!_cancellable || !_cancellable.is_cancelled()) + this.getInitialResultSet(terms, callback, _cancellable); } }); return; -- GitLab From 40cd789b6cb9dc4510ee1308ec0401456914e0f1 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 01:45:56 -0300 Subject: [PATCH 18/25] network: Also cancel promisified async calls on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/network.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 9b34dbb020..36591ef1c2 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -1640,6 +1640,8 @@ class Indicator extends PanelMenu.SystemIndicator { _init() { super._init(); + this._cancellable = new Gio.Cancellable(); + this._primaryIndicator = this._addIndicator(); this._vpnIndicator = this._addIndicator(); @@ -1677,7 +1679,13 @@ class Indicator extends PanelMenu.SystemIndicator { } async _getClient() { - this._client = await NM.Client.new_async(null); + try { + this._client = await NM.Client.new_async(this._cancellable); + } catch (e) { + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + logError(e); + return; + } this._activeConnections = []; this._connections = []; @@ -2039,10 +2047,14 @@ class Indicator extends PanelMenu.SystemIndicator { this._closeConnectivityCheck(path); } else if (result == PortalHelperResult.RECHECK) { try { - const state = await this._client.check_connectivity_async(null); + const state = await this._client.check_connectivity_async( + this._cancellable); if (state >= NM.ConnectivityState.FULL) this._closeConnectivityCheck(path); - } catch (e) { } + } catch (e) { + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + log('Failed to check connectivity status: %s'.format(e.toString())); + } } else { log('Invalid result from portal helper: %s'.format(result)); } @@ -2076,7 +2088,6 @@ class Indicator extends PanelMenu.SystemIndicator { if (this._portalHelperProxy) { this._portalHelperProxy.AuthenticateRemote(path, '', timestamp); } else { - this._cancellable = new Gio.Cancellable(); new PortalHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PortalHelper', '/org/gnome/Shell/PortalHelper', (proxy, error) => { if (error) { -- GitLab From cd27af97a6740508043ea0ecb7e53d1b5d50ca30 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 01:46:32 -0300 Subject: [PATCH 19/25] thunderbolt: Also cancel promisified async calls on destruction https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/thunderbolt.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/js/ui/status/thunderbolt.js b/js/ui/status/thunderbolt.js index ca83f928b1..d9c46b830c 100644 --- a/js/ui/status/thunderbolt.js +++ b/js/ui/status/thunderbolt.js @@ -51,6 +51,7 @@ const BOLT_DBUS_PATH = '/org/freedesktop/bolt'; var Client = class { constructor() { + this._cancellable = new Gio.Cancellable(); this._proxy = null; this.probing = false; this._getProxy(); @@ -66,9 +67,10 @@ var Client = class { BOLT_DBUS_NAME, BOLT_DBUS_PATH, BOLT_DBUS_CLIENT_IFACE, - null); + this._cancellable); } catch (e) { - log('error creating bolt proxy: %s'.format(e.message)); + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + log('error creating bolt proxy: %s'.format(e.message)); return; } this._propsChangedId = this._proxy.connect('g-properties-changed', this._onPropertiesChanged.bind(this)); @@ -99,6 +101,11 @@ var Client = class { /* public methods */ close() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + if (!this._proxy) return; @@ -235,6 +242,8 @@ class Indicator extends PanelMenu.SystemIndicator { _init() { super._init(); + this._cancellable = new Gio.Cancellable(); + this._indicator = this._addIndicator(); this._indicator.icon_name = 'thunderbolt-symbolic'; @@ -259,13 +268,20 @@ class Indicator extends PanelMenu.SystemIndicator { async _createPermission() { try { - this._perm = await Polkit.Permission.new('org.freedesktop.bolt.enroll', null, null); + this._perm = await Polkit.Permission.new('org.freedesktop.bolt.enroll', null, + this._cancellable); } catch (e) { - log('Failed to get PolKit permission: %s'.format(e.toString())); + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + log('Failed to get PolKit permission: %s'.format(e.toString())); } } _onDestroy() { + if (this._cancellable) { + this._cancellable.cancel(); + this._cancellable = null; + } + this._robot.close(); this._client.close(); -- GitLab From d67323e7c82c442c0c2af7e1736c862800a12058 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 02:46:13 -0300 Subject: [PATCH 20/25] bluetooth: Don't log cancelled D-Bus operations https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/bluetooth.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index a7b0cea46d..8edfa6ea66 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -30,7 +30,9 @@ class Indicator extends PanelMenu.SystemIndicator { this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { - log(error.message); + if (!error.matches(Gio.IOErrorEnum, + Gio.IOErrorEnum.CANCELLED)) + log(error.message); return; } this._sync(); -- GitLab From 7e6f503f94cf3e81cc0f8e0de5d0cb8791b335d3 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 02:46:13 -0300 Subject: [PATCH 21/25] brightness: Don't log cancelled D-Bus operations https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/brightness.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/ui/status/brightness.js b/js/ui/status/brightness.js index 0c2e8e485e..66915c0eaa 100644 --- a/js/ui/status/brightness.js +++ b/js/ui/status/brightness.js @@ -23,7 +23,9 @@ class Indicator extends PanelMenu.SystemIndicator { this._proxy = new BrightnessProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { - log(error.message); + if (!error.matches(Gio.IOErrorEnum, + Gio.IOErrorEnum.CANCELLED)) + log(error.message); return; } this._sync(); -- GitLab From 58682a80a5a0e669163bf0ffe4197c009f6bb43f Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 02:46:13 -0300 Subject: [PATCH 22/25] location: Don't log cancelled D-Bus operations https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/location.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/ui/status/location.js b/js/ui/status/location.js index d1519b4af4..ba69ded8a6 100644 --- a/js/ui/status/location.js +++ b/js/ui/status/location.js @@ -167,7 +167,8 @@ class Indicator extends PanelMenu.SystemIndicator { _onManagerProxyReady(proxy, error) { if (error != null) { - log(error.message); + if (!error.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + log(error.message); this._connecting = false; return; } @@ -260,7 +261,8 @@ class Indicator extends PanelMenu.SystemIndicator { _onPermStoreProxyReady(proxy, error) { if (error != null) { - log(error.message); + if (!error.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + log(error.message); return; } -- GitLab From 6a073004835ff0bc2ddccae01754209f5e6a2994 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 02:46:13 -0300 Subject: [PATCH 23/25] nightLight: Don't log cancelled D-Bus operations https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/nightLight.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/ui/status/nightLight.js b/js/ui/status/nightLight.js index 5a3c1ae760..d7d1a4d6d2 100644 --- a/js/ui/status/nightLight.js +++ b/js/ui/status/nightLight.js @@ -26,7 +26,8 @@ class Indicator extends PanelMenu.SystemIndicator { this._proxy = new ColorProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { - log(error.message); + if (!error.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + log(error.message); return; } this._sync(); -- GitLab From a914b584a59f4b9936c7565202b4d65247d01b00 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 02:46:13 -0300 Subject: [PATCH 24/25] power: Don't log cancelled D-Bus operations https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/power.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/ui/status/power.js b/js/ui/status/power.js index 554503dc8e..e5f581a688 100644 --- a/js/ui/status/power.js +++ b/js/ui/status/power.js @@ -36,7 +36,9 @@ class Indicator extends PanelMenu.SystemIndicator { this._proxy = new PowerManagerProxy(Gio.DBus.system, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { - log(error.message); + if (!error.matches(Gio.IOErrorEnum, + Gio.IOErrorEnum.CANCELLED)) + log(error.message); return; } this._sync(); -- GitLab From 26247381e2f04df7232b63e47d577794c5c20293 Mon Sep 17 00:00:00 2001 From: Andre Moreira Magalhaes Date: Thu, 6 Aug 2020 02:46:13 -0300 Subject: [PATCH 25/25] rfkill: Don't log cancelled D-Bus operations https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1392 --- js/ui/status/rfkill.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/ui/status/rfkill.js b/js/ui/status/rfkill.js index 987c0aa150..3732ec1d5c 100644 --- a/js/ui/status/rfkill.js +++ b/js/ui/status/rfkill.js @@ -21,7 +21,9 @@ var RfkillManager = class { this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, (proxy, error) => { if (error) { - log(error.message); + if (!error.matches(Gio.IOErrorEnum, + Gio.IOErrorEnum.CANCELLED)) + log(error.message); return; } this._proxy.connect('g-properties-changed', -- GitLab