Add battery charging indication

This commit is contained in:
scorpion-26 2023-10-28 23:29:27 +02:00
parent 74f8df49f3
commit 6e71e8a4f3
5 changed files with 44 additions and 0 deletions

View file

@ -198,6 +198,10 @@ highlight {
font-size: 16px;
}
.battery-charging {
color: #ffb86c;
}
.network-data-text {
color: #50fa7b;
font-size: 16px;

View file

@ -229,11 +229,16 @@ highlight {
background-color: $inactive;
font-size: $textsize;
}
.battery-data-text {
color: $pink;
font-size: $textsize;
}
.battery-charging {
color: $orange
}
.network-data-text {
color: $green;
font-size: $textsize;

View file

@ -42,6 +42,7 @@ namespace Bar
}
static Text* batteryText;
static bool wasCharging = false;
static TimerResult UpdateBattery(Sensor& sensor)
{
double percentage = System::GetBatteryPercentage();
@ -56,6 +57,20 @@ namespace Bar
batteryText->SetText(text);
}
sensor.SetValue(percentage);
bool isCharging = System::IsBatteryCharging();
if (isCharging && !wasCharging && sensor.Get() != nullptr)
{
sensor.AddClass("battery-charging");
batteryText->AddClass("battery-charging");
wasCharging = true;
}
else if (!isCharging && wasCharging)
{
sensor.RemoveClass("battery-charging");
batteryText->RemoveClass("battery-charging");
wasCharging = false;
}
return TimerResult::Ok;
}

View file

@ -89,6 +89,25 @@ namespace System
return temp;
}
bool IsBatteryCharging()
{
std::ifstream batteryStatus(Config::Get().batteryFolder + "/status");
if (batteryStatus.is_open())
{
std::string status;
std::getline(batteryStatus, status);
if (status == "Charging" || status == "Full")
{
return true;
}
else
{
return false;
}
}
return false;
}
double GetBatteryPercentage()
{
std::ifstream fullChargeFile(Config::Get().batteryFolder + "/charge_full");

View file

@ -11,6 +11,7 @@ namespace System
// Tctl
double GetCPUTemp();
bool IsBatteryCharging();
double GetBatteryPercentage();
struct RAMInfo