Skip to content

Commit 22ce4a8

Browse files
committed
Disconnect settings on disable/destroy
We connect to setting change events, but never disconnect. Destroying the object doesn't disconnect the events. Disabling and re-enabling the extension then caused repeated updates. And locking and unlocking the screen caused the extension to be disabled and re-enabled. We now clean up the setting events when the object gets destroyed.
1 parent 440a669 commit 22ce4a8

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

extension.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,13 @@ class BingWallpaperIndicator extends Button {
220220

221221
// listen for configuration changes
222222
_setConnections() {
223-
this._settings.connect('changed::hide', () => {
224-
this.visible = !this._settings.get_boolean('hide');
225-
});
223+
this.settings_connections = [];
224+
225+
this.settings_connections.push(
226+
this._settings.connect('changed::hide', () => {
227+
this.visible = !this._settings.get_boolean('hide');
228+
})
229+
);
226230

227231
let settingConnections = [
228232
{signal: 'changed::icon-name', call: this._setIcon},
@@ -246,7 +250,9 @@ class BingWallpaperIndicator extends Button {
246250

247251
// _setShuffleToggleState
248252
settingConnections.forEach((e) => {
249-
this._settings.connect(e.signal, e.call.bind(this));
253+
this.settings_connections.push(
254+
this._settings.connect(e.signal, e.call.bind(this))
255+
);
250256
});
251257

252258
// ensure we're in a sensible initial state
@@ -281,10 +287,12 @@ class BingWallpaperIndicator extends Button {
281287
/*{key: 'random-mode-include-only-unhidden', toggle: this.toggleShuffleOnlyUnhidden},*/
282288
{key: 'random-mode-include-only-uhd', toggle: this.toggleShuffleOnlyUHD}];
283289

284-
toggles.forEach( (e) => {
285-
this._settings.connect('changed::'+e.key, () => {
286-
e.toggle.setToggleState(this._settings.get_boolean(e.key));
287-
});
290+
toggles.forEach( (e) => {
291+
this.settings_connections.push(
292+
this._settings.connect('changed::'+e.key, () => {
293+
e.toggle.setToggleState(this._settings.get_boolean(e.key));
294+
})
295+
);
288296
e.toggle.connect('toggled', (item, state) => {
289297
this._settings.set_boolean(e.key, state);
290298
});
@@ -301,6 +309,16 @@ class BingWallpaperIndicator extends Button {
301309
}
302310
}
303311

312+
_onDestroy() {
313+
this._unsetConnections();
314+
}
315+
316+
_unsetConnections() {
317+
this.settings_connections.forEach((e) => {
318+
this._settings.disconnect(e);
319+
});
320+
}
321+
304322
_openPrefs() {
305323
this._extension.openPreferences();
306324
}

0 commit comments

Comments
 (0)