From 06db5f7e3e9fe55df9243d0a92a3a2c76176ae34 Mon Sep 17 00:00:00 2001 From: Litesung Date: Tue, 27 Jan 2026 10:50:14 -0800 Subject: [PATCH] fix: resolve race condition in caffeine toggle notification The notification was reading the label via get_label() after GLib.idle_add() scheduled the update, but before it executed. This caused the notification to show the wrong state (e.g., "Disabled" when enabling). Fix: Track new_state directly in the code path instead of reading the label asynchronously. --- modules/buttons.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/buttons.py b/modules/buttons.py index ec14178e..1deacc87 100644 --- a/modules/buttons.py +++ b/modules/buttons.py @@ -406,15 +406,15 @@ def _toggle_inhibit_thread(self, external): exec_shell_command_async("pkill ax-inhibit") GLib.idle_add(self.caffeine_status.set_label, "Disabled") GLib.idle_add(self._add_disabled_style) + new_state = "Disabled" except subprocess.CalledProcessError: exec_shell_command_async(f"python {data.HOME_DIR}/.config/{data.APP_NAME_CAP}/scripts/inhibit.py") GLib.idle_add(self.caffeine_status.set_label, "Enabled") GLib.idle_add(self._remove_disabled_style) + new_state = "Enabled" if external: - # Different if enabled or disabled - status = "Disabled" if self.caffeine_status.get_label() == "Disabled" else "Enabled" - message = "Disabled 💤" if status == "Disabled" else "Enabled ☀️" + message = "Disabled 💤" if new_state == "Disabled" else "Enabled ☀️" exec_shell_command_async(f"notify-send '☕ Caffeine' '{message}' -a '{data.APP_NAME_CAP}' -e") def _add_disabled_style(self):