From 118894907ebc9de439d26b2ce11a0a6d807a4610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enner=20P=C3=A9rez?= Date: Tue, 1 Jul 2025 21:25:38 -0500 Subject: [PATCH] fix: Custom Shell/Terminal or Diff/Merge Tool crash fix (#1484) * fix(1483): FilePickerOpenOptions Fix * fix(1483): Missing Try Cath Block --- src/Views/Preferences.axaml.cs | 53 +++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/Views/Preferences.axaml.cs b/src/Views/Preferences.axaml.cs index f0f4617a..adf3e703 100644 --- a/src/Views/Preferences.axaml.cs +++ b/src/Views/Preferences.axaml.cs @@ -293,14 +293,28 @@ namespace SourceGit.Views return; var shell = Models.ShellOrTerminal.Supported[type]; - var options = new FilePickerOpenOptions() - { - FileTypeFilter = [new FilePickerFileType(shell.Name) { Patterns = [shell.Exec] }], - AllowMultiple = false, - }; - var selected = await StorageProvider.OpenFilePickerAsync(options); - if (selected.Count == 1) + var options = new FilePickerOpenOptions() { AllowMultiple = false }; + if (shell.Name != "Custom") + { + options = new FilePickerOpenOptions() + { + FileTypeFilter = [new FilePickerFileType(shell.Name) { Patterns = [shell.Exec] }], + AllowMultiple = false, + }; + } + + IReadOnlyList selected = null; + try + { + selected = await StorageProvider.OpenFilePickerAsync(options); + } + catch (Exception ex) + { + App.RaiseException(string.Empty, $"Failed to select shell/terminal: {ex.Message}"); + } + + if (selected is { Count: 1 }) { ViewModels.Preferences.Instance.ShellOrTerminalPath = selected[0].Path.LocalPath; } @@ -319,14 +333,27 @@ namespace SourceGit.Views } var tool = Models.ExternalMerger.Supported[type]; - var options = new FilePickerOpenOptions() + var options = new FilePickerOpenOptions() { AllowMultiple = false }; + if (tool.Name != "Custom") { - FileTypeFilter = [new FilePickerFileType(tool.Name) { Patterns = tool.GetPatterns() }], - AllowMultiple = false, - }; + options = new FilePickerOpenOptions() + { + FileTypeFilter = [new FilePickerFileType(tool.Name) { Patterns = tool.GetPatterns() }], + AllowMultiple = false, + }; + } - var selected = await StorageProvider.OpenFilePickerAsync(options); - if (selected.Count == 1) + IReadOnlyList selected = null; + try + { + selected = await StorageProvider.OpenFilePickerAsync(options); + } + catch (Exception ex) + { + App.RaiseException(string.Empty, $"Failed to select merge tool: {ex.Message}"); + } + + if (selected is { Count: 1 }) { ViewModels.Preferences.Instance.ExternalMergeToolPath = selected[0].Path.LocalPath; }