Skip to content

Commit

Permalink
feat: add level labels to battery component
Browse files Browse the repository at this point in the history
  • Loading branch information
jovark committed Sep 18, 2023
1 parent 6bac18b commit 6f7f0ef
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 26 deletions.
104 changes: 84 additions & 20 deletions GlazeWM.Bar/Components/BatteryComponentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,95 @@ public LabelViewModel CreateLabel()

// Display the battery level as a 100% if device has no dedicated battery.
if (ps.BatteryFlag == 128)
return XamlHelper.ParseLabel(
_config.LabelDraining,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelDrainingLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelDrainingMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelDrainingHigh,
CreateVariableDict(batteryLevel),
this
)
};

if (ps.ACLineStatus == 1)
return XamlHelper.ParseLabel(
_config.LabelCharging,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelChargingLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelChargingMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelChargingHigh,
CreateVariableDict(batteryLevel),
this
)
};

if (ps.SystemStatusFlag == 1)
return XamlHelper.ParseLabel(
_config.LabelPowerSaver,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelPowerSaverLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelPowerSaverMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelPowerSaverHigh,
CreateVariableDict(batteryLevel),
this
)
};

return XamlHelper.ParseLabel(
_config.LabelDraining,
CreateVariableDict(batteryLevel),
this
);
return ps.BatteryLifePercent switch
{
> 0 and < 33 =>
XamlHelper.ParseLabel(
_config.LabelDrainingLow,
CreateVariableDict(batteryLevel),
this
),
>= 33 and < 66 =>
XamlHelper.ParseLabel(
_config.LabelDrainingMedium,
CreateVariableDict(batteryLevel),
this
),
_ =>
XamlHelper.ParseLabel(
_config.LabelDrainingHigh,
CreateVariableDict(batteryLevel),
this
)
};
}

public static Dictionary<string, Func<string>> CreateVariableDict(string batteryLevel)
Expand Down
36 changes: 30 additions & 6 deletions GlazeWM.Domain/UserConfigs/BatteryComponentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,40 @@ namespace GlazeWM.Domain.UserConfigs
public class BatteryComponentConfig : BarComponentConfig
{
/// <summary>
/// Formatted text to display when the device is draining battery power.
/// Formatted text to display when the device is draining battery power and battery level is low.
/// </summary>
public string LabelDraining { get; set; } = "{battery_level}%";
public string LabelDrainingLow { get; set; } = "Low {battery_level}%";
/// <summary>
/// Formatted text to display when the device is in power saving mode.
/// Formatted text to display when the device is draining battery power and battery level is medium.
/// </summary>
public string LabelPowerSaver { get; set; } = "{battery_level}% (power saver)";
public string LabelDrainingMedium { get; set; } = "Medium {battery_level}%";
/// <summary>
/// Formatted text to display when the device is connected to power.
/// Formatted text to display when the device is draining battery power and battery level is high.
/// </summary>
public string LabelCharging { get; set; } = "{battery_level}% (charging)";
public string LabelDrainingHigh { get; set; } = "High {battery_level}%";
/// <summary>
/// Formatted text to display when the device is in power saving mode and battery level is low.
/// </summary>
public string LabelPowerSaverLow { get; set; } = "Low {battery_level}% (power saver)";
/// <summary>
/// Formatted text to display when the device is in power saving mode and battery level is medium.
/// </summary>
public string LabelPowerSaverMedium { get; set; } = "Medium {battery_level}% (power saver)";
/// <summary>
/// Formatted text to display when the device is in power saving mode and battery level is high.
/// </summary>
public string LabelPowerSaverHigh { get; set; } = "High {battery_level}% (power saver)";
/// <summary>
/// Formatted text to display when the device is connected to power and battery level is low.
/// </summary>
public string LabelChargingLow { get; set; } = "Low {battery_level}% (charging)";
/// <summary>
/// Formatted text to display when the device is connected to power and battery level is medium.
/// </summary>
public string LabelChargingMedium { get; set; } = "Medium {battery_level}% (charging)";
/// <summary>
/// Formatted text to display when the device is connected to power and battery level is high.
/// </summary>
public string LabelChargingHigh { get; set; } = "High {battery_level}% (charging)";
}
}

0 comments on commit 6f7f0ef

Please sign in to comment.