Skip to content

Commit

Permalink
Preparing Performance Setting Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 20, 2023
1 parent 7f44759 commit 2e7740d
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private void InitializeViewModel()
};

Battery.Title.Text = "Pil Gücü";
Battery.LeftIcon.Symbol = SymbolRegular.Battery624;
Battery.LeftIcon.Symbol = BatterySymbol(SMMM.BatteryUsage);
Battery.Description.Text = "Dizüstü bilgisayar pil gücünde çalışırken duvar kağıdına ne olacağı.";

ComboBox BatteryPerformance = new();
Expand Down Expand Up @@ -396,7 +396,7 @@ private void InitializeViewModel()
Minimum = 0
};

BatteryUsage.ValueChanged += (s, e) => BatteryUsageChanged(BatteryUsage.Value);
BatteryUsage.ValueChanged += (s, e) => BatteryUsageChanged(Battery, BatteryUsage.Value);

BatteryContent.Children.Add(BatteryUsageText);
BatteryContent.Children.Add(BatteryUsage);
Expand Down Expand Up @@ -443,6 +443,54 @@ public void OnNavigatedFrom()
//Dispose();
}

private SymbolRegular BatterySymbol(int Value)
{
if (Value <= 0)
{
return SymbolRegular.Battery024;
}
else if (Value <= 10)
{
return SymbolRegular.Battery124;
}
else if (Value <= 20)
{
return SymbolRegular.Battery224;
}
else if (Value <= 30)
{
return SymbolRegular.Battery324;
}
else if (Value <= 40)
{
return SymbolRegular.Battery424;
}
else if (Value <= 50)
{
return SymbolRegular.Battery524;
}
else if (Value <= 60)
{
return SymbolRegular.Battery624;
}
else if (Value <= 70)
{
return SymbolRegular.Battery724;
}
else if (Value <= 80)
{
return SymbolRegular.Battery824;
}
else if (Value <= 90)
{
return SymbolRegular.Battery924;
}
else
{
return SymbolRegular.Battery1024;
}
}

private void CpuUsageChanged(double? Value)
{
int NewValue = Convert.ToInt32(Value);
Expand Down Expand Up @@ -490,16 +538,6 @@ private void MemoryUsageChanged(double? Value)
}
}

private void BatteryUsageChanged(double? Value)
{
int NewValue = Convert.ToInt32(Value);

if (NewValue != SMMM.BatteryUsage)
{
SMMI.BackgroundogSettingManager.SetSetting(SMC.BatteryUsage, NewValue);
}
}

private void NetworkUploadChanged(double? Value)
{
int NewValue = Convert.ToInt32(Value);
Expand Down Expand Up @@ -588,6 +626,18 @@ private void NetworkDownloadTypeSelected(int Index)
}
}

private void BatteryUsageChanged(SPVCEC Battery, double? Value)
{
int NewValue = Convert.ToInt32(Value);

if (NewValue != SMMM.BatteryUsage)
{
Battery.LeftIcon.Symbol = BatterySymbol(NewValue);

SMMI.BackgroundogSettingManager.SetSetting(SMC.BatteryUsage, NewValue);
}
}

