Skip to content

Commit

Permalink
Recreate the menu when settings change
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthayhurst committed May 21, 2022
1 parent 9269fff commit 67cbdf8
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function enable() {
privacyMenu = new Extension();

//Create menu
privacyMenu.createMenu();
privacyMenu.initMenu();
}

function disable() {
//Destroy the menu
privacyMenu.indicator.remove_all_children();
privacyMenu.indicator.destroy();
//Disconnect listeners, then destroy the indicator and class
privacyMenu.disconnectListeners();
privacyMenu.destroyMenu();
privacyMenu = null;
}

Expand Down Expand Up @@ -109,6 +109,21 @@ class Extension {
this.extensionSettings = ExtensionUtils.getSettings();
}

disconnectListeners() {
this.extensionSettings.disconnect(this._settingsChangedSignal);
}

initMenu() {
//Create the indicator
this.createMenu();

//When settings change, recreate the indicator
this._settingsChangedSignal = this.extensionSettings.connect('changed', () => {
this.destroyMenu();
this.createMenu();
});
}

createMenu() {
//Create and setup indicator and menu
this.indicator = new PrivacyMenu();
Expand All @@ -125,4 +140,10 @@ class Extension {
//Add to panel
Main.panel.addToStatusArea(Me.metadata.uuid, this.indicator, offset);
}

destroyMenu() {
//Destroy the indicator
this.indicator.remove_all_children();
this.indicator.destroy();
}
}

0 comments on commit 67cbdf8

Please sign in to comment.