InternalPage.xaml.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using ManagedCommon; 6 using Microsoft.CommandPalette.Extensions.Toolkit; 7 using Microsoft.UI.Xaml; 8 using Windows.System; 9 using Page = Microsoft.UI.Xaml.Controls.Page; 10 11 namespace Microsoft.CmdPal.UI.Settings; 12 13 /// <summary> 14 /// An empty page that can be used on its own or navigated to within a Frame. 15 /// </summary> 16 public sealed partial class InternalPage : Page 17 { 18 public InternalPage() 19 { 20 InitializeComponent(); 21 } 22 23 private void ThrowPlainMainThreadException_Click(object sender, RoutedEventArgs e) 24 { 25 Logger.LogDebug("Throwing test exception from the UI thread"); 26 throw new NotImplementedException("Test exception; thrown from the UI thread"); 27 } 28 29 private void ThrowExceptionInUnobservedTask_Click(object sender, RoutedEventArgs e) 30 { 31 Logger.LogDebug("Starting a task that will throw test exception"); 32 Task.Run(() => 33 { 34 Logger.LogDebug("Throwing test exception from a task"); 35 throw new InvalidOperationException("Test exception; thrown from a task"); 36 }); 37 } 38 39 private void ThrowPlainMainThreadExceptionPii_Click(object sender, RoutedEventArgs e) 40 { 41 Logger.LogDebug("Throwing test exception from the UI thread (PII)"); 42 throw new InvalidOperationException(SampleData.ExceptionMessageWithPii); 43 } 44 45 private async void OpenLogsCardClicked(object sender, RoutedEventArgs e) 46 { 47 try 48 { 49 var logFolderPath = Logger.CurrentVersionLogDirectoryPath; 50 if (Directory.Exists(logFolderPath)) 51 { 52 await Launcher.LaunchFolderPathAsync(logFolderPath); 53 } 54 } 55 catch (Exception ex) 56 { 57 Logger.LogError("Failed to open directory in Explorer", ex); 58 } 59 } 60 61 private async void OpenCurrentLogCardClicked(object sender, RoutedEventArgs e) 62 { 63 try 64 { 65 var logPath = Logger.CurrentLogFile; 66 if (File.Exists(logPath)) 67 { 68 await Launcher.LaunchUriAsync(new Uri(logPath)); 69 } 70 } 71 catch (Exception ex) 72 { 73 Logger.LogError("Failed to open log file", ex); 74 } 75 } 76 77 private async void OpenConfigFolderCardClick(object sender, RoutedEventArgs e) 78 { 79 try 80 { 81 var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal"); 82 if (Directory.Exists(directory)) 83 { 84 await Launcher.LaunchFolderPathAsync(directory); 85 } 86 } 87 catch (Exception ex) 88 { 89 Logger.LogError("Failed to open directory in Explorer", ex); 90 } 91 } 92 }