Compare commits
No commits in common. "fa4084ae07ef762921eb15d303e8d98cff014db7" and "9cff918c2e70f19b8bc730e6c39693f7faaa6cc9" have entirely different histories.
fa4084ae07
...
9cff918c2e
3 changed files with 18 additions and 101 deletions
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.background": "#0C2E56",
|
||||
"titleBar.activeBackground": "#104078",
|
||||
"titleBar.activeForeground": "#F7FAFE"
|
||||
}
|
||||
}
|
104
extension.js
104
extension.js
|
@ -21,8 +21,6 @@
|
|||
const GETTEXT_DOMAIN = 'my-indicator-extension';
|
||||
|
||||
const { GObject, St } = imports.gi;
|
||||
const GLib = imports.gi.GLib;
|
||||
const ByteArray = imports.byteArray;
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const Main = imports.ui.main;
|
||||
|
@ -32,33 +30,22 @@ const PopupMenu = imports.ui.popupMenu;
|
|||
const _ = ExtensionUtils.gettext;
|
||||
|
||||
const Indicator = GObject.registerClass(
|
||||
class Indicator extends PanelMenu.Button {
|
||||
_init() {
|
||||
super._init(0.0, _('My Shiny Indicator'));
|
||||
class Indicator extends PanelMenu.Button {
|
||||
_init() {
|
||||
super._init(0.0, _('My Shiny Indicator'));
|
||||
|
||||
this.add_child(new St.Icon({
|
||||
icon_name: 'face-smile-symbolic',
|
||||
style_class: 'system-status-icon',
|
||||
}));
|
||||
this.add_child(new St.Icon({
|
||||
icon_name: 'face-smile-symbolic',
|
||||
style_class: 'system-status-icon',
|
||||
}));
|
||||
|
||||
let sampleRate = getCurrentSampleRate();
|
||||
let currentSampleRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + sampleRate));
|
||||
this.menu.addMenuItem(currentSampleRate);
|
||||
|
||||
let allowedRates = getAllowedSampleRates();
|
||||
|
||||
for (let i = 0; i < allowedRates.length; i++) {
|
||||
let allowedRate = new PopupMenu.PopupMenuItem(_("Allowed Rates: " + allowedRates[i]));
|
||||
allowedRate.connect('activate', () => {
|
||||
console.log("set sample rate " + allowedRates[i]);
|
||||
setSampleRate(allowedRates[i]);
|
||||
currentSampleRate.label.text = "Sample Rate: " + getCurrentSampleRate();
|
||||
});
|
||||
|
||||
this.menu.addMenuItem(allowedRate);
|
||||
}
|
||||
}
|
||||
});
|
||||
let item = new PopupMenu.PopupMenuItem(_('Show Notification'));
|
||||
item.connect('activate', () => {
|
||||
Main.notify(_('Whatʼs up, folks?'));
|
||||
});
|
||||
this.menu.addMenuItem(item);
|
||||
}
|
||||
});
|
||||
|
||||
class Extension {
|
||||
constructor(uuid) {
|
||||
|
@ -81,66 +68,3 @@ class Extension {
|
|||
function init(meta) {
|
||||
return new Extension(meta.uuid);
|
||||
}
|
||||
|
||||
function setSampleRate(sampleRate) {
|
||||
spawnCommandLine("pw-metadata -n settings 0 clock.rate " + sampleRate);
|
||||
}
|
||||
|
||||
function getCurrentSampleRate() {
|
||||
let res = spawnCommandLine("pw-metadata -n settings");
|
||||
let lines = res.split(/\r?\n/);
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i].includes('clock.rate')) {
|
||||
let phrases = lines[i].split(" ");
|
||||
|
||||
for (let j = 0; j < phrases.length; j++) {
|
||||
if (phrases[j].includes("value")) {
|
||||
return phrases[j].slice(7, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "not found";
|
||||
}
|
||||
|
||||
function getAllowedSampleRates() {
|
||||
let res = spawnCommandLine("pw-metadata -n settings");
|
||||
let lines = res.split(/\r?\n/);
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i].includes('clock.allowed-rates')) {
|
||||
let valueIndex = lines[i].indexOf("value");
|
||||
|
||||
if (valueIndex !== -1) {
|
||||
return lines[i].slice(valueIndex + 9, -11).replaceAll(",", "").split(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "not found";
|
||||
}
|
||||
|
||||
// Runs @command_line in the background, handling any errors that
|
||||
// occur when trying to parse or start the program.
|
||||
function spawnCommandLine(command_line) {
|
||||
try {
|
||||
let [, stdout, stderr, status] = GLib.spawn_command_line_sync(command_line);
|
||||
|
||||
if (status !== 0) {
|
||||
if (stderr instanceof Uint8Array)
|
||||
stderr = ByteArray.toString(stderr);
|
||||
|
||||
throw new Error(stderr);
|
||||
}
|
||||
|
||||
if (stdout instanceof Uint8Array)
|
||||
stdout = ByteArray.toString(stdout);
|
||||
|
||||
// Now were done blocking the main loop, phewf!
|
||||
return stdout;
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "Pipewire Settings",
|
||||
"description": "Change pipewire settings for the current session",
|
||||
"uuid": "pipewiresettings@gavania.de",
|
||||
"name": "PipewireSettings",
|
||||
"description": "Change pipewire settings for this session",
|
||||
"uuid": "michaelh.95@t-online.de",
|
||||
"shell-version": [
|
||||
"43"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue