Skip to content

Commit

Permalink
Better extension loading system
Browse files Browse the repository at this point in the history
  • Loading branch information
qwreey committed Nov 12, 2022
1 parent 5c937e1 commit e7eab27
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 65 deletions.
87 changes: 45 additions & 42 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,54 @@ const Me = ExtensionUtils.getCurrentExtension()
const Features = Me.imports.features
const { logger } = Me.imports.libs.utility
const { GLib } = imports.gi
var loaded
var timeout

// handling extension
function enable() {
logger("Loading ...")

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

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

// Add timeout for waitting other extensions such as GSConnect
// This is necessary behavior due to ordering qs panel
timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 400, () => {
for (const feature of loaded) {
logger(`Loading feature '${feature.constructor.name}'`)
feature.load()
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()
]
}
disable() {
logger("Unloading ...")

if (this.timeout) {
GLib.Source.remove(this.timeout)
this.timeout = null
}
logger("Loaded")
return GLib.SOURCE_REMOVE;
});
}

function disable() {
logger("Unloading ...")

if (timeout) {
GLib.Source.remove(timeout)
timeout = null
for (const feature of this.features) {
logger(`Unload feature '${feature.constructor.name}'`)
feature.unload()
feature.settings = null
}

logger("Diabled")
}
if (!loaded) return
for (const feature of loaded) {
logger(`Unload feature '${feature.constructor.name}'`)
feature.unload()
enable() {
logger("Loading ...")

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, () => {
for (const feature of this.features) {
logger(`Loading feature '${feature.constructor.name}'`)
feature.settings = settings
feature.load()
}
logger("Loaded")
return GLib.SOURCE_REMOVE
})
}
loaded = null
}

logger("Diabled")
function init(meta) {
return new Extension()
}
4 changes: 1 addition & 3 deletions features/buttonRemover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const featureReloader = Me.imports.libs.featureReloader
const { QuickSettingsGrid } = Me.imports.libs.gnome

var buttonRemoverFeature = class {
constructor(settings) {
this.settings = settings
constructor() {
this.removedItems = []
this.visibleListeners = []
}
Expand Down Expand Up @@ -70,6 +69,5 @@ var buttonRemoverFeature = class {
unload() {
this._unapply()
this.settings.disconnect(this._removedItemsConnection)
this.settings = null
}
}
4 changes: 0 additions & 4 deletions features/dateMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const {
const { Indicator } = Me.imports.libs.dndQuickToogleHandler

var dateMenuFeature = class {
constructor(settings) {
this.settings = settings
}

load() {
// setup reloader
featureReloader.enableWithSettingKeys(this,[
Expand Down
4 changes: 0 additions & 4 deletions features/dndQuickToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ const { QuickSettings } = Me.imports.libs.gnome
const { Indicator } = Me.imports.libs.dndQuickToogleHandler

var dndQuickToggleFeature = class {
constructor(settings) {
this.settings = settings
}

load() {
// setup reloader
featureReloader.enableWithSettingKeys(this,[
Expand Down
4 changes: 0 additions & 4 deletions features/inputOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ const Volume = imports.ui.status.volume
const PopupMenu = imports.ui.popupMenu;

var inputOutputFeature = class {
constructor(settings) {
this.settings = settings
}

load() {
// setup reloader
featureReloader.enableWithSettingKeys(this,[
Expand Down
4 changes: 0 additions & 4 deletions features/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const {
} = Me.imports.libs.gnome

var notificationsFeature = class {
constructor(settings) {
this.settings = settings
}

load() {
let settings = this.settings

Expand Down
4 changes: 0 additions & 4 deletions features/volumeMixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ const { QuickSettingsGrid } = Me.imports.libs.gnome
const { addChildWithIndex } = Me.imports.libs.utility

var volumeMixerFeature = class {
constructor(settings) {
this.settings = settings
}

load() {
let settings = this.settings

Expand Down

0 comments on commit e7eab27

Please sign in to comment.