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
1 changed files with 9 additions and 9 deletions

View File

@ -229,16 +229,11 @@ namespace modules {
m_state = state;
m_percentage = percentage;
const auto label = [this] {
switch (m_state) {
case battery_module::state::FULL: return m_label_full;
case battery_module::state::DISCHARGING: return m_label_discharging;
case battery_module::state::LOW: return m_label_low;
default: return m_label_charging;
const auto replace_tokens = [&](label_t& label) {
if (!label) {
return;
}
}();
if (label) {
label->reset_tokens();
label->replace_token("%percentage%", to_string(clamp_percentage(m_percentage, m_state)));
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()) {
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;
}