Skip to content

Commit

Permalink
block signal handlers in toggle button when updating state (#406)
Browse files Browse the repository at this point in the history
* blockg signal handlers in toggle button when updating state

* fix linting

---------

Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com>
  • Loading branch information
theRealCarneiro and ErikReider authored Mar 25, 2024
1 parent 7e503e6 commit be1533a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/controlCenter/widgets/shared/toggleButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace SwayNotificationCenter.Widgets {

private string command;
private string update_command;
private ulong handler_id;

public ToggleButton (string label, string command, string update_command, bool active) {
this.command = command;
Expand All @@ -13,7 +14,7 @@ namespace SwayNotificationCenter.Widgets {
this.active = true;
}

this.toggled.connect (on_toggle);
this.handler_id = this.toggled.connect (on_toggle);
}

private async void on_toggle () {
Expand All @@ -31,11 +32,13 @@ namespace SwayNotificationCenter.Widgets {
// remove trailing whitespaces
Regex regex = new Regex ("\\s+$");
string res = regex.replace (msg, msg.length, 0, "");
GLib.SignalHandler.block (this, this.handler_id);
if (res.up () == "TRUE") {
this.active = true;
} else {
this.active = false;
}
GLib.SignalHandler.unblock (this, this.handler_id);
} catch (RegexError e) {
stderr.printf ("RegexError: %s\n", e.message);
}
Expand Down

0 comments on commit be1533a

Please sign in to comment.