Skip to content

Commit

Permalink
Preparing Backgroundog
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 21, 2023
1 parent 7f47b5a commit 3a2425b
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Library/Sucrose.Manager/Manage/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public static class Manager

public static int DownloadValue => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.DownloadValue, 10);

public static int BatteryUsage => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.BatteryUsage, 75);
public static int BatteryUsage => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.BatteryUsage, 50);

public static int UploadValue => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.UploadValue, 800);

public static int MemoryUsage => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.MemoryUsage, 75);
public static int MemoryUsage => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.MemoryUsage, 80);

public static string UserAgent => SMMI.GeneralSettingManager.GetSetting(SMC.UserAgent, SMR.UserAgent);

Expand All @@ -79,7 +79,7 @@ public static class Manager

public static bool AdvertisingState => SMMI.DonateManager.GetSetting(SMC.AdvertisingState, true);

public static int CpuUsage => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.CpuUsage, 75);
public static int CpuUsage => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.CpuUsage, 70);

public static int ScreenIndex => SMMI.EngineSettingManager.GetSettingStable(SMC.ScreenIndex, 0);

Expand Down
4 changes: 2 additions & 2 deletions src/Portal/Sucrose.Portal/Manage/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ internal static class Manager

public static SSDEPT NetworkPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.NetworkPerformance, SSDEPT.Resume);

public static SSDEPT BatteryPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.BatteryPerformance, SSDEPT.Pause);
public static SSDEPT BatteryPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.BatteryPerformance, SSDEPT.Close);

public static SSDEPT MemoryPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.MemoryPerformance, SSDEPT.Pause);

public static SSDEPT SaverPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.SaverPerformance, SSDEPT.Pause);

public static SSDEPT CpuPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.CpuPerformance, SSDEPT.Pause);
public static SSDEPT CpuPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.CpuPerformance, SSDEPT.Close);

public static IPAddress Host => SMMI.LauncherSettingManager.GetSettingAddress(SMC.Host, IPAddress.Loopback);

Expand Down
106 changes: 106 additions & 0 deletions src/Project/Sucrose.Backgroundog/Helper/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SMMM = Sucrose.Manager.Manage.Manager;
using SSDECPT = Sucrose.Shared.Dependency.Enum.CategoryPerformanceType;
using SSDEPT = Sucrose.Shared.Dependency.Enum.PerformanceType;
using SSDENPT = Sucrose.Shared.Dependency.Enum.NetworkPerformanceType;
using SSLHR = Sucrose.Shared.Live.Helper.Run;
using SSSHL = Sucrose.Shared.Space.Helper.Live;
using SSSHP = Sucrose.Shared.Space.Helper.Processor;
Expand All @@ -28,6 +29,21 @@ public static async Task Start()
{
return;
}

if (await SaverCondition())
{
return;
}

if (await MemoryCondition())
{
return;
}

if (await BatteryCondition())
{
return;
}
}

await Task.CompletedTask;
Expand Down Expand Up @@ -89,5 +105,95 @@ private static async Task<bool> CpuCondition()

return false;
}

