1+ // Copyright (c) Files Community
2+ // Licensed under the MIT License.
3+
4+ using Microsoft . UI . Xaml . Controls ;
5+ using Microsoft . UI . Xaml . Media ;
6+ using Windows . Foundation . Metadata ;
7+ using Windows . Storage ;
8+ using Windows . System ;
9+
10+ namespace Files . App . Actions
11+ {
12+ internal sealed partial class OpenLogFileAction : IAction
13+ {
14+ public string Label
15+ => Strings . OpenLogFile . GetLocalizedResource ( ) ;
16+
17+ public string Description
18+ => Strings . OpenLogFileDescription . GetLocalizedResource ( ) ;
19+
20+ public HotKey HotKey
21+ => new ( Keys . OemPeriod , KeyModifiers . Ctrl ) ;
22+
23+ public async Task ExecuteAsync ( object ? parameter = null )
24+ {
25+ try
26+ {
27+ var debugFile = await ApplicationData . Current . LocalFolder . TryGetItemAsync ( "debug.log" ) as StorageFile ;
28+
29+ if ( debugFile != null && ! await Launcher . LaunchFileAsync ( debugFile ) )
30+ {
31+ // Fallback to Process.Start if Launcher fails
32+ using var process = Process . Start ( new ProcessStartInfo ( debugFile . Path )
33+ {
34+ UseShellExecute = true ,
35+ Verb = "open"
36+ } ) ;
37+ }
38+ }
39+ catch ( Exception ex )
40+ {
41+ // Only show the error dialog if no other popups are open
42+ if ( ! VisualTreeHelper . GetOpenPopupsForXamlRoot ( MainWindow . Instance . Content . XamlRoot ) . Any ( ) )
43+ {
44+ var errorDialog = new ContentDialog ( )
45+ {
46+ Title = Strings . FailedToOpenLogFile . GetLocalizedResource ( ) ,
47+ Content = ex . Message ,
48+ PrimaryButtonText = Strings . OK . GetLocalizedResource ( ) ,
49+ } ;
50+
51+ if ( ApiInformation . IsApiContractPresent ( "Windows.Foundation.UniversalApiContract" , 8 ) )
52+ errorDialog . XamlRoot = MainWindow . Instance . Content . XamlRoot ;
53+
54+ await errorDialog . TryShowAsync ( ) ;
55+ }
56+ }
57+ }
58+ }
59+ }
0 commit comments