Compare commits
3 commits
9cff918c2e
...
fa4084ae07
Author | SHA1 | Date | |
---|---|---|---|
|
fa4084ae07 | ||
|
b55c9d9437 | ||
|
58c238f3b9 |
3 changed files with 101 additions and 18 deletions
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"workbench.colorCustomizations": {
|
||||||
|
"activityBar.background": "#0C2E56",
|
||||||
|
"titleBar.activeBackground": "#104078",
|
||||||
|
"titleBar.activeForeground": "#F7FAFE"
|
||||||
|
}
|
||||||
|
}
|
104
extension.js
104
extension.js
|
@ -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;
|
||||||
|
@ -30,22 +32,33 @@ const PopupMenu = imports.ui.popupMenu;
|
||||||
const _ = ExtensionUtils.gettext;
|
const _ = ExtensionUtils.gettext;
|
||||||
|
|
||||||
const Indicator = GObject.registerClass(
|
const Indicator = GObject.registerClass(
|
||||||
class Indicator extends PanelMenu.Button {
|
class Indicator extends PanelMenu.Button {
|
||||||
_init() {
|
_init() {
|
||||||
super._init(0.0, _('My Shiny Indicator'));
|
super._init(0.0, _('My Shiny Indicator'));
|
||||||
|
|
||||||
this.add_child(new St.Icon({
|
this.add_child(new St.Icon({
|
||||||
icon_name: 'face-smile-symbolic',
|
icon_name: 'face-smile-symbolic',
|
||||||
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);
|
||||||
});
|
|
||||||
this.menu.addMenuItem(item);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
class Extension {
|
class Extension {
|
||||||
constructor(uuid) {
|
constructor(uuid) {
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"name": "PipewireSettings",
|
"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"
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in a new issue