private static async Task<bool> SaverCondition()
{
if (SBMI.CategoryPerformance == SSDECPT.Saver)
{
int Count = 0;
int MaxCount = 3;

while (!SBMI.BatteryData.SavingMode || SBMI.BatteryData.SaverStatus == "Off" || SBMM.SaverPerformance == SSDEPT.Resume)
{
if (Count >= MaxCount)
{
Lifecycle();
SBMI.Condition = false;
SBMI.Performance = SSDEPT.Resume;
SBMI.CategoryPerformance = SSDECPT.Not;

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}

private static async Task<bool> MemoryCondition()
{
if (SBMI.CategoryPerformance == SSDECPT.Memory)
{
int Count = 0;
int MaxCount = 3;

while (SBMI.MemoryData.MemoryLoad < SMMM.MemoryUsage || SBMM.MemoryPerformance == SSDEPT.Resume)
{
if (Count >= MaxCount)
{
Lifecycle();
SBMI.Condition = false;
SBMI.Performance = SSDEPT.Resume;
SBMI.CategoryPerformance = SSDECPT.Not;

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}

private static async Task<bool> BatteryCondition()
{
if (SBMI.CategoryPerformance == SSDECPT.Battery)
{
int Count = 0;
int MaxCount = 3;

while (SBMI.BatteryData.ChargeLevel > SMMM.BatteryUsage || SBMM.BatteryPerformance == SSDEPT.Resume)
{
if (Count >= MaxCount)
{
Lifecycle();
SBMI.Condition = false;
SBMI.Performance = SSDEPT.Resume;
SBMI.CategoryPerformance = SSDECPT.Not;

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}
}
}
109 changes: 107 additions & 2 deletions src/Project/Sucrose.Backgroundog/Helper/Performance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SBMI = Sucrose.Backgroundog.Manage.Internal;
using SBMM = Sucrose.Backgroundog.Manage.Manager;
using SMMM = Sucrose.Manager.Manage.Manager;
using SSDENPT = Sucrose.Shared.Dependency.Enum.NetworkPerformanceType;
using SSDECPT = Sucrose.Shared.Dependency.Enum.CategoryPerformanceType;
using SSDEPT = Sucrose.Shared.Dependency.Enum.PerformanceType;
using SSLHK = Sucrose.Shared.Live.Helper.Kill;
Expand All @@ -14,14 +15,28 @@ internal static class Performance
{
public static async Task Start()
{
Console.WriteLine("Run");
//Performans şartları kontrol edilecek...
Console.WriteLine("Performance");

if (await CpuPerformance())
{
return;
}

if (await SaverPerformance())
{
return;
}

if (await MemoryPerformance())
{
return;
}

if (await BatteryPerformance())
{
return;
}

await Task.CompletedTask;
}

Expand Down Expand Up @@ -81,5 +96,95 @@ private static async Task<bool> CpuPerformance()

return false;
}

private static async Task<bool> SaverPerformance()
{
if (SBMM.SaverPerformance != SSDEPT.Resume)
{
int Count = 0;
int MaxCount = 5;

while (SBMI.BatteryData.State && (SBMI.BatteryData.SavingMode || SBMI.BatteryData.SaverStatus == "On"))
{
if (Count >= MaxCount)
{
SBMI.Performance = SBMM.SaverPerformance;
SBMI.CategoryPerformance = SSDECPT.Saver;
SBMI.Condition = true;
Lifecycle();

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}

private static async Task<bool> MemoryPerformance()
{
if (SBMM.MemoryPerformance != SSDEPT.Resume)
{
int Count = 0;
int MaxCount = 5;

while (SBMI.MemoryData.State && SMMM.MemoryUsage > 0 && SBMI.MemoryData.MemoryLoad >= SMMM.MemoryUsage)
{
if (Count >= MaxCount)
{
SBMI.Performance = SBMM.MemoryPerformance;
SBMI.CategoryPerformance = SSDECPT.Memory;
SBMI.Condition = true;
Lifecycle();

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}

private static async Task<bool> BatteryPerformance()
{
if (SBMM.BatteryPerformance != SSDEPT.Resume)
{
int Count = 0;
int MaxCount = 5;

while (SBMI.BatteryData.State && SMMM.BatteryUsage > 0 && SBMI.BatteryData.ChargeLevel <= SMMM.BatteryUsage)
{
if (Count >= MaxCount)
{
SBMI.Performance = SBMM.BatteryPerformance;
SBMI.CategoryPerformance = SSDECPT.Battery;
SBMI.Condition = true;
Lifecycle();

return true;
}
else
{
Count++;
}

await Task.Delay(TimeSpan.FromSeconds(1));
}
}

return false;
}
}
}
3 changes: 3 additions & 0 deletions src/Project/Sucrose.Backgroundog/Manage/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using SBSDMDS = Sucrose.Backgroundog.Struct.Data.MotherboardStruct;
using SBSDMYS = Sucrose.Backgroundog.Struct.Data.MemoryStruct;
using SBSDNS = Sucrose.Backgroundog.Struct.Data.NetworkStruct;
using SSDENPT = Sucrose.Shared.Dependency.Enum.NetworkPerformanceType;
using SSDECPT = Sucrose.Shared.Dependency.Enum.CategoryPerformanceType;
using SSDEPT = Sucrose.Shared.Dependency.Enum.PerformanceType;
using Timer = System.Threading.Timer;
Expand Down Expand Up @@ -52,6 +53,8 @@ internal static class Internal

public static PerformanceCounter UploadCounter = null;

public static SSDENPT NetworkPerformance = SSDENPT.Not;

public static SSDECPT CategoryPerformance = SSDECPT.Not;

public static MediaPlaybackDataSource DataSource = null;
Expand Down
7 changes: 7 additions & 0 deletions src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ internal enum PerformanceType
Resume
}

internal enum NetworkPerformanceType
{
Not,
Upload,
Download
}

internal enum CategoryPerformanceType
{
Not,
Expand Down

0 comments on commit 3a2425b

Please sign in to comment.