diff --git a/src/Library/Sucrose.Manager/Manage/Manager.cs b/src/Library/Sucrose.Manager/Manage/Manager.cs index 014bb4493..4facc0316 100644 --- a/src/Library/Sucrose.Manager/Manage/Manager.cs +++ b/src/Library/Sucrose.Manager/Manage/Manager.cs @@ -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); @@ -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); diff --git a/src/Portal/Sucrose.Portal/Manage/Manager.cs b/src/Portal/Sucrose.Portal/Manage/Manager.cs index 3a8e1237e..6e4b31886 100644 --- a/src/Portal/Sucrose.Portal/Manage/Manager.cs +++ b/src/Portal/Sucrose.Portal/Manage/Manager.cs @@ -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); diff --git a/src/Project/Sucrose.Backgroundog/Helper/Condition.cs b/src/Project/Sucrose.Backgroundog/Helper/Condition.cs index e530eba12..604a18f0e 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Condition.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Condition.cs @@ -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; @@ -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; @@ -89,5 +105,95 @@ private static async Task CpuCondition() return false; } + + private static async Task 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 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 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; + } } } \ No newline at end of file diff --git a/src/Project/Sucrose.Backgroundog/Helper/Performance.cs b/src/Project/Sucrose.Backgroundog/Helper/Performance.cs index c95ddf30a..adc44924a 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Performance.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Performance.cs @@ -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; @@ -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; } @@ -81,5 +96,95 @@ private static async Task CpuPerformance() return false; } + + private static async Task 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 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 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; + } } } \ No newline at end of file diff --git a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs index 4b99942be..3517dba78 100644 --- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs +++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs @@ -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; @@ -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; diff --git a/src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs b/src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs index 38dfda930..fcce0c9ce 100644 --- a/src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs +++ b/src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs @@ -7,6 +7,13 @@ internal enum PerformanceType Resume } + internal enum NetworkPerformanceType + { + Not, + Upload, + Download + } + internal enum CategoryPerformanceType { Not,