Unverified Commit be1533ad authored by Gabriel Carneiro's avatar Gabriel Carneiro Committed by GitHub

block signal handlers in toggle button when updating state (#406)

* blockg signal handlers in toggle button when updating state * fix linting --------- Co-authored-by: 's avatarErik Reider <35975961+ErikReider@users.noreply.github.com>
parent 7e503e68
...@@ -3,6 +3,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -3,6 +3,7 @@ namespace SwayNotificationCenter.Widgets {
private string command; private string command;
private string update_command; private string update_command;
private ulong handler_id;
public ToggleButton (string label, string command, string update_command, bool active) { public ToggleButton (string label, string command, string update_command, bool active) {
this.command = command; this.command = command;
...@@ -13,7 +14,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -13,7 +14,7 @@ namespace SwayNotificationCenter.Widgets {
this.active = true; this.active = true;
} }
this.toggled.connect (on_toggle); this.handler_id = this.toggled.connect (on_toggle);
} }
private async void on_toggle () { private async void on_toggle () {
...@@ -31,11 +32,13 @@ namespace SwayNotificationCenter.Widgets { ...@@ -31,11 +32,13 @@ namespace SwayNotificationCenter.Widgets {
// remove trailing whitespaces // remove trailing whitespaces
Regex regex = new Regex ("\\s+$"); Regex regex = new Regex ("\\s+$");
string res = regex.replace (msg, msg.length, 0, ""); string res = regex.replace (msg, msg.length, 0, "");
GLib.SignalHandler.block (this, this.handler_id);
if (res.up () == "TRUE") { if (res.up () == "TRUE") {
this.active = true; this.active = true;
} else { } else {
this.active = false; this.active = false;
} }
GLib.SignalHandler.unblock (this, this.handler_id);
} catch (RegexError e) { } catch (RegexError e) {
stderr.printf ("RegexError: %s\n", e.message); stderr.printf ("RegexError: %s\n", e.message);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment