Blame waybar-0.10.0-power-profiles-daemon-initial-visibility.patch

9423a10
From dcddddd3f1a1c1560a84caf791a21b4610f0fc7d Mon Sep 17 00:00:00 2001
9423a10
From: Aleksei Bavshin <alebastr89@gmail.com>
9423a10
Date: Thu, 14 Mar 2024 00:58:33 -0700
9423a10
Subject: [PATCH] fix(power-profiles-daemon): correctly set initial visibility
9423a10
9423a10
The bus error when the daemon is not reachable prevents the initial
9423a10
update and keeps the module visible, as an empty section on the bar.
9423a10
9423a10
Do the update explicitly before connecting to set initial visibility.
9423a10
9423a10
While we at it, remove a couple of redundant `update()` calls.
9423a10
---
9423a10
 src/modules/power_profiles_daemon.cpp | 9 ++++-----
9423a10
 1 file changed, 4 insertions(+), 5 deletions(-)
9423a10
9423a10
diff --git a/src/modules/power_profiles_daemon.cpp b/src/modules/power_profiles_daemon.cpp
9423a10
index ae3d7443b..ac5f7a2a6 100644
9423a10
--- a/src/modules/power_profiles_daemon.cpp
9423a10
+++ b/src/modules/power_profiles_daemon.cpp
9423a10
@@ -42,6 +42,8 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
9423a10
   Gio::DBus::Proxy::create_for_bus(Gio::DBus::BusType::BUS_TYPE_SYSTEM, "net.hadess.PowerProfiles",
9423a10
                                    "/net/hadess/PowerProfiles", "net.hadess.PowerProfiles",
9423a10
                                    sigc::mem_fun(*this, &PowerProfilesDaemon::busConnectedCb));
9423a10
+  // Schedule update to set the initial visibility
9423a10
+  dp.emit();
9423a10
 }
9423a10
 
9423a10
 void PowerProfilesDaemon::busConnectedCb(Glib::RefPtr<Gio::AsyncResult>& r) {
9423a10
@@ -74,7 +76,6 @@ void PowerProfilesDaemon::getAllPropsCb(Glib::RefPtr<Gio::AsyncResult>& r) {
9423a10
     powerProfilesProxy_->signal_properties_changed().connect(
9423a10
         sigc::mem_fun(*this, &PowerProfilesDaemon::profileChangedCb));
9423a10
     populateInitState();
9423a10
-    dp.emit();
9423a10
   } catch (const std::exception& err) {
9423a10
     spdlog::error("Failed to query power-profiles-daemon via dbus: {}", err.what());
9423a10
   } catch (const Glib::Error& err) {
9423a10
@@ -112,8 +113,6 @@ void PowerProfilesDaemon::populateInitState() {
9423a10
   // Find the index of the current activated mode (to toggle)
9423a10
   std::string str = profileStr.get();
9423a10
   switchToProfile(str);
9423a10
-
9423a10
-  update();
9423a10
 }
9423a10
 
9423a10
 void PowerProfilesDaemon::profileChangedCb(
9423a10
@@ -128,7 +127,6 @@ void PowerProfilesDaemon::profileChangedCb(
9423a10
           Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second)
9423a10
               .get();
9423a10
       switchToProfile(activeProfile);
9423a10
-      update();
9423a10
     }
9423a10
   }
9423a10
 }
9423a10
@@ -145,6 +143,7 @@ void PowerProfilesDaemon::switchToProfile(std::string const& str) {
9423a10
         "Power profile daemon: can't find the active profile {} in the available profiles list",
9423a10
         str);
9423a10
   }
9423a10
+  dp.emit();
9423a10
 }
9423a10
 
9423a10
 auto PowerProfilesDaemon::update() -> void {
9423a10
@@ -195,7 +194,7 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
9423a10
 void PowerProfilesDaemon::setPropCb(Glib::RefPtr<Gio::AsyncResult>& r) {
9423a10
   try {
9423a10
     auto _ = powerProfilesProxy_->call_finish(r);
9423a10
-    update();
9423a10
+    dp.emit();
9423a10
   } catch (const std::exception& e) {
9423a10
     spdlog::error("Failed to set the the active power profile: {}", e.what());
9423a10
   } catch (const Glib::Error& e) {