public void Dispose()
{
Contents.Clear();
Expand Down
8 changes: 8 additions & 0 deletions src/Project/Sucrose.Backgroundog/Extension/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,22 @@ public static JObject GetBatteryInfo()
{ "State", SBMI.BatteryData.State },
{ "Voltage", SBMI.BatteryData.Voltage },
{ "ChargeRate", SBMI.BatteryData.ChargeRate },
{ "SavingMode", SBMI.BatteryData.SavingMode },
{ "ChargeLevel", SBMI.BatteryData.ChargeLevel },
{ "SaverStatus", SBMI.BatteryData.SaverStatus },
{ "LifePercent", SBMI.BatteryData.LifePercent },
{ "FullLifetime", SBMI.BatteryData.FullLifetime },
{ "ChargeCurrent", SBMI.BatteryData.ChargeCurrent },
{ "DischargeRate", SBMI.BatteryData.DischargeRate },
{ "ACPowerStatus", SBMI.BatteryData.ACPowerStatus },
{ "LifeRemaining", SBMI.BatteryData.LifeRemaining },
{ "DischargeLevel", SBMI.BatteryData.DischargeLevel },
{ "ChargeStatus", $"{SBMI.BatteryData.ChargeStatus}" },
{ "DischargeCurrent", SBMI.BatteryData.DischargeCurrent },
{ "DegradationLevel", SBMI.BatteryData.DegradationLevel },
{ "DesignedCapacity", SBMI.BatteryData.DesignedCapacity },
{ "RemainingCapacity", SBMI.BatteryData.RemainingCapacity },
{ "PowerLineStatus", $"{SBMI.BatteryData.PowerLineStatus}" },
{ "FullChargedCapacity", SBMI.BatteryData.FullChargedCapacity },
{ "ChargeDischargeRate", SBMI.BatteryData.ChargeDischargeRate },
{ "ChargeDischargeCurrent", SBMI.BatteryData.ChargeDischargeCurrent },
Expand Down
120 changes: 71 additions & 49 deletions src/Project/Sucrose.Backgroundog/Helper/Specification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using SMMI = Sucrose.Manager.Manage.Internal;
using SMMM = Sucrose.Manager.Manage.Manager;
using SSSHN = Sucrose.Shared.Space.Helper.Network;
using SWUP = Skylark.Wing.Utility.Power;
using SystemInformation = System.Windows.Forms.SystemInformation;

namespace Sucrose.Backgroundog.Helper
{
Expand Down Expand Up @@ -92,6 +94,19 @@ public static async Task Start()
SBEAS.SessionListChanged();
});

_ = Task.Run(() =>
{
SBMI.BatteryData.ACPowerStatus = $"{SWUP.GetACPowerStatus()}";
SBMI.BatteryData.SavingMode = SWUP.IsBatterySavingMode;
SBMI.BatteryData.SaverStatus = $"{SWUP.GetBatterySaverStatus()}";

SBMI.BatteryData.LifePercent = SystemInformation.PowerStatus.BatteryLifePercent;
SBMI.BatteryData.PowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus;
SBMI.BatteryData.FullLifetime = SystemInformation.PowerStatus.BatteryFullLifetime;
SBMI.BatteryData.ChargeStatus = SystemInformation.PowerStatus.BatteryChargeStatus;
SBMI.BatteryData.LifeRemaining = SystemInformation.PowerStatus.BatteryLifeRemaining;
});

