fix(battery): Replace tokens for all labels

Otherwise we have to replicate the fallback logic for LOW -> DISCHARGING
in multiple places.

Fixes #2379
This commit is contained in:
patrick96 2022-02-21 02:14:54 +01:00 committed by Patrick Ziegler
parent 62da14e30d
commit ae7686d24b

View File

@ -229,16 +229,11 @@ namespace modules {
m_state = state; m_state = state;
m_percentage = percentage; m_percentage = percentage;
const auto label = [this] { const auto replace_tokens = [&](label_t& label) {
switch (m_state) { if (!label) {
case battery_module::state::FULL: return m_label_full; return;
case battery_module::state::DISCHARGING: return m_label_discharging;
case battery_module::state::LOW: return m_label_low;
default: return m_label_charging;
} }
}();
if (label) {
label->reset_tokens(); label->reset_tokens();
label->replace_token("%percentage%", to_string(clamp_percentage(m_percentage, m_state))); label->replace_token("%percentage%", to_string(clamp_percentage(m_percentage, m_state)));
label->replace_token("%percentage_raw%", to_string(m_percentage)); label->replace_token("%percentage_raw%", to_string(m_percentage));
@ -247,7 +242,12 @@ namespace modules {
if (m_state != battery_module::state::FULL && !m_timeformat.empty()) { if (m_state != battery_module::state::FULL && !m_timeformat.empty()) {
label->replace_token("%time%", current_time()); label->replace_token("%time%", current_time());
} }
} };
replace_tokens(m_label_full);
replace_tokens(m_label_discharging);
replace_tokens(m_label_low);
replace_tokens(m_label_charging);
return true; return true;
} }