From 2c1d345dd5bc0628a97c813f3573d7e739e462f3 Mon Sep 17 00:00:00 2001 From: Qwreey Date: Wed, 3 May 2023 02:59:41 +0900 Subject: [PATCH] Add onMenuItemAdded to fix #73 #65 --- extension.js | 20 +++++++++++++++++--- features/buttonRemover.js | 12 +++++++----- features/volumeMixer.js | 10 ++++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/extension.js b/extension.js index 24c13a6..d199c98 100644 --- a/extension.js +++ b/extension.js @@ -13,7 +13,7 @@ class Extension { // unload menu open tracker QuickSettingsGrid.disconnect(this.menuOpenTracker) - this.menuOpenTracker = null + QuickSettingsGrid.disconnect(this.menuItemAddedTracker) // unload features for (const feature of this.features) { @@ -21,7 +21,9 @@ class Extension { feature.unload() feature.settings = null } - this.features = null + + // Null out + this.menuItemAddedTracker = this.features = this.updating = this.menuOpenTracker = null logger("Diabled. " + (+new Date() - start) + "ms taken") } @@ -52,12 +54,24 @@ class Extension { } // load menu open tracker + this.updating = false this.menuOpenTracker = QuickSettingsGrid.connect("notify::mapped",()=>{ if (!QuickSettingsGrid.mapped) return - logger(`Update layout`) + this.updating = true for (const feature of this.features) { if (feature.onMenuOpen) feature.onMenuOpen() } + this.updating = false + }) + + // load menu item added tracker + this.menuItemAddedTracker = QuickSettingsGrid.connect("actor-added",()=>{ + if (this.updating) return + this.updating = true + for (const feature of this.features) { + if (feature.onMenuItemAdded) feature.onMenuItemAdded() + } + this.updating = false }) logger("Loaded. " + (+Date.now() - start) + "ms taken") diff --git a/features/buttonRemover.js b/features/buttonRemover.js index 1bf85fe..417a766 100644 --- a/features/buttonRemover.js +++ b/features/buttonRemover.js @@ -1,7 +1,5 @@ // forked from https://github.com/qwreey75/gnome-quick-settings-button-remover -// ! NEED TO REWRITE - const ExtensionUtils = imports.misc.extensionUtils const Me = ExtensionUtils.getCurrentExtension() @@ -13,6 +11,10 @@ var buttonRemoverFeature = class { this.removedItems = [] this.visibleListeners = [] } + onMenuItemAdded() { + this._unapply() + this._apply(this.userRemovedItems) + } _apply(removedItems) { for (const item of QuickSettingsGrid.get_children()) { let name = item.constructor.name.toString() @@ -50,9 +52,9 @@ var buttonRemoverFeature = class { this.settings.set_string("list-buttons",JSON.stringify(listButtons)) } - let items = this.settings.get_strv("user-removed-buttons") + let items = this.userRemovedItems = this.settings.get_strv("user-removed-buttons") if (!items) { - items = [] + items = this.userRemovedItems = [] this.settings.set_strv("user-removed-buttons",items) } @@ -61,7 +63,7 @@ var buttonRemoverFeature = class { this._removedItemsConnection = this.settings.connect('changed::user-removed-buttons', (settings, key) => { this._unapply() - this._apply(this.settings.get_strv("user-removed-buttons")) + this._apply(this.userRemovedItems = this.settings.get_strv("user-removed-buttons")) }) } unload() { diff --git a/features/volumeMixer.js b/features/volumeMixer.js index eb09e43..d74846b 100644 --- a/features/volumeMixer.js +++ b/features/volumeMixer.js @@ -8,10 +8,12 @@ const { QuickSettingsGrid } = Me.imports.libs.gnome var volumeMixerFeature = class { onMenuOpen() { // reorder on menu open - QuickSettingsGrid.set_child_below_sibling( - this.volumeMixer.actor, - this._getInputStreamSlider() - ) + if (this.volumeMixer) { + QuickSettingsGrid.set_child_below_sibling( + this.volumeMixer.actor, + this._getInputStreamSlider() + ) + } } _getInputStreamSlider() {