_ = Task.Run(() =>
{
string[] Interfaces = SSSHN.InstanceNetworkInterfaces();
Expand Down Expand Up @@ -215,59 +230,66 @@ public static async Task Start()
{
Hardware.Update();

SBMI.BatteryData.State = true;
SBMI.BatteryData.Name = Hardware.Name;

foreach (ISensor Sensor in Hardware.Sensors)
if (Hardware.Sensors.Any())
{
switch (Sensor.Name)
SBMI.BatteryData.State = true;
SBMI.BatteryData.Name = Hardware.Name;

foreach (ISensor Sensor in Hardware.Sensors)
{
case "Charge Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.ChargeLevel = Sensor.Value;
break;
case "Discharge Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.DischargeLevel = Sensor.Value;
break;
case "Voltage" when Sensor.SensorType == SensorType.Voltage:
SBMI.BatteryData.Voltage = Sensor.Value;
break;
case "Charge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.ChargeCurrent = Sensor.Value;
break;
case "Discharge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.DischargeCurrent = Sensor.Value;
break;
case "Charge / Discharge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.ChargeDischargeCurrent = Sensor.Value;
break;
case "Designed Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.DesignedCapacity = Sensor.Value;
break;
case "Full Charged Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.FullChargedCapacity = Sensor.Value;
break;
case "Remaining Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.RemainingCapacity = Sensor.Value;
break;
case "Charge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.ChargeRate = Sensor.Value;
break;
case "Discharge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.DischargeRate = Sensor.Value;
break;
case "Charge / Discharge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.ChargeDischargeRate = Sensor.Value;
break;
case "Degradation Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.DegradationLevel = Sensor.Value;
break;
case "Remaining Time (Estimated)" when Sensor.SensorType == SensorType.TimeSpan:
SBMI.BatteryData.RemainingTimeEstimated = Sensor.Value;
break;
default:
break;
switch (Sensor.Name)
{
case "Charge Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.ChargeLevel = Sensor.Value;
break;
case "Discharge Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.DischargeLevel = Sensor.Value;
break;
case "Voltage" when Sensor.SensorType == SensorType.Voltage:
SBMI.BatteryData.Voltage = Sensor.Value;
break;
case "Charge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.ChargeCurrent = Sensor.Value;
break;
case "Discharge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.DischargeCurrent = Sensor.Value;
break;
case "Charge / Discharge Current" when Sensor.SensorType == SensorType.Current:
SBMI.BatteryData.ChargeDischargeCurrent = Sensor.Value;
break;
case "Designed Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.DesignedCapacity = Sensor.Value;
break;
case "Full Charged Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.FullChargedCapacity = Sensor.Value;
break;
case "Remaining Capacity" when Sensor.SensorType == SensorType.Energy:
SBMI.BatteryData.RemainingCapacity = Sensor.Value;
break;
case "Charge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.ChargeRate = Sensor.Value;
break;
case "Discharge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.DischargeRate = Sensor.Value;
break;
case "Charge / Discharge Rate" when Sensor.SensorType == SensorType.Power:
SBMI.BatteryData.ChargeDischargeRate = Sensor.Value;
break;
case "Degradation Level" when Sensor.SensorType == SensorType.Level:
SBMI.BatteryData.DegradationLevel = Sensor.Value;
break;
case "Remaining Time (Estimated)" when Sensor.SensorType == SensorType.TimeSpan:
SBMI.BatteryData.RemainingTimeEstimated = Sensor.Value;
break;
default:
break;
}
}
}
else
{
SBMI.BatteryData.State = false;
}
}
else if (Hardware.HardwareType == HardwareType.Motherboard)
{
Expand Down
9 changes: 8 additions & 1 deletion src/Project/Sucrose.Backgroundog/Manage/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ internal static class Internal
State = false,
ChargeRate = 0f,
ChargeLevel = 0f,
LifePercent = 0f,
FullLifetime = 0,
LifeRemaining = 0,
ChargeCurrent = 0f,
DischargeRate = 0f,
SavingMode = false,
DischargeLevel = 0f,
Name = string.Empty,
DischargeCurrent = 0f,
Expand All @@ -177,7 +181,10 @@ internal static class Internal
FullChargedCapacity = 0f,
ChargeDischargeRate = 0f,
ChargeDischargeCurrent = 0f,
RemainingTimeEstimated = 0f
RemainingTimeEstimated = 0f,
ACPowerStatus = string.Empty,
PowerLineStatus = PowerLineStatus.Unknown,
ChargeStatus = BatteryChargeStatus.Unknown
};

public static SBSDMDS MotherboardData = new()
Expand Down
32 changes: 32 additions & 0 deletions src/Project/Sucrose.Backgroundog/Struct/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,38 @@ public struct BatteryStruct
/// <summary>
///
/// </summary>
public bool SavingMode;
/// <summary>
///
/// </summary>
public int FullLifetime;
/// <summary>
///
/// </summary>
public float? ChargeRate;
/// <summary>
///
/// </summary>
public int LifeRemaining;
/// <summary>
///
/// </summary>
public float LifePercent;
/// <summary>
///
/// </summary>
public string SaverStatus;
/// <summary>
///
/// </summary>
public float? ChargeLevel;
/// <summary>
///
/// </summary>
public string ACPowerStatus;
/// <summary>
///
/// </summary>
public float? ChargeCurrent;
/// <summary>
///
Expand Down Expand Up @@ -366,6 +390,14 @@ public struct BatteryStruct
///
/// </summary>
public float? RemainingTimeEstimated;
/// <summary>
///
/// </summary>
public PowerLineStatus PowerLineStatus;
/// <summary>
///
/// </summary>
public BatteryChargeStatus ChargeStatus;
}

/// <summary>
Expand Down

0 comments on commit 2e7740d

Please sign in to comment.