diff --git a/src/Library/Sucrose.Manager/Manage/Internal.cs b/src/Library/Sucrose.Manager/Manage/Internal.cs index 4737ffc85..27e6a8873 100644 --- a/src/Library/Sucrose.Manager/Manage/Internal.cs +++ b/src/Library/Sucrose.Manager/Manage/Internal.cs @@ -21,6 +21,8 @@ public static class Internal public static readonly SMLM PortalLogManager = new("Portal-{0}.log"); + public static readonly SMSM SystemSettingManager = new("System.json"); + public static readonly SMSM PortalSettingManager = new("Portal.json"); public static readonly SMSM AuroraSettingManager = new("Aurora.json"); diff --git a/src/Library/Sucrose.Manager/Manage/Manager.cs b/src/Library/Sucrose.Manager/Manage/Manager.cs index 686eeda31..f29178af6 100644 --- a/src/Library/Sucrose.Manager/Manage/Manager.cs +++ b/src/Library/Sucrose.Manager/Manage/Manager.cs @@ -1,4 +1,5 @@ -using SHC = Skylark.Helper.Culture; +using SEST = Skylark.Enum.StorageType; +using SHC = Skylark.Helper.Culture; using SHS = Skylark.Helper.Skymath; using SMC = Sucrose.Memory.Constant; using SMMI = Sucrose.Manager.Manage.Internal; @@ -20,6 +21,8 @@ public static class Manager public static int LibraryPagination => SHS.Clamp(SMMI.PortalSettingManager.GetSettingStable(SMC.LibraryPagination, 36), 1, 100); + public static string[] NetworkInterfaces => SMMI.SystemSettingManager.GetSetting(SMC.NetworkInterfaces, Array.Empty()); + public static string Culture => SMMI.GeneralSettingManager.GetSetting(SMC.CultureName, SHC.CurrentUITwoLetterISOLanguageName); public static int StorePagination => SHS.Clamp(SMMI.PortalSettingManager.GetSettingStable(SMC.StorePagination, 30), 1, 100); @@ -48,6 +51,10 @@ public static class Manager public static string BackgroundImage => SMMI.PortalSettingManager.GetSetting(SMC.BackgroundImage, string.Empty); + public static SEST DownloadType => SMMI.BackgroundogSettingManager.GetSetting(SMC.DownloadType, SEST.Kilobyte); + + public static SEST UploadType => SMMI.BackgroundogSettingManager.GetSetting(SMC.UploadType, SEST.Kilobyte); + public static int Volume => SHS.Clamp(SMMI.EngineSettingManager.GetSettingStable(SMC.Volume, 100), 0, 100); public static int DownloadValue => SMMI.BackgroundogSettingManager.GetSettingStable(SMC.DownloadValue, 0); diff --git a/src/Library/Sucrose.Manager/SettingManager.cs b/src/Library/Sucrose.Manager/SettingManager.cs index d5fd4536a..3c6c16d30 100644 --- a/src/Library/Sucrose.Manager/SettingManager.cs +++ b/src/Library/Sucrose.Manager/SettingManager.cs @@ -258,6 +258,17 @@ private T ConvertToType(object value) return (T)(object)new KeyValuePair(parts[0].Trim(), parts[1].Trim()); } + else if (type == typeof(string[])) + { + if (value is string[] array) + { + return (T)(object)array; + } + else if (value is JArray jArray) + { + return (T)(object)jArray.Select(jValue => (string)jValue).ToArray(); + } + } else if (type == typeof(List)) { if (value is List list) diff --git a/src/Library/Sucrose.Memory/Constant.cs b/src/Library/Sucrose.Memory/Constant.cs index f87afa8bb..facd019bc 100644 --- a/src/Library/Sucrose.Memory/Constant.cs +++ b/src/Library/Sucrose.Memory/Constant.cs @@ -50,6 +50,8 @@ public static class Constant public const string ScreenType = "ScreenType"; + public const string UploadType = "UploadType"; + public const string LibraryMove = "LibraryMove"; public const string ScreenIndex = "ScreenIndex"; @@ -76,6 +78,8 @@ public static class Constant public const string DiscordState = "DiscordState"; + public const string DownloadType = "DownloadType"; + public const string DownloadValue = "DownloadValue"; public const string DonateVisible = "DonateVisible"; @@ -120,8 +124,12 @@ public static class Constant public const string DescriptionLength = "DescriptionLength"; + public const string NetworkInterfaces = "NetworkInterfaces"; + public const string PerformanceCounter = "PerformanceCounter"; + public const string NetworkPerformance = "NetworkPerformance"; + 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 0343206ef..4afbc14c5 100644 --- a/src/Portal/Sucrose.Portal/Manage/Manager.cs +++ b/src/Portal/Sucrose.Portal/Manage/Manager.cs @@ -7,6 +7,7 @@ using SMMI = Sucrose.Manager.Manage.Internal; using SMR = Sucrose.Memory.Readonly; using SSDEST = Sucrose.Shared.Dependency.Enum.StretchType; +using SSDEPT = Sucrose.Shared.Dependency.Enum.PerformanceType; using SWHWT = Skylark.Wing.Helper.WindowsTheme; namespace Sucrose.Portal.Manage @@ -17,6 +18,8 @@ internal static class Manager public static WindowBackdropType BackdropType => SMMI.PortalSettingManager.GetSetting(SMC.BackdropType, DefaultBackdropType); + public static SSDEPT NetworkPerformance => SMMI.BackgroundogSettingManager.GetSetting(SMC.NetworkPerformance, SSDEPT.Resume); + public static IPAddress Host => SMMI.LauncherSettingManager.GetSettingAddress(SMC.Host, IPAddress.Loopback); public static SEST ScreenType => SMMI.EngineSettingManager.GetSetting(SMC.ScreenType, SEST.DisplayBound); diff --git a/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs b/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs index 0a60f9b77..15cdcea64 100644 --- a/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs +++ b/src/Portal/Sucrose.Portal/ViewModels/Pages/Setting/PerformanceSettingViewModel.cs @@ -3,14 +3,16 @@ using System.Windows.Controls; using System.Windows.Media; using Wpf.Ui.Controls; +using SEST = Skylark.Enum.StorageType; using SMC = Sucrose.Memory.Constant; using SMMI = Sucrose.Manager.Manage.Internal; using SMMM = Sucrose.Manager.Manage.Manager; +using SPMM = Sucrose.Portal.Manage.Manager; using SMR = Sucrose.Memory.Readonly; using SPVCEC = Sucrose.Portal.Views.Controls.ExpanderCard; using SSDECT = Sucrose.Shared.Dependency.Enum.CommandsType; +using SSDEPT = Sucrose.Shared.Dependency.Enum.PerformanceType; using SSRER = Sucrose.Shared.Resources.Extension.Resources; -using SSSHN = Sucrose.Shared.Space.Helper.Network; using SSSHP = Sucrose.Shared.Space.Helper.Processor; using SSSMI = Sucrose.Shared.Space.Manage.Internal; using TextBlock = System.Windows.Controls.TextBlock; @@ -76,39 +78,65 @@ private void InitializeViewModel() Contents.Add(SystemResourcesArea); - SPVCEC Adapter = new() + SPVCEC Network = new() { Margin = new Thickness(0, 10, 0, 0) }; - Adapter.Title.Text = "Ağ Kullanımı"; - Adapter.LeftIcon.Symbol = SymbolRegular.NetworkCheck24; - Adapter.Description.Text = "Ağ kullanımı belirlenen sınırı geçtiğinde duvar kağıdına ne olacağı."; + Network.Title.Text = "Ağ Kullanımı"; + Network.LeftIcon.Symbol = SymbolRegular.NetworkCheck24; + Network.Description.Text = "Ağ kullanımı belirlenen sınırı geçtiğinde duvar kağıdına ne olacağı."; + + ComboBox NetworkPerformance = new(); + + NetworkPerformance.SelectionChanged += (s, e) => NetworkPerformanceSelected(NetworkPerformance.SelectedIndex); + + foreach (SSDEPT Type in Enum.GetValues(typeof(SSDEPT))) + { + NetworkPerformance.Items.Add(Type); + } + + NetworkPerformance.SelectedIndex = (int)SPMM.NetworkPerformance; + + Network.HeaderFrame = NetworkPerformance; + + StackPanel NetworkContent = new(); + + StackPanel NetworkAdapterContent = new() + { + Orientation = Orientation.Horizontal + }; + + TextBlock NetworkAdapterText = new() + { + Foreground = SSRER.GetResource("TextFillColorPrimaryBrush"), + VerticalAlignment = VerticalAlignment.Center, + Margin = new Thickness(0, 0, 10, 0), + FontWeight = FontWeights.SemiBold, + Text = "Ağ Adaptörü:" + }; ComboBox NetworkAdapter = new() { - MaxWidth = 250 + MaxWidth = 700 }; NetworkAdapter.SelectionChanged += (s, e) => NetworkAdapterSelected($"{NetworkAdapter.SelectedValue}"); - foreach (string Network in SSSHN.InstanceNetworkInterfaces()) + foreach (string Interface in SMMM.NetworkInterfaces) { - NetworkAdapter.Items.Add(Network); + NetworkAdapter.Items.Add(Interface); } NetworkAdapter.SelectedValue = SMMM.NetworkAdapter; - Adapter.HeaderFrame = NetworkAdapter; - - StackPanel AdapterContent = new(); - - StackPanel AdapterUploadContent = new() + StackPanel NetworkUploadContent = new() { - Orientation = Orientation.Horizontal + Orientation = Orientation.Horizontal, + Margin = new Thickness(0, 10, 0, 0) }; - TextBlock AdapterUploadText = new() + TextBlock NetworkUploadText = new() { Foreground = SSRER.GetResource("TextFillColorPrimaryBrush"), VerticalAlignment = VerticalAlignment.Center, @@ -117,8 +145,9 @@ private void InitializeViewModel() Text = "Yükleme Boyutu:" }; - NumberBox AdapterUpload = new() + NumberBox NetworkUpload = new() { + Margin = new Thickness(0, 0, 10, 0), ClearButtonEnabled = false, Value = SMMM.UploadValue, MaxDecimalPlaces = 0, @@ -127,13 +156,24 @@ private void InitializeViewModel() Minimum = 0 }; - StackPanel AdapterDownloadContent = new() + ComboBox NetworkUploadType = new(); + + NetworkUploadType.SelectionChanged += (s, e) => NetworkUploadTypeSelected(NetworkUploadType.SelectedIndex); + + foreach (SEST Type in Enum.GetValues(typeof(SEST))) + { + NetworkUploadType.Items.Add(Type); + } + + NetworkUploadType.SelectedIndex = (int)SMMM.UploadType; + + StackPanel NetworkDownloadContent = new() { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 10, 0, 0) }; - TextBlock AdapterDownloadText = new() + TextBlock NetworkDownloadText = new() { Foreground = SSRER.GetResource("TextFillColorPrimaryBrush"), VerticalAlignment = VerticalAlignment.Center, @@ -142,8 +182,9 @@ private void InitializeViewModel() Text = "İndirme Boyutu:" }; - NumberBox AdapterDownload = new() + NumberBox NetworkDownload = new() { + Margin = new Thickness(0, 0, 10, 0), ClearButtonEnabled = false, Value = SMMM.DownloadValue, MaxDecimalPlaces = 0, @@ -152,18 +193,35 @@ private void InitializeViewModel() Minimum = 0 }; - AdapterUploadContent.Children.Add(AdapterUploadText); - AdapterUploadContent.Children.Add(AdapterUpload); + ComboBox NetworkDownloadType = new(); + + NetworkDownloadType.SelectionChanged += (s, e) => NetworkDownloadTypeSelected(NetworkDownloadType.SelectedIndex); + + foreach (SEST Type in Enum.GetValues(typeof(SEST))) + { + NetworkDownloadType.Items.Add(Type); + } + + NetworkDownloadType.SelectedIndex = (int)SMMM.DownloadType; + + NetworkAdapterContent.Children.Add(NetworkAdapterText); + NetworkAdapterContent.Children.Add(NetworkAdapter); - AdapterDownloadContent.Children.Add(AdapterDownloadText); - AdapterDownloadContent.Children.Add(AdapterDownload); + NetworkUploadContent.Children.Add(NetworkUploadText); + NetworkUploadContent.Children.Add(NetworkUpload); + NetworkUploadContent.Children.Add(NetworkUploadType); - AdapterContent.Children.Add(AdapterUploadContent); - AdapterContent.Children.Add(AdapterDownloadContent); + NetworkDownloadContent.Children.Add(NetworkDownloadText); + NetworkDownloadContent.Children.Add(NetworkDownload); + NetworkDownloadContent.Children.Add(NetworkDownloadType); - Adapter.FooterCard = AdapterContent; + NetworkContent.Children.Add(NetworkAdapterContent); + NetworkContent.Children.Add(NetworkUploadContent); + NetworkContent.Children.Add(NetworkDownloadContent); - Contents.Add(Adapter); + Network.FooterCard = NetworkContent; + + Contents.Add(Network); _isInitialized = true; } @@ -195,6 +253,16 @@ private void CounterStateChecked(bool State) } } + private void NetworkUploadTypeSelected(int Index) + { + if (Index != (int)SMMM.UploadType) + { + SEST Type = (SEST)Index; + + SMMI.BackgroundogSettingManager.SetSetting(SMC.UploadType, Type); + } + } + private void NetworkAdapterSelected(string Value) { if (Value != SMMM.NetworkAdapter) @@ -203,6 +271,26 @@ private void NetworkAdapterSelected(string Value) } } + private void NetworkPerformanceSelected(int Index) + { + if (Index != (int)SPMM.NetworkPerformance) + { + SSDEPT Type = (SSDEPT)Index; + + SMMI.BackgroundogSettingManager.SetSetting(SMC.NetworkPerformance, Type); + } + } + + private void NetworkDownloadTypeSelected(int Index) + { + if (Index != (int)SMMM.DownloadType) + { + SEST Type = (SEST)Index; + + SMMI.BackgroundogSettingManager.SetSetting(SMC.DownloadType, Type); + } + } + public void Dispose() { Contents.Clear(); diff --git a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs index 0ebe37d2f..37a5e7c24 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs @@ -1,4 +1,5 @@ -using LibreHardwareMonitor.Hardware; +using Google.Protobuf.WellKnownTypes; +using LibreHardwareMonitor.Hardware; using Skylark.Enum; using Skylark.Helper; using Skylark.Standard.Extension.Storage; @@ -8,6 +9,8 @@ using SBMI = Sucrose.Backgroundog.Manage.Internal; using SMMM = Sucrose.Manager.Manage.Manager; using SSSHN = Sucrose.Shared.Space.Helper.Network; +using SMMI = Sucrose.Manager.Manage.Internal; +using SMC = Sucrose.Memory.Constant; namespace Sucrose.Backgroundog.Helper { @@ -92,31 +95,43 @@ public static async Task Start() _ = Task.Run(() => { - foreach (string Name in SSSHN.InstanceNetworkInterfaces()) + string[] Interfaces = SSSHN.InstanceNetworkInterfaces(); + + SMMI.SystemSettingManager.SetSetting(SMC.NetworkInterfaces, Interfaces); + + if (Interfaces.Contains(SMMM.NetworkAdapter)) { - if (SMMM.NetworkAdapter == Name) + foreach (string Name in Interfaces) { - if (SMMM.NetworkAdapter != SBMI.NetworkData.Name) + if (SMMM.NetworkAdapter == Name) { - SBMI.NetworkData.State = true; - SBMI.NetworkData.Name = SMMM.NetworkAdapter; + if (SMMM.NetworkAdapter != SBMI.NetworkData.Name) + { + SBMI.NetworkData.State = true; + SBMI.NetworkData.Name = SMMM.NetworkAdapter; - SBMI.UploadCounter = new("Network Interface", "Bytes Sent/sec", Name); - SBMI.DownloadCounter = new("Network Interface", "Bytes Received/sec", Name); - } + SBMI.UploadCounter = new("Network Interface", "Bytes Sent/sec", Name); + SBMI.DownloadCounter = new("Network Interface", "Bytes Received/sec", Name); + } - SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue(); - SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue(); + SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue(); + SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue(); - SBMI.NetworkData.UploadData = StorageExtension.AutoConvert(SBMI.NetworkData.Upload, StorageType.Byte, ModeStorageType.Palila); - SBMI.NetworkData.DownloadData = StorageExtension.AutoConvert(SBMI.NetworkData.Download, StorageType.Byte, ModeStorageType.Palila); + SBMI.NetworkData.UploadData = StorageExtension.AutoConvert(SBMI.NetworkData.Upload, StorageType.Byte, ModeStorageType.Palila); + SBMI.NetworkData.DownloadData = StorageExtension.AutoConvert(SBMI.NetworkData.Download, StorageType.Byte, ModeStorageType.Palila); - SBMI.NetworkData.FormatUploadData = Numeric.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.UploadData.Text; - SBMI.NetworkData.FormatDownloadData = Numeric.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.DownloadData.Text; + SBMI.NetworkData.FormatUploadData = Numeric.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.UploadData.Text; + SBMI.NetworkData.FormatDownloadData = Numeric.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.DownloadData.Text; - break; + break; + } } } + else + { + SBMI.NetworkData.State = false; + SBMI.NetworkData.Name = SMMM.NetworkAdapter; + } }); _ = Task.Run(() => diff --git a/src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs b/src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs new file mode 100644 index 000000000..64a958277 --- /dev/null +++ b/src/Shared/Sucrose.Shared.Dependency/Enum/PerformanceType.cs @@ -0,0 +1,9 @@ +namespace Sucrose.Shared.Dependency.Enum +{ + internal enum PerformanceType + { + Close, + Pause, + Resume + } +} \ No newline at end of file diff --git a/src/Shared/Sucrose.Shared.Dependency/Sucrose.Shared.Dependency.projitems b/src/Shared/Sucrose.Shared.Dependency/Sucrose.Shared.Dependency.projitems index 667aaf159..8c3af6e09 100644 --- a/src/Shared/Sucrose.Shared.Dependency/Sucrose.Shared.Dependency.projitems +++ b/src/Shared/Sucrose.Shared.Dependency/Sucrose.Shared.Dependency.projitems @@ -11,6 +11,7 @@ +