Add nullptr check for batteryText

If SensorTooltips: true, then batteryText would be nullptr, but the
class would still be updated, causing the crash

Fixes https://github.com/scorpion-26/gBar/issues/58
This commit is contained in:
scorpion-26 2023-11-06 20:16:51 +01:00
parent 4b3679b550
commit 8b8ce501d4

View file

@ -24,6 +24,7 @@ namespace Bar
case Right: return Alignment::Right; case Right: return Alignment::Right;
case Center: return Alignment::Fill; case Center: return Alignment::Fill;
} }
return Alignment::Right;
} }
TransitionType SideToDefaultTransition(Side side) TransitionType SideToDefaultTransition(Side side)
@ -94,12 +95,14 @@ namespace Bar
if (isCharging && !wasCharging && sensor.Get() != nullptr) if (isCharging && !wasCharging && sensor.Get() != nullptr)
{ {
sensor.AddClass("battery-charging"); sensor.AddClass("battery-charging");
if (batteryText)
batteryText->AddClass("battery-charging"); batteryText->AddClass("battery-charging");
wasCharging = true; wasCharging = true;
} }
else if (!isCharging && wasCharging) else if (!isCharging && wasCharging)
{ {
sensor.RemoveClass("battery-charging"); sensor.RemoveClass("battery-charging");
if (batteryText)
batteryText->RemoveClass("battery-charging"); batteryText->RemoveClass("battery-charging");
wasCharging = false; wasCharging = false;
} }