Make ui actually usable

This commit is contained in:
hodasemi 2023-03-16 07:43:38 +01:00
parent cd70b78487
commit ec4e3bca02

View file

@ -31,6 +31,8 @@ const PopupMenu = imports.ui.popupMenu;
const _ = ExtensionUtils.gettext; const _ = ExtensionUtils.gettext;
allowedRateElements = [];
const Indicator = GObject.registerClass( const Indicator = GObject.registerClass(
class Indicator extends PanelMenu.Button { class Indicator extends PanelMenu.Button {
_init() { _init() {
@ -42,21 +44,35 @@ const Indicator = GObject.registerClass(
})); }));
let sampleRate = getForcedSampleRate(); let sampleRate = getForcedSampleRate();
let currentSampleRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + sampleRate));
this.menu.addMenuItem(currentSampleRate);
let allowedRates = getAllowedSampleRates(); let allowedRates = getAllowedSampleRates();
allowedRateElements = [];
for (let i = 0; i < allowedRates.length; i++) { for (let i = 0; i < allowedRates.length; i++) {
let allowedRate = new PopupMenu.PopupMenuItem(_("Allowed Rates: " + allowedRates[i])); let allowedRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + allowedRates[i]));
if (allowedRates[i] == sampleRate) {
allowedRate.setOrnament(PopupMenu.Ornament.DOT);
}
allowedRate.connect('activate', () => { allowedRate.connect('activate', () => {
console.log("set sample rate " + allowedRates[i]); console.log("set sample rate " + allowedRates[i]);
for (let k = 0; k < allowedRateElements.length; k++) {
allowedRateElements[k].setOrnament(PopupMenu.Ornament.NONE);
}
setSampleRate(allowedRates[i]); setSampleRate(allowedRates[i]);
currentSampleRate.label.text = "Sample Rate: " + getForcedSampleRate();
// sanity check sample rate
let forcedRate = getForcedSampleRate();
if (forcedRate == allowedRates[i]) {
allowedRate.setOrnament(PopupMenu.Ornament.DOT);
}
}); });
this.menu.addMenuItem(allowedRate); this.menu.addMenuItem(allowedRate);
allowedRateElements.push(allowedRate);
} }
} }
}); });