Check sample rate on pop up
This commit is contained in:
parent
ec4e3bca02
commit
5e8f17eaf0
1 changed files with 28 additions and 19 deletions
47
extension.js
47
extension.js
|
@ -31,7 +31,9 @@ const PopupMenu = imports.ui.popupMenu;
|
|||
|
||||
const _ = ExtensionUtils.gettext;
|
||||
|
||||
allowedRateElements = [];
|
||||
let allowedRateElements = [];
|
||||
let allowedSampleRates = [];
|
||||
let indicatorButton;
|
||||
|
||||
const Indicator = GObject.registerClass(
|
||||
class Indicator extends PanelMenu.Button {
|
||||
|
@ -44,35 +46,33 @@ const Indicator = GObject.registerClass(
|
|||
}));
|
||||
|
||||
let sampleRate = getForcedSampleRate();
|
||||
let allowedRates = getAllowedSampleRates();
|
||||
allowedSampleRates = getAllowedSampleRates();
|
||||
allowedRateElements = [];
|
||||
|
||||
for (let i = 0; i < allowedRates.length; i++) {
|
||||
let allowedRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + allowedRates[i]));
|
||||
for (let i = 0; i < allowedSampleRates.length; i++) {
|
||||
let allowedRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + allowedSampleRates[i]));
|
||||
|
||||
if (allowedRates[i] == sampleRate) {
|
||||
if (allowedSampleRates[i] == sampleRate) {
|
||||
allowedRate.setOrnament(PopupMenu.Ornament.DOT);
|
||||
}
|
||||
|
||||
allowedRate.connect('activate', () => {
|
||||
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(allowedSampleRates[i]);
|
||||
|
||||
// sanity check sample rate
|
||||
let forcedRate = getForcedSampleRate();
|
||||
|
||||
if (forcedRate == allowedRates[i]) {
|
||||
if (forcedRate == allowedSampleRates[i]) {
|
||||
allowedRate.setOrnament(PopupMenu.Ornament.DOT);
|
||||
}
|
||||
});
|
||||
|
||||
this.menu.addMenuItem(allowedRate);
|
||||
allowedRateElements.push(allowedRate);
|
||||
this.menu.addMenuItem(allowedRate);
|
||||
allowedRateElements.push(allowedRate);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -85,13 +85,26 @@ class Extension {
|
|||
}
|
||||
|
||||
enable() {
|
||||
this._indicator = new Indicator();
|
||||
Main.panel.addToStatusArea(this._uuid, this._indicator);
|
||||
indicatorButton = new Indicator();
|
||||
|
||||
indicatorButton.connect('button-press-event', () => {
|
||||
let sampleRate = getForcedSampleRate();
|
||||
|
||||
for (let k = 0; k < allowedRateElements.length; k++) {
|
||||
if (allowedSampleRates[k] == sampleRate) {
|
||||
allowedRateElements[k].setOrnament(PopupMenu.Ornament.DOT);
|
||||
} else {
|
||||
allowedRateElements[k].setOrnament(PopupMenu.Ornament.NONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Main.panel.addToStatusArea(this._uuid, indicatorButton);
|
||||
}
|
||||
|
||||
disable() {
|
||||
this._indicator.destroy();
|
||||
this._indicator = null;
|
||||
indicatorButton.destroy();
|
||||
indicatorButton = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,16 +123,12 @@ function getForcedSampleRate() {
|
|||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i].includes('clock.force-rate')) {
|
||||
console.log("found current force rate setting");
|
||||
|
||||
let phrases = lines[i].split(" ");
|
||||
|
||||
for (let j = 0; j < phrases.length; j++) {
|
||||
if (phrases[j].includes("value")) {
|
||||
let value = phrases[j].slice(7, -1);
|
||||
|
||||
console.log("with current value " + value);
|
||||
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue