| 675 | } |
| 676 | |
| 677 | auto waybar::modules::Battery::update() -> void { |
| 678 | #if defined(__linux__) |
| 679 | if (batteries_.empty()) { |
| 680 | event_box_.hide(); |
| 681 | return; |
| 682 | } |
| 683 | #endif |
| 684 | auto [capacity, time_remaining, status, power, cycles, health] = getInfos(); |
| 685 | if (status == "Unknown") { |
| 686 | status = getAdapterStatus(capacity); |
| 687 | } |
| 688 | auto status_pretty = status; |
| 689 | puts(status.c_str()); |
| 690 | // Transform to lowercase and replace space with dash |
| 691 | std::ranges::transform(status.begin(), status.end(), status.begin(), |
| 692 | [](char ch) { return ch == ' ' ? '-' : std::tolower(ch); }); |
| 693 | auto format = format_; |
| 694 | auto state = getState(capacity, true); |
| 695 | processEvents(state, status, capacity); |
| 696 | setBarClass(state); |
| 697 | auto time_remaining_formatted = formatTimeRemaining(time_remaining); |
| 698 | if (tooltipEnabled()) { |
| 699 | std::string tooltip_text_default; |
| 700 | std::string tooltip_format = "{timeTo}"; |
| 701 | if (time_remaining != 0) { |
| 702 | if (time_remaining > 0) { |
| 703 | tooltip_text_default = std::string("Empty in ") + time_remaining_formatted; |
| 704 | } else { |
| 705 | tooltip_text_default = std::string("Full in ") + time_remaining_formatted; |
| 706 | } |
| 707 | } else { |
| 708 | tooltip_text_default = status_pretty; |
| 709 | } |
| 710 | if (!state.empty() && config_["tooltip-format-" + status + "-" + state].isString()) { |
| 711 | tooltip_format = config_["tooltip-format-" + status + "-" + state].asString(); |
| 712 | } else if (config_["tooltip-format-" + status].isString()) { |
| 713 | tooltip_format = config_["tooltip-format-" + status].asString(); |
| 714 | } else if (!state.empty() && config_["tooltip-format-" + state].isString()) { |
| 715 | tooltip_format = config_["tooltip-format-" + state].asString(); |
| 716 | } else if (config_["tooltip-format"].isString()) { |
| 717 | tooltip_format = config_["tooltip-format"].asString(); |
| 718 | } |
| 719 | label_.set_tooltip_markup( |
| 720 | fmt::format(fmt::runtime(tooltip_format), fmt::arg("timeTo", tooltip_text_default), |
| 721 | fmt::arg("power", power), fmt::arg("capacity", capacity), |
| 722 | fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles), |
| 723 | fmt::arg("health", fmt::format("{:.3}", health)))); |
| 724 | } |
| 725 | if (!old_status_.empty()) { |
| 726 | label_.get_style_context()->remove_class(old_status_); |
| 727 | } |
| 728 | label_.get_style_context()->add_class(status); |
| 729 | old_status_ = status; |
| 730 | if (!state.empty() && config_["format-" + status + "-" + state].isString()) { |
| 731 | format = config_["format-" + status + "-" + state].asString(); |
| 732 | } else if (config_["format-" + status].isString()) { |
| 733 | format = config_["format-" + status].asString(); |
| 734 | } else if (!state.empty() && config_["format-" + state].isString()) { |