Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MuteToggler@jebeaudet.com] Separate cmd line evaluation and executed on settings change #6651

Merged
merged 9 commits into from
Nov 29, 2024
40 changes: 21 additions & 19 deletions MuteToggler@jebeaudet.com/files/MuteToggler@jebeaudet.com/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function findFirstMatch(searchStrings, checkString) {
MyApplet.prototype = {
__proto__: Applet.IconApplet.prototype,

_init: async function(metadata, orientation, panel_height, instance_id) {
_init: function(metadata, orientation, panel_height, instance_id) {
try {
this.settings = new Settings.AppletSettings(this, UUID, instance_id);
VERBOSE = this.settings.getValue("verbose");
Expand Down Expand Up @@ -114,23 +114,6 @@ MyApplet.prototype = {
this.on_settings_changed();
}

this.amixer = "amixer";
await this.evaluate_soundcard();
await this.evaluate_input();

const parameters = ["", " -D pulse"];
for (let param of parameters) {
let cmd = this.amixer + param + " scontrols";
log("Test mixer command '" + cmd + "'");
// TODO: Make it async.
let [res, stdout] = GLib.spawn_command_line_sync(cmd);
if (res && to_string(stdout).indexOf(this.input) != -1) {
this.amixer += param;
log("Use mixer command '" + this.amixer + "'");
break;
}
}

this.applet_is_running = true;
this.set_not_muted_icon();
this.is_audio_muted();
Expand All @@ -152,7 +135,7 @@ MyApplet.prototype = {
}

VERBOSE = this.verbose;
this.evaluate_soundcard();
this.evaluate_cmd_line();
},

refresh_loop: function() {
Expand Down Expand Up @@ -262,6 +245,25 @@ MyApplet.prototype = {
});
},

evaluate_cmd_line: async function() {
this.amixer = "amixer";
await this.evaluate_soundcard();
await this.evaluate_input();

const parameters = ["", " -D pulse"];
for (let param of parameters) {
let cmd = this.amixer + param + " scontrols";
log("Test mixer command '" + cmd + "'");
// TODO: Make it async.
let [res, stdout] = GLib.spawn_command_line_sync(cmd);
if (res && to_string(stdout).indexOf(this.input) != -1) {
this.amixer += param;
log("Use mixer command '" + this.amixer + "'");
break;
}
}
},

on_applet_clicked: function(event) {
try{
let cmd = [
Expand Down