fix(power-profiles-daemon): correctly set initial visibility
The bus error when the daemon is not reachable prevents the initial update and keeps the module visible, as an empty section on the bar. Do the update explicitly before connecting to set initial visibility. While we at it, remove a couple of redundant `update()` calls.
This commit is contained in:
parent
32eac3ccb7
commit
dcddddd3f1
|
@ -42,6 +42,8 @@ PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Valu
|
||||||
Gio::DBus::Proxy::create_for_bus(Gio::DBus::BusType::BUS_TYPE_SYSTEM, "net.hadess.PowerProfiles",
|
Gio::DBus::Proxy::create_for_bus(Gio::DBus::BusType::BUS_TYPE_SYSTEM, "net.hadess.PowerProfiles",
|
||||||
"/net/hadess/PowerProfiles", "net.hadess.PowerProfiles",
|
"/net/hadess/PowerProfiles", "net.hadess.PowerProfiles",
|
||||||
sigc::mem_fun(*this, &PowerProfilesDaemon::busConnectedCb));
|
sigc::mem_fun(*this, &PowerProfilesDaemon::busConnectedCb));
|
||||||
|
// Schedule update to set the initial visibility
|
||||||
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerProfilesDaemon::busConnectedCb(Glib::RefPtr<Gio::AsyncResult>& r) {
|
void PowerProfilesDaemon::busConnectedCb(Glib::RefPtr<Gio::AsyncResult>& r) {
|
||||||
|
@ -74,7 +76,6 @@ void PowerProfilesDaemon::getAllPropsCb(Glib::RefPtr<Gio::AsyncResult>& r) {
|
||||||
powerProfilesProxy_->signal_properties_changed().connect(
|
powerProfilesProxy_->signal_properties_changed().connect(
|
||||||
sigc::mem_fun(*this, &PowerProfilesDaemon::profileChangedCb));
|
sigc::mem_fun(*this, &PowerProfilesDaemon::profileChangedCb));
|
||||||
populateInitState();
|
populateInitState();
|
||||||
dp.emit();
|
|
||||||
} catch (const std::exception& err) {
|
} catch (const std::exception& err) {
|
||||||
spdlog::error("Failed to query power-profiles-daemon via dbus: {}", err.what());
|
spdlog::error("Failed to query power-profiles-daemon via dbus: {}", err.what());
|
||||||
} catch (const Glib::Error& err) {
|
} catch (const Glib::Error& err) {
|
||||||
|
@ -112,8 +113,6 @@ void PowerProfilesDaemon::populateInitState() {
|
||||||
// Find the index of the current activated mode (to toggle)
|
// Find the index of the current activated mode (to toggle)
|
||||||
std::string str = profileStr.get();
|
std::string str = profileStr.get();
|
||||||
switchToProfile(str);
|
switchToProfile(str);
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerProfilesDaemon::profileChangedCb(
|
void PowerProfilesDaemon::profileChangedCb(
|
||||||
|
@ -128,7 +127,6 @@ void PowerProfilesDaemon::profileChangedCb(
|
||||||
Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second)
|
Glib::VariantBase::cast_dynamic<Glib::Variant<std::string>>(activeProfileVariant->second)
|
||||||
.get();
|
.get();
|
||||||
switchToProfile(activeProfile);
|
switchToProfile(activeProfile);
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,6 +143,7 @@ void PowerProfilesDaemon::switchToProfile(std::string const& str) {
|
||||||
"Power profile daemon: can't find the active profile {} in the available profiles list",
|
"Power profile daemon: can't find the active profile {} in the available profiles list",
|
||||||
str);
|
str);
|
||||||
}
|
}
|
||||||
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto PowerProfilesDaemon::update() -> void {
|
auto PowerProfilesDaemon::update() -> void {
|
||||||
|
@ -195,7 +194,7 @@ bool PowerProfilesDaemon::handleToggle(GdkEventButton* const& e) {
|
||||||
void PowerProfilesDaemon::setPropCb(Glib::RefPtr<Gio::AsyncResult>& r) {
|
void PowerProfilesDaemon::setPropCb(Glib::RefPtr<Gio::AsyncResult>& r) {
|
||||||
try {
|
try {
|
||||||
auto _ = powerProfilesProxy_->call_finish(r);
|
auto _ = powerProfilesProxy_->call_finish(r);
|
||||||
update();
|
dp.emit();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::error("Failed to set the the active power profile: {}", e.what());
|
spdlog::error("Failed to set the the active power profile: {}", e.what());
|
||||||
} catch (const Glib::Error& e) {
|
} catch (const Glib::Error& e) {
|
||||||
|
|
Loading…
Reference in New Issue