Hi. Please, look at the code bellow:
const { GObject } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const PanelMenu = imports.ui.panelMenu;
const Me = ExtensionUtils.getCurrentExtension();
var Preferences = GObject.registerClass({
Signals: {
'prop1Changed': {},
'prop2Changed': {},
'prop3Changed': {},
},
}, class Preferences extends GObject.Object {
constructor() {
super();
this._keyProp1 = 'prop1';
this._keyProp2 = 'prop1';
this._keyProp3 = 'prop1';
this._settings = ExtensionUtils.getSettings();
this._settings.connect(`changed`, (...[, key]) => {
switch (key) {
case this._keyProp1: {
this.emit(`prop1Changed`);
break;
}
case this._keyProp2: {
this.emit(`prop2Changed`);
break;
}
case this._keyProp3: {
this.emit(`prop3Changed`);
break;
}
default:
break;
}
});
}
destroy() {
this._settings.run_dispose();
this.run_dispose();
}
get prop1() {
return this._settings.get_int(this._keyProp1);
}
get prop2() {
return this._settings.get_int(this._keyProp2);
}
get prop3() {
return this._settings.get_int(this._keyProp3);
}
});
const PanelIndicator = GObject.registerClass(
class PanelIndicator extends PanelMenu.Button {
constructor() {
super(0);
this._preferences = new Preferences();
this._preferences.connect(`prop1Changed`, () => {
log(`Prop1 changed ${this._preferences.prop1}`);
});
this._preferences.connect(`prop2Changed`, () => {
log(`Prop2 changed ${this._preferences.prop2}`);
});
this._preferences.connect(`prop3Changed`, () => {
log(`Prop3 changed ${this._preferences.prop3}`);
});
}
destroy() {
this._preferences.destroy();
super.destroy();
}
});
let panelIndicator;
function init() {
ExtensionUtils.initTranslations(Me.uuid);
}
function enable() {
panelIndicator = new PanelIndicator();
Main.panel.addToStatusArea(`${Me.metadata.name}`, panelIndicator);
}
function disable() {
panelIndicator.destroy();
panelIndicator = null;
}
Is it okay to use run_dispose()
in this way?