Skip to content

Commit 6f86916

Browse files
committed
Added error dialog
1 parent 3d590bb commit 6f86916

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/Files.App/Actions/Open/OpenSettingsFileAction.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
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;
47
using Windows.Storage;
58
using Windows.System;
69

710
namespace 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+
}

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,6 +3697,9 @@
36973697
<data name="FailedToSetBackground" xml:space="preserve">
36983698
<value>Failed to set the background wallpaper</value>
36993699
</data>
3700+
<data name="FailedToOpenSettingsFile" xml:space="preserve">
3701+
<value>Failed to open the settings file</value>
3702+
</data>
37003703
<data name="GitDeleteBranch" xml:space="preserve">
37013704
<value>Delete Git branch</value>
37023705
</data>

0 commit comments

Comments
 (0)