From 10554039e5e79d6fe58422d55e068120a9306352 Mon Sep 17 00:00:00 2001 From: NoobNotFound Date: Sun, 1 Dec 2024 17:00:50 +0530 Subject: [PATCH] convert appearance page. --- Emerald/DirectResources.cs | 2 +- Emerald/Emerald.csproj | 7 +- Emerald/Helpers/Extensions.cs | 48 +++--- Emerald/Views/Settings/AppearancePage.xaml | 116 ++++++++++++++ Emerald/Views/Settings/AppearancePage.xaml.cs | 147 ++++++++++++++++++ Emerald/Views/Settings/SettingsPage.xaml.cs | 2 +- 6 files changed, 301 insertions(+), 21 deletions(-) create mode 100644 Emerald/Views/Settings/AppearancePage.xaml create mode 100644 Emerald/Views/Settings/AppearancePage.xaml.cs diff --git a/Emerald/DirectResources.cs b/Emerald/DirectResources.cs index f2d25777..f72ac03c 100644 --- a/Emerald/DirectResources.cs +++ b/Emerald/DirectResources.cs @@ -9,7 +9,7 @@ namespace Emerald; public static class DirectResoucres { public static int MaxRAM - => Extensions.GetMemoryGB() * 1024; + => (Extensions.GetMemoryGB() ?? 192) * 1024; //switches maximum ram if failed, I couldn't find the max ram for MC. public static int MinRAM => 512; diff --git a/Emerald/Emerald.csproj b/Emerald/Emerald.csproj index 523591d0..14bc28dd 100644 --- a/Emerald/Emerald.csproj +++ b/Emerald/Emerald.csproj @@ -1,4 +1,4 @@ - + net8.0-maccatalyst; @@ -49,6 +49,7 @@ + @@ -90,4 +91,8 @@ + + + + diff --git a/Emerald/Helpers/Extensions.cs b/Emerald/Helpers/Extensions.cs index 62482347..04854cfd 100644 --- a/Emerald/Helpers/Extensions.cs +++ b/Emerald/Helpers/Extensions.cs @@ -31,12 +31,20 @@ public static class Extensions // } //} - public static int GetMemoryGB() + public static int? GetMemoryGB() { - SystemMemoryUsageReport systemMemoryUsageReport = SystemDiagnosticInfo.GetForCurrentSystem().MemoryUsage.GetReport(); + SystemMemoryUsageReport? systemMemoryUsageReport = SystemDiagnosticInfo.GetForCurrentSystem()?.MemoryUsage?.GetReport(); - long memkb = Convert.ToInt64(systemMemoryUsageReport.TotalPhysicalSizeInBytes); - return Convert.ToInt32(memkb / Math.Pow(1024, 3)); + try + { + long memkb = Convert.ToInt64(systemMemoryUsageReport?.TotalPhysicalSizeInBytes); + return Convert.ToInt32(memkb / Math.Pow(1024, 3)); + } + catch + { + + return null; + } } public static string KiloFormat(this int num) @@ -56,20 +64,24 @@ public static string KiloFormat(this int num) return num.ToString("#,0"); } - //public static ContentDialog ToContentDialog(this UIElement content, string title, string closebtnText = null, ContentDialogButton defaultButton = ContentDialogButton.Close) - //{ - // ContentDialog dialog = new() - // { - // XamlRoot = App.Current.MainWindow.Content.XamlRoot, - // Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style, - // Title = title, - // CloseButtonText = closebtnText, - // DefaultButton = defaultButton, - // Content = content, - // RequestedTheme = (ElementTheme)Settings.SettingsSystem.Settings.App.Appearance.Theme - // }; - // return dialog; - //} + public static ContentDialog ToContentDialog(this UIElement content, string title, string closebtnText = null, ContentDialogButton defaultButton = ContentDialogButton.Close, bool addScrollBar = true) + { + ContentDialog dialog = new() + { + XamlRoot = App.Current.MainWindow.Content.XamlRoot, + Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style, + Title = title, + CloseButtonText = closebtnText, + DefaultButton = defaultButton, + Content = addScrollBar ? new ScrollViewer() + { + Content = content, + Padding = new(12) + } : content, + RequestedTheme = (ElementTheme)Settings.SettingsSystem.Settings.App.Appearance.Theme + }; + return dialog; + } public static int Remove(this ObservableCollection coll, Func condition) { diff --git a/Emerald/Views/Settings/AppearancePage.xaml b/Emerald/Views/Settings/AppearancePage.xaml new file mode 100644 index 00000000..951d2069 --- /dev/null +++ b/Emerald/Views/Settings/AppearancePage.xaml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +