From 9b4ab212ece92fe502ab02559157844fe0d41ff6 Mon Sep 17 00:00:00 2001 From: Rayen Ghanmi Date: Mon, 8 Jan 2024 18:55:41 +0100 Subject: [PATCH 1/5] check CHANGELOG.md --- App.xaml.cs | 13 +- CHANGELOG.md | 18 + Helpers/LogHelper.cs | 58 ++ Helpers/OptimizationOptions.cs | 7 +- Helpers/OptimizeSystemHelper.cs | 4 - MainWindow.xaml.cs | 1 + Package.appxmanifest | 2 +- RyTuneX.csproj | 5 + Views/DebloatSystemPage.xaml | 13 +- Views/DebloatSystemPage.xaml.cs | 79 +- Views/HomePage.xaml.cs | 1 + Views/OptimizeSystemPage.xaml | 15 +- Views/OptimizeSystemPage.xaml.cs | 1295 +++++++++++++++--------------- Views/SettingsPage.xaml | 8 +- Views/SettingsPage.xaml.cs | 34 +- Views/ShellPage.xaml | 16 +- Views/ShellPage.xaml.cs | 2 +- Views/SystemInfoPage.xaml.cs | 30 +- 18 files changed, 892 insertions(+), 709 deletions(-) create mode 100644 Helpers/LogHelper.cs diff --git a/App.xaml.cs b/App.xaml.cs index ba03ec8..7e756aa 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -61,7 +61,7 @@ public static T GetService() public App() { InitializeComponent(); - + LogHelper.Log("Initializing App"); Host = Microsoft.Extensions.Hosting.Host. CreateDefaultBuilder(). UseContentRoot(AppContext.BaseDirectory). @@ -102,23 +102,17 @@ public App() App.GetService().Initialize(); - UnhandledException += App_UnhandledException; - } - - private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) - { - // TODO: Log and handle exceptions as appropriate. - // https://docs.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.application.unhandledexception. } protected async override void OnLaunched(LaunchActivatedEventArgs args) { base.OnLaunched(args); - bool showWelcomeNotification = ShouldShowWelcomeNotification(); + var showWelcomeNotification = ShouldShowWelcomeNotification(); if (showWelcomeNotification) { + await LogHelper.Log("Showing Welcome Notification"); App.GetService().Show(string.Format("WelcomeNotification".GetLocalized(), AppContext.BaseDirectory)); // Set the flag to indicate that the welcome notification has been shown @@ -143,6 +137,7 @@ private bool ShouldShowWelcomeNotification() private void SetWelcomeNotificationShown() { // Set the flag to true to indicate that the welcome notification has been shown + LogHelper.Log("Setting WelcomeNotificationShown"); ApplicationData.Current.LocalSettings.Values["WelcomeNotificationShown"] = true; } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 674f49e..9ab5943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to this project will be documented in this file. +## 0.7 + +## Added + +- Error Logging for better debugging. +- New `View Logs` HyperLink in Settings Page. + +## Changes + +- Minor UI improvements and fixes. +- Better exception handling. +- Package Name has been changed to `Rayen.RyTuneX`. + +### Fixes + +- Selecting and unselecting a package, then selecting it again, should now attempt to remove it once. +- Crashing when exiting the app while fetching installed apps. + ## 0.6 > [!TIP] diff --git a/Helpers/LogHelper.cs b/Helpers/LogHelper.cs new file mode 100644 index 0000000..e9d2f90 --- /dev/null +++ b/Helpers/LogHelper.cs @@ -0,0 +1,58 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Windows.Storage; + +internal class LogHelper +{ + public static async void ShowErrorMessageAndLog(Exception ex, XamlRoot xamlRoot) + { + var errorMessage = $"Caught Error: {ex.Message}"; + + await LogError(errorMessage); + + InitiliseErrorMessage(errorMessage, xamlRoot); + } + + private static async Task LogToFile(string message, string fileName) + { + try + { + var tempFolder = ApplicationData.Current.TemporaryFolder; + + var logFile = await tempFolder.CreateFileAsync($"{fileName}_{DateTime.Now:yyyy-MM-dd}.txt", CreationCollisionOption.OpenIfExists); + + await FileIO.AppendTextAsync(logFile, $"{DateTime.Now:T}: {message}\n"); + } + catch (Exception logException) + { + Console.WriteLine($"Error logging to file: {logException.Message}"); + } + } + + private static async void InitiliseErrorMessage(string errorMessage, XamlRoot xamlRoot) + { + ContentDialog errorDialog = new ContentDialog + { + Title = "Error", + Content = errorMessage, + CloseButtonText = "Close", + PrimaryButtonText = "Open Logs File" + }; + errorDialog.XamlRoot = xamlRoot; + + errorDialog.PrimaryButtonClick += async (sender, args) => + { + StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder; + StorageFile logFile = await tempFolder.GetFileAsync($"ErrorLogs_{DateTime.Now:yyyy-MM-dd}.txt"); + if (logFile != null) + { + var options = new Windows.System.LauncherOptions(); + options.DisplayApplicationPicker = false; + await Windows.System.Launcher.LaunchFileAsync(logFile, options); + } + }; + await errorDialog.ShowAsync(); + } + public static Task Log(string message) => LogToFile(message, "Logs"); + public static Task LogError(string message) => LogToFile(message, "ErrorLogs"); +} \ No newline at end of file diff --git a/Helpers/OptimizationOptions.cs b/Helpers/OptimizationOptions.cs index 1ff9ae8..36304fe 100644 --- a/Helpers/OptimizationOptions.cs +++ b/Helpers/OptimizationOptions.cs @@ -13,7 +13,7 @@ public static List> GetUWPApps(bool uninstallableOn using (var PowerShellInstance = PowerShell.Create()) { - + LogHelper.Log("Getting Installed Apps [OptimizationOptions.cs]"); PowerShellInstance.AddScript("Set-ExecutionPolicy RemoteSigned -Scope Process"); PowerShellInstance.AddScript("Import-Module Appx") .AddArgument("-ExecutionPolicy Bypass"); @@ -52,7 +52,7 @@ public static List> GetUWPApps(bool uninstallableOn } } } - + LogHelper.Log("Returning Installed Apps [OptimizationOptions.cs]"); return installedApps; } @@ -64,6 +64,7 @@ internal static void StopService(string serviceName) { if (ServiceExists(serviceName)) { + LogHelper.Log($"Stopping svc: {serviceName}"); var sc = new ServiceController(serviceName); if (sc.CanStop) { @@ -77,6 +78,7 @@ internal static void StartInCmd(string command) { return; } + LogHelper.Log("Starting CMD Command"); using var p = new Process(); p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo.FileName = "cmd.exe"; @@ -90,6 +92,7 @@ internal static void StartService(string serviceName) { if (ServiceExists(serviceName)) { + LogHelper.Log($"Starting svc: {serviceName}"); var sc = new ServiceController(serviceName); sc.Start(); } diff --git a/Helpers/OptimizeSystemHelper.cs b/Helpers/OptimizeSystemHelper.cs index 1e6f005..db9cd37 100644 --- a/Helpers/OptimizeSystemHelper.cs +++ b/Helpers/OptimizeSystemHelper.cs @@ -351,16 +351,12 @@ internal static void DisableLegacyVolumeSlider() internal static void EnableTaskbarColor() { - OptimizationOptions.StartInCmd("reg add \"HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\" /v EnableTransparency /t REG_DWORD /d 0 /f"); - OptimizationOptions.StartInCmd("reg add \"HKCU\\SOFTWARE\\Microsoft\\Windows\\DWM\" /v ColorPrevalence /t REG_DWORD /d 00000001 /f"); OptimizationOptions.StartInCmd("reg add \"HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\" /v ColorPrevalence /t REG_DWORD /d 00000000 /f"); } internal static void DisableTaskbarColor() { - OptimizationOptions.StartInCmd("reg add \"HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\" /v EnableTransparency /t REG_DWORD /d 1 /f"); - OptimizationOptions.StartInCmd("reg add \"HKCU\\SOFTWARE\\Microsoft\\Windows\\DWM\" /v ColorPrevalence /t REG_DWORD /d 00000000 /f"); OptimizationOptions.StartInCmd("reg add \"HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\" /v ColorPrevalence /t REG_DWORD /d 00000001 /f"); } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index c16f3f9..a1b6131 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -33,6 +33,7 @@ public sealed partial class MainWindow : WindowEx public MainWindow() { InitializeComponent(); + LogHelper.Log("Initializing MainWindow"); AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico")); Content = null; Title = "AppDisplayName".GetLocalized(); diff --git a/Package.appxmanifest b/Package.appxmanifest index 3cdf5ed..f59d8b6 100644 --- a/Package.appxmanifest +++ b/Package.appxmanifest @@ -11,7 +11,7 @@ IgnorableNamespaces="uap rescap genTemplate"> diff --git a/RyTuneX.csproj b/RyTuneX.csproj index 50b9598..fe42e89 100644 --- a/RyTuneX.csproj +++ b/RyTuneX.csproj @@ -40,6 +40,7 @@ + @@ -108,4 +109,8 @@ + + + + diff --git a/Views/DebloatSystemPage.xaml b/Views/DebloatSystemPage.xaml index 1f301ef..d47ebdf 100644 --- a/Views/DebloatSystemPage.xaml +++ b/Views/DebloatSystemPage.xaml @@ -5,7 +5,9 @@ xmlns:local="using:RyTuneX.Views" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:viewmodels="using:RyTuneX.ViewModels" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls" + xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors" + xmlns:interactivity="using:Microsoft.Xaml.Interactivity" mc:Ignorable="d"> @@ -37,5 +39,14 @@