Skip to content

Commit

Permalink
Add onMenuItemAdded to fix #73 #65
Browse files Browse the repository at this point in the history
  • Loading branch information
qwreey committed May 2, 2023
1 parent 6e23b41 commit 2c1d345
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
20 changes: 17 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ 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) {
logger(`Unload feature '${feature.constructor.name}'`)
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")
}
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 7 additions & 5 deletions features/buttonRemover.js
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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()
Expand Down Expand Up @@ -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)
}

Expand All @@ -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() {
Expand Down
10 changes: 6 additions & 4 deletions features/volumeMixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2c1d345

Please sign in to comment.