Compare commits

...

3 commits

Author SHA1 Message Date
Michael Hübner fa4084ae07 colored border 2023-03-14 10:36:01 +01:00
Michael Hübner b55c9d9437 Merge branch 'master' of PipewireSettings 2023-03-14 10:35:50 +01:00
Michael Hübner 58c238f3b9 First example 2023-03-14 10:34:00 +01:00
3 changed files with 101 additions and 18 deletions

7
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#0C2E56",
"titleBar.activeBackground": "#104078",
"titleBar.activeForeground": "#F7FAFE"
}
}

View file

@ -21,6 +21,8 @@
const GETTEXT_DOMAIN = 'my-indicator-extension'; const GETTEXT_DOMAIN = 'my-indicator-extension';
const { GObject, St } = imports.gi; const { GObject, St } = imports.gi;
const GLib = imports.gi.GLib;
const ByteArray = imports.byteArray;
const ExtensionUtils = imports.misc.extensionUtils; const ExtensionUtils = imports.misc.extensionUtils;
const Main = imports.ui.main; const Main = imports.ui.main;
@ -39,11 +41,22 @@ class Indicator extends PanelMenu.Button {
style_class: 'system-status-icon', style_class: 'system-status-icon',
})); }));
let item = new PopupMenu.PopupMenuItem(_('Show Notification')); let sampleRate = getCurrentSampleRate();
item.connect('activate', () => { let currentSampleRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + sampleRate));
Main.notify(_('Whatʼs up, folks?')); 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(item);
this.menu.addMenuItem(allowedRate);
}
} }
}); });
@ -68,3 +81,66 @@ class Extension {
function init(meta) { function init(meta) {
return new Extension(meta.uuid); 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);
}
}

View file

@ -1,7 +1,7 @@
{ {
"name": "Pipewire Settings", "name": "Pipewire Settings",
"description": "Change pipewire settings for this session", "description": "Change pipewire settings for the current session",
"uuid": "michaelh.95@t-online.de", "uuid": "pipewiresettings@gavania.de",
"shell-version": [ "shell-version": [
"43" "43"
] ]