Skip to content

Commit

Permalink
Merge pull request #85 from qwreey75/dev
Browse files Browse the repository at this point in the history
Stable 1.18
  • Loading branch information
qwreey authored May 2, 2023
2 parents 0f8a281 + 2c1d345 commit 816e094
Show file tree
Hide file tree
Showing 23 changed files with 738 additions and 531 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ install: build

dev: install
ifeq ($(XDG_SESSION_TYPE),x11)
pkill gnome-shell &
busctl --user call org.gnome.Shell /org/gnome/Shell org.gnome.Shell Eval s 'Meta.restart("Restarting…", global.context)'
endif

log:
journalctl /usr/bin/gnome-shell -f -q --output cat | grep '\[EXTENSION QSTweaks\] '
83 changes: 55 additions & 28 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,79 @@ const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()
const Features = Me.imports.features
const { logger } = Me.imports.libs.utility
const { QuickSettingsGrid } = Me.imports.libs.gnome
const { GLib } = imports.gi

class Extension {
constructor() {
logger("Init")
this.features = [
new Features.dndQuickToggle.dndQuickToggleFeature(),
new Features.notifications.notificationsFeature(),
new Features.volumeMixer.volumeMixerFeature(),
new Features.dateMenu.dateMenuFeature(),
new Features.buttonRemover.buttonRemoverFeature(),
new Features.inputOutput.inputOutputFeature()
]
}
constructor() {}
disable() {
logger("Unloading ...")

if (this.timeout) {
GLib.Source.remove(this.timeout)
this.timeout = null
}
let start = +Date.now()

// unload menu open tracker
QuickSettingsGrid.disconnect(this.menuOpenTracker)
QuickSettingsGrid.disconnect(this.menuItemAddedTracker)

// unload features
for (const feature of this.features) {
logger(`Unload feature '${feature.constructor.name}'`)
feature.unload()
feature.settings = null
}

logger("Diabled")

// Null out
this.menuItemAddedTracker = this.features = this.updating = this.menuOpenTracker = null

logger("Diabled. " + (+new Date() - start) + "ms taken")
}
enable() {
logger("Loading ...")

let start = +Date.now()

// load modules
this.features = [
new Features.dndQuickToggle.dndQuickToggleFeature(),
new Features.unsafeQuickToggle.unsafeQuickToggleFeature(),
new Features.notifications.notificationsFeature(),
new Features.volumeMixer.volumeMixerFeature(),
new Features.dateMenu.dateMenuFeature(),
new Features.buttonRemover.buttonRemoverFeature(),
new Features.inputOutput.inputOutputFeature(),
]

// load settings
let settings = ExtensionUtils.getSettings(Me.metadata['settings-schema'])
ExtensionUtils.initTranslations(Me.metadata['gettext-domain'])

// Add timeout for waitting other extensions such as GSConnect
// This is necessary behavior due to ordering qs panel
this.timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 400, () => {

// load features
for (const feature of this.features) {
logger(`Loading feature '${feature.constructor.name}'`)
feature.settings = settings
feature.load()
}

// load menu open tracker
this.updating = false
this.menuOpenTracker = QuickSettingsGrid.connect("notify::mapped",()=>{
if (!QuickSettingsGrid.mapped) return
this.updating = true
for (const feature of this.features) {
logger(`Loading feature '${feature.constructor.name}'`)
feature.settings = settings
feature.load()
if (feature.onMenuOpen) feature.onMenuOpen()
}
logger("Loaded")
return GLib.SOURCE_REMOVE
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
20 changes: 10 additions & 10 deletions features/buttonRemover.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// forked from https://github.com/qwreey75/gnome-quick-settings-button-remover

// ! NEED TO REWRITE

const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()

const featureReloader = Me.imports.libs.featureReloader
const { featureReloader } = Me.imports.libs.utility
const { QuickSettingsGrid } = Me.imports.libs.gnome

var buttonRemoverFeature = class {
constructor() {
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,20 +52,18 @@ var buttonRemoverFeature = class {
this.settings.set_string("list-buttons",JSON.stringify(listButtons))
}

let items; {
items = this.settings.get_strv("user-removed-buttons")
if (!items) {
items = []
this.settings.set_strv("user-removed-buttons",items)
}
let items = this.userRemovedItems = this.settings.get_strv("user-removed-buttons")
if (!items) {
items = this.userRemovedItems = []
this.settings.set_strv("user-removed-buttons",items)
}

this._apply(items)

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
116 changes: 57 additions & 59 deletions features/dateMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,72 @@ const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()
const { GLib } = imports.gi

const featureReloader = Me.imports.libs.featureReloader
const { featureReloader } = Me.imports.libs.utility
const {
DateMenuNotifications,
DateMenuMediaControl,
DateMenuHolder,
DateMenuBox
DateMenuNotifications,
DateMenuMediaControl,
DateMenuHolder,
DateMenuBox,
} = Me.imports.libs.gnome
const { Indicator } = Me.imports.libs.dndQuickToogleHandler
const { Indicator } = Me.imports.libs.dndQuickToggleHandler

var dateMenuFeature = class {
load() {
// setup reloader
featureReloader.enableWithSettingKeys(this,[
"datemenu-remove-media-control",
"datemenu-remove-notifications",
"datemenu-fix-weather-widget"
])
load() {
// setup reloader
featureReloader.enableWithSettingKeys(this, [
"datemenu-remove-media-control",
"datemenu-remove-notifications",
"datemenu-fix-weather-widget",
])

// remove media control from date menu
if (this.settings.get_boolean("datemenu-remove-media-control")) {
this.dateMenuMediaControlRemoved = true
DateMenuMediaControl.hide()
this.dateMenuMediaControlConnection = DateMenuMediaControl.connect("show", ()=>{
DateMenuMediaControl.hide()
})
}
// remove media control from date menu
if (this.settings.get_boolean("datemenu-remove-media-control")) {
this.dateMenuMediaControlRemoved = true
DateMenuMediaControl.hide()
this.dateMenuMediaControlConnection = DateMenuMediaControl.connect(
"show",DateMenuMediaControl.hide.bind(DateMenuMediaControl)
)
}

// remove notifications from date menu
if (this.settings.get_boolean("datemenu-remove-notifications")) {
this.dateMenuNotificationsRemoved = true
DateMenuNotifications.hide()
DateMenuBox.style = "padding: 4px 6px 4px 0px;"
this.dateMenuConnection = DateMenuNotifications.connect("show", ()=>{
DateMenuNotifications.hide()
})
}

// datemenu fix weather widget
if (this.settings.get_boolean("datemenu-fix-weather-widget")) {
this.weatherFixBackupClass = DateMenuBox.style_class
DateMenuBox.style_class += " qwreey-fixed-weather"
}
// remove notifications from date menu
if (this.settings.get_boolean("datemenu-remove-notifications")) {
this.dateMenuNotificationsRemoved = true
DateMenuNotifications.hide()
DateMenuBox.style = "padding: 4px 6px 4px 0px;"
this.dateMenuConnection = DateMenuNotifications.connect("show", DateMenuNotifications.hide.bind(DateMenuNotifications))
}

unload() {
// disable feature reloader
featureReloader.disable(this)
// datemenu fix weather widget
if (this.settings.get_boolean("datemenu-fix-weather-widget")) {
this.weatherFixBackupClass = DateMenuBox.style_class
DateMenuBox.style_class += " qwreey-fixed-weather"
}
}

// restore media control
if (this.dateMenuMediaControlRemoved) {
DateMenuMediaControl.disconnect(this.dateMenuMediaControlConnection)
if (DateMenuMediaControl._shouldShow()) DateMenuMediaControl.show()
this.dateMenuMediaControlRemoved = null
this.dateMenuMediaControlConnection = null
}
unload() {
// disable feature reloader
featureReloader.disable(this);

// restore notifications to date menu
if (this.dateMenuNotificationsRemoved) {
DateMenuNotifications.disconnect(this.dateMenuConnection)
DateMenuNotifications.show()
DateMenuBox.style = ""
this.dateMenuNotificationsRemoved = null
}
// undo weather fix
if (this.weatherFixBackupClass) {
DateMenuBox.style_class = this.weatherFixBackupClass
this.weatherFixBackupClass = null
}
// restore media control
if (this.dateMenuMediaControlRemoved) {
DateMenuMediaControl.disconnect(this.dateMenuMediaControlConnection);
if (DateMenuMediaControl._shouldShow()) DateMenuMediaControl.show();
this.dateMenuMediaControlRemoved = null;
this.dateMenuMediaControlConnection = null;
}
}

// restore notifications to date menu
if (this.dateMenuNotificationsRemoved) {
DateMenuNotifications.disconnect(this.dateMenuConnection);
DateMenuNotifications.show();
DateMenuBox.style = "";
this.dateMenuNotificationsRemoved = null;
}

// undo weather fix
if (this.weatherFixBackupClass) {
DateMenuBox.style_class = this.weatherFixBackupClass;
this.weatherFixBackupClass = null;
}
}
};
Loading

0 comments on commit 816e094

Please sign in to comment.