From 7f44759a83b0166931b5a2d8c2e2cd2859ab1e24 Mon Sep 17 00:00:00 2001 From: Taiizor <41683699+Taiizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:25:32 +0300 Subject: [PATCH] Preparing Performance Setting Page --- src/Library/Sucrose.Manager/Manage/Manager.cs | 2 + src/Library/Sucrose.Memory/Constant.cs | 6 + src/Portal/Sucrose.Portal/Manage/Manager.cs | 4 + .../Setting/PerformanceSettingViewModel.cs | 121 ++++++++++++++++++ 4 files changed, 133 insertions(+) diff --git a/src/Library/Sucrose.Manager/Manage/Manager.cs b/src/Library/Sucrose.Manager/Manage/Manager.cs index 56037fe75..014bb4493 100644 --- a/src/Library/Sucrose.Manager/Manage/Manager.cs +++ b/src/Library/Sucrose.Manager/Manage/Manager.cs @@ -59,6 +59,8 @@ 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 UploadValue => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.UploadValue, 800); public static int MemoryUsage => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.MemoryUsage, 75); diff --git a/src/Library/Sucrose.Memory/Constant.cs b/src/Library/Sucrose.Memory/Constant.cs index 0f40a568f..f432f44a0 100644 --- a/src/Library/Sucrose.Memory/Constant.cs +++ b/src/Library/Sucrose.Memory/Constant.cs @@ -72,6 +72,8 @@ public static class Constant public const string UploadValue = "UploadValue"; + public const string BatteryUsage = "BatteryUsage"; + public const string BackdropType = "BackdropType"; public const string CefArguments = "CefArguments"; @@ -122,6 +124,8 @@ public static class Constant public const string ExpandScreenType = "ExpandScreenType"; + public const string SaverPerformance = "SaverPerformance"; + public const string BackgroundOpacity = "BackgroundOpacity"; public const string BackgroundStretch = "BackgroundStretch"; @@ -138,6 +142,8 @@ public static class Constant public const string NetworkPerformance = "NetworkPerformance"; + public const string BatteryPerformance = "BatteryPerformance"; + public const string DuplicateScreenType = "DuplicateScreenType"; } } \ No newline at end of file diff --git a/src/Portal/Sucrose.Portal/Manage/Manager.cs b/src/Portal/Sucrose.Portal/Manage/Manager.cs index 00a1a2d5c..3a8e1237e 100644 --- a/src/Portal/Sucrose.Portal/Manage/Manager.cs +++ b/src/Portal/Sucrose.Portal/Manage/Manager.cs @@ -20,8 +20,12 @@ 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 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 IPAddress Host => SMMI.LauncherSettingManager.GetSettingAddress(SMC.Host, IPAddress.Loopback); diff --git a/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs b/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs index 695bf6c77..ecee02d55 100644 --- a/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs +++ b/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs @@ -339,6 +339,97 @@ private void InitializeViewModel() Contents.Add(Network); + TextBlock LaptopArea = new() + { + Foreground = SSRER.GetResource("TextFillColorPrimaryBrush"), + Margin = new Thickness(0, 10, 0, 0), + FontWeight = FontWeights.Bold, + Text = "Dizüstü" + }; + + Contents.Add(LaptopArea); + + SPVCEC Battery = new() + { + Margin = new Thickness(0, 10, 0, 0) + }; + + Battery.Title.Text = "Pil Gücü"; + Battery.LeftIcon.Symbol = SymbolRegular.Battery624; + Battery.Description.Text = "Dizüstü bilgisayar pil gücünde çalışırken duvar kağıdına ne olacağı."; + + ComboBox BatteryPerformance = new(); + + BatteryPerformance.SelectionChanged += (s, e) => BatteryPerformanceSelected(BatteryPerformance.SelectedIndex); + + foreach (SSDEPT Type in Enum.GetValues(typeof(SSDEPT))) + { + BatteryPerformance.Items.Add(Type); + } + + BatteryPerformance.SelectedIndex = (int)SPMM.BatteryPerformance; + + Battery.HeaderFrame = BatteryPerformance; + + StackPanel BatteryContent = new() + { + Orientation = Orientation.Horizontal + }; + + TextBlock BatteryUsageText = new() + { + Foreground = SSRER.GetResource("TextFillColorPrimaryBrush"), + VerticalAlignment = VerticalAlignment.Center, + Margin = new Thickness(0, 0, 10, 0), + FontWeight = FontWeights.SemiBold, + Text = "Pil Durumu (%):" + }; + + NumberBox BatteryUsage = new() + { + Margin = new Thickness(0, 0, 10, 0), + ClearButtonEnabled = false, + Value = SMMM.BatteryUsage, + MaxDecimalPlaces = 0, + Maximum = 100, + MaxLength = 3, + Minimum = 0 + }; + + BatteryUsage.ValueChanged += (s, e) => BatteryUsageChanged(BatteryUsage.Value); + + BatteryContent.Children.Add(BatteryUsageText); + BatteryContent.Children.Add(BatteryUsage); + + Battery.FooterCard = BatteryContent; + + Contents.Add(Battery); + + SPVCEC Saver = new() + { + Margin = new Thickness(0, 10, 0, 0), + Expandable = false + }; + + Saver.Title.Text = "Pil Tasarrufu"; + Saver.LeftIcon.Symbol = SymbolRegular.BatterySaver24; + Saver.Description.Text = "Dizüstü bilgisayar pil tasarrufu modundayken duvar kağıdına ne olacağı."; + + ComboBox SaverPerformance = new(); + + SaverPerformance.SelectionChanged += (s, e) => SaverPerformanceSelected(SaverPerformance.SelectedIndex); + + foreach (SSDEPT Type in Enum.GetValues(typeof(SSDEPT))) + { + SaverPerformance.Items.Add(Type); + } + + SaverPerformance.SelectedIndex = (int)SPMM.SaverPerformance; + + Saver.HeaderFrame = SaverPerformance; + + Contents.Add(Saver); + _isInitialized = true; } @@ -399,6 +490,16 @@ 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); @@ -409,6 +510,16 @@ private void NetworkUploadChanged(double? Value) } } + private void SaverPerformanceSelected(int Index) + { + if (Index != (int)SPMM.SaverPerformance) + { + SSDEPT Type = (SSDEPT)Index; + + SMMI.BackgroundogSettingManager.SetSetting(SMC.SaverPerformance, Type); + } + } + private void NetworkUploadTypeSelected(int Index) { if (Index != (int)SMMM.UploadType) @@ -447,6 +558,16 @@ private void NetworkPerformanceSelected(int Index) } } + private void BatteryPerformanceSelected(int Index) + { + if (Index != (int)SPMM.BatteryPerformance) + { + SSDEPT Type = (SSDEPT)Index; + + SMMI.BackgroundogSettingManager.SetSetting(SMC.BatteryPerformance, Type); + } + } + private void NetworkDownloadChanged(double? Value) { int NewValue = Convert.ToInt32(Value);