Not adding the constructor causes a compilation error on Ubuntu 22.04
with both clang 14 and gcc 11:
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/alloc_traits.h:518:4: error: no matching function for call to 'construct_at'
std::construct_at(__p, std::forward<_Args>(__args)...);
^~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/vector.tcc:117:21: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<waybar::modules::Profile>>::construct<waybar::modules::Profile, Glib::ustring, Glib::ustring>' requested here
_Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
^
../src/modules/power_profiles_daemon.cpp:106:26: note: in instantiation of function template specialization 'std::vector<waybar::modules::Profile>::emplace_back<Glib::ustring, Glib::ustring>' requested here
availableProfiles_.emplace_back(std::move(name), std::move(driver));
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_construct.h:94:5: note: candidate template ignored: substitution failure [with _Tp = waybar::modules::Profile, _Args = <Glib::ustring, Glib::ustring>]: no matching constructor for initialization of 'waybar::modules::Profile'
construct_at(_Tp* __location, _Args&&... __args)
^
2 changes to address the review feedback:
1. Aleksei pointed out in this
comment (https://github.com/Alexays/Waybar/pull/2971#issuecomment-1972364896)
that there's no way to tell if a proxy is alive other than trying to
call a method on it. We perform a little dance to check whether or
not power-profiles-daemon is available on the system by calling
properties.GetAll. If something responds, we assume
power-profiles-daemon is installed, it's then safe to draw the
widget and attach the callback to the active profile.
2. We replaced all the synchronous DBus operations by their async
counterparts.
We introduce a module in charge to display and toggle on click the
power profiles via power-profiles-daemon.
https://gitlab.freedesktop.org/upower/power-profiles-daemon
This daemon is pretty widespread. It's the component used by Gnome and
KDE to manage the power profiles. The power management daemon is a
pretty important software component for laptops and other
battery-powered devices.
We're using the daemon DBus interface to:
- Fetch the available power profiles.
- Track the active power profile.
- Change the active power profile.
The original author recently gave up maintenance on the project. The
Upower group took over the maintenance burden… …and created a new
DBus name for the project. The old name is still advertised for now.
We use the old name for compatibility sake: most distributions did not
release 0.20, which introduces this new DBus name. We'll likely revisit
this in the future and point to the new bus name. See the inline
comment for more details.
Given how widespread this daemon is, I activated the module in the
default configuration.