refactor(bluetooth): remove Bluetooth::status_

The string was always overwritten in `update()`; don't need to store
temporary value in the class.
This commit is contained in:
Aleksei Bavshin 2021-02-02 20:01:01 -08:00
parent 38c29fc242
commit ecc32ddd18
No known key found for this signature in database
GPG Key ID: 4F071603387A382A
2 changed files with 7 additions and 18 deletions

View File

@ -1,8 +1,5 @@
#pragma once #pragma once
#include <fmt/chrono.h>
#include <fmt/format.h>
#include "ALabel.hpp" #include "ALabel.hpp"
#include "util/rfkill.hpp" #include "util/rfkill.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
@ -16,7 +13,6 @@ class Bluetooth : public ALabel {
auto update() -> void; auto update() -> void;
private: private:
std::string status_;
util::SleeperThread thread_; util::SleeperThread thread_;
util::Rfkill rfkill_; util::Rfkill rfkill_;
}; };

View File

@ -1,9 +1,9 @@
#include "modules/bluetooth.hpp" #include "modules/bluetooth.hpp"
#include <fmt/format.h>
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
: ALabel(config, "bluetooth", id, "{icon}", 10), : ALabel(config, "bluetooth", id, "{icon}", 10), rfkill_{RFKILL_TYPE_BLUETOOTH} {
status_("disabled"),
rfkill_{RFKILL_TYPE_BLUETOOTH} {
rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update))); rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update)));
thread_ = [this] { thread_ = [this] {
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
@ -15,25 +15,18 @@ waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value&
} }
auto waybar::modules::Bluetooth::update() -> void { auto waybar::modules::Bluetooth::update() -> void {
if (rfkill_.getState()) { std::string status = rfkill_.getState() ? "disabled" : "enabled";
status_ = "disabled";
} else {
status_ = "enabled";
}
label_.set_markup( label_.set_markup(
fmt::format( fmt::format(format_, fmt::arg("status", status), fmt::arg("icon", getIcon(0, status))));
format_,
fmt::arg("status", status_),
fmt::arg("icon", getIcon(0, status_))));
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
auto tooltip_text = fmt::format(tooltip_format, status_); auto tooltip_text = fmt::format(tooltip_format, status);
label_.set_tooltip_text(tooltip_text); label_.set_tooltip_text(tooltip_text);
} else { } else {
label_.set_tooltip_text(status_); label_.set_tooltip_text(status);
} }
} }
} }