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; font-size: 16px;
} }
.battery-charging {
color: #ffb86c;
}
.network-data-text { .network-data-text {
color: #50fa7b; color: #50fa7b;
font-size: 16px; font-size: 16px;

View file

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

View file

@ -42,6 +42,7 @@ namespace Bar
} }
static Text* batteryText; static Text* batteryText;
static bool wasCharging = false;
static TimerResult UpdateBattery(Sensor& sensor) static TimerResult UpdateBattery(Sensor& sensor)
{ {
double percentage = System::GetBatteryPercentage(); double percentage = System::GetBatteryPercentage();
@ -56,6 +57,20 @@ namespace Bar
batteryText->SetText(text); batteryText->SetText(text);
} }
sensor.SetValue(percentage); 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; return TimerResult::Ok;
} }

View file

@ -89,6 +89,25 @@ namespace System
return temp; 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() double GetBatteryPercentage()
{ {
std::ifstream fullChargeFile(Config::Get().batteryFolder + "/charge_full"); std::ifstream fullChargeFile(Config::Get().batteryFolder + "/charge_full");

View file

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