11// Copyright (c) Files Community
22// Licensed under the MIT License.
33
4+ using Microsoft . UI . Xaml . Controls ;
5+ using Microsoft . UI . Xaml . Media ;
6+ using Windows . Foundation . Metadata ;
47using Windows . Storage ;
58using Windows . System ;
69
710namespace Files . App . Actions
811{
9- internal sealed partial class OpenSettingsFileAction : IAction
12+ internal sealed partial class OpenSettingsFileAction : IAction
1013 {
1114 public string Label
1215 => Strings . EditSettingsFile . GetLocalizedResource ( ) ;
@@ -22,12 +25,30 @@ public RichGlyph Glyph
2225
2326 public async Task ExecuteAsync ( object ? parameter = null )
2427 {
25- await SafetyExtensions . IgnoreExceptions ( async ( ) =>
28+ try
2629 {
2730 var settingsJsonFile = await StorageFile . GetFileFromApplicationUriAsync ( new Uri ( $ "ms-appdata:///local/{ Constants . LocalSettings . SettingsFolderName } /{ Constants . LocalSettings . UserSettingsFileName } ") ) ;
2831 if ( ! await Launcher . LaunchFileAsync ( settingsJsonFile ) )
2932 await ContextMenu . InvokeVerb ( "open" , settingsJsonFile . Path ) ;
30- } ) ;
33+ }
34+ catch ( Exception ex )
35+ {
36+ // Only show the error dialog if no other popups are open
37+ if ( ! VisualTreeHelper . GetOpenPopupsForXamlRoot ( MainWindow . Instance . Content . XamlRoot ) . Any ( ) )
38+ {
39+ var errorDialog = new ContentDialog ( )
40+ {
41+ Title = Strings . FailedToOpenSettingsFile . GetLocalizedResource ( ) ,
42+ Content = ex . Message ,
43+ PrimaryButtonText = Strings . OK . GetLocalizedResource ( ) ,
44+ } ;
45+
46+ if ( ApiInformation . IsApiContractPresent ( "Windows.Foundation.UniversalApiContract" , 8 ) )
47+ errorDialog . XamlRoot = MainWindow . Instance . Content . XamlRoot ;
48+
49+ await errorDialog . TryShowAsync ( ) ;
50+ }
51+ }
3152 }
3253 }
33- }
54+ }
0 commit comments