From d24efc2aec6c4fbc00a4536998caf30553dc1e9b Mon Sep 17 00:00:00 2001 From: meizhigang Date: Tue, 9 Apr 2024 14:09:04 +0800 Subject: [PATCH 13/14] fix(power):Fix battery charging and discharging time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 适配电池充电和放电时间 Related #28618 --- plugins/power/tray/power-tray.cpp | 41 ++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/plugins/power/tray/power-tray.cpp b/plugins/power/tray/power-tray.cpp index 8f76bcb..c372ef9 100644 --- a/plugins/power/tray/power-tray.cpp +++ b/plugins/power/tray/power-tray.cpp @@ -107,30 +107,41 @@ void PowerTray::update_status_icon_toolstip(std::shared_ptr d { case UP_DEVICE_STATE_CHARGING: { - auto time_to_full_text = PowerUtils::get_time_translation(device_for_tray->get_props().time_to_full); - auto tooltip_text = fmt::format(_("Remaining electricty: {0:.1f}%, approximately {1} until charged"), - device_for_tray->get_props().percentage, - time_to_full_text); - gtk_status_icon_set_tooltip_text(this->status_icon_, tooltip_text.c_str()); + auto time_to_full = device_for_tray->get_props().time_to_full; + if (time_to_full > 0) + { + auto time_to_full_text = PowerUtils::get_time_translation(time_to_full); + auto tooltip_text = fmt::format(_("Remaining electricty: {0:.1f}%, approximately {1} until charged"), + device_for_tray->get_props().percentage, + time_to_full_text); + gtk_status_icon_set_tooltip_text(this->status_icon_, tooltip_text.c_str()); + + return; + } break; } case UP_DEVICE_STATE_DISCHARGING: { - auto time_to_empty_text = PowerUtils::get_time_translation(device_for_tray->get_props().time_to_empty); - auto tooltip_text = fmt::format(_("Remaining electricty: {0:.1f}%, approximately provides {1} runtime"), - device_for_tray->get_props().percentage, - time_to_empty_text); - gtk_status_icon_set_tooltip_text(this->status_icon_, tooltip_text.c_str()); + auto time_to_empty = device_for_tray->get_props().time_to_empty; + if (time_to_empty > 0) + { + auto time_to_empty_text = PowerUtils::get_time_translation(time_to_empty); + auto tooltip_text = fmt::format(_("Remaining electricty: {0:.1f}%, approximately provides {1} runtime"), + device_for_tray->get_props().percentage, + time_to_empty_text); + gtk_status_icon_set_tooltip_text(this->status_icon_, tooltip_text.c_str()); + + return; + } break; } case UP_DEVICE_STATE_FULLY_CHARGED: default: - { - auto tooltip_text = fmt::format(_("Remaining electricty: {0:.1f}%"), device_for_tray->get_props().percentage); - gtk_status_icon_set_tooltip_text(this->status_icon_, tooltip_text.c_str()); - } - break; + break; } + + auto tooltip_text = fmt::format(_("Remaining electricty: {0:.1f}%"), device_for_tray->get_props().percentage); + gtk_status_icon_set_tooltip_text(this->status_icon_, tooltip_text.c_str()); } void PowerTray::delay_update_status_icon() -- 2.27.0