Skip to content

Commit 1188949

Browse files
authored
fix: Custom Shell/Terminal or Diff/Merge Tool crash fix (#1484)
* fix(1483): FilePickerOpenOptions Fix * fix(1483): Missing Try Cath Block
1 parent db5efbd commit 1188949

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

src/Views/Preferences.axaml.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,28 @@ private async void SelectShellOrTerminal(object _, RoutedEventArgs e)
293293
return;
294294

295295
var shell = Models.ShellOrTerminal.Supported[type];
296-
var options = new FilePickerOpenOptions()
296+
297+
var options = new FilePickerOpenOptions() { AllowMultiple = false };
298+
if (shell.Name != "Custom")
297299
{
298-
FileTypeFilter = [new FilePickerFileType(shell.Name) { Patterns = [shell.Exec] }],
299-
AllowMultiple = false,
300-
};
300+
options = new FilePickerOpenOptions()
301+
{
302+
FileTypeFilter = [new FilePickerFileType(shell.Name) { Patterns = [shell.Exec] }],
303+
AllowMultiple = false,
304+
};
305+
}
301306

302-
var selected = await StorageProvider.OpenFilePickerAsync(options);
303-
if (selected.Count == 1)
307+
IReadOnlyList<IStorageFile> selected = null;
308+
try
309+
{
310+
selected = await StorageProvider.OpenFilePickerAsync(options);
311+
}
312+
catch (Exception ex)
313+
{
314+
App.RaiseException(string.Empty, $"Failed to select shell/terminal: {ex.Message}");
315+
}
316+
317+
if (selected is { Count: 1 })
304318
{
305319
ViewModels.Preferences.Instance.ShellOrTerminalPath = selected[0].Path.LocalPath;
306320
}
@@ -319,14 +333,27 @@ private async void SelectExternalMergeTool(object _, RoutedEventArgs e)
319333
}
320334

321335
var tool = Models.ExternalMerger.Supported[type];
322-
var options = new FilePickerOpenOptions()
336+
var options = new FilePickerOpenOptions() { AllowMultiple = false };
337+
if (tool.Name != "Custom")
323338
{
324-
FileTypeFilter = [new FilePickerFileType(tool.Name) { Patterns = tool.GetPatterns() }],
325-
AllowMultiple = false,
326-
};
339+
options = new FilePickerOpenOptions()
340+
{
341+
FileTypeFilter = [new FilePickerFileType(tool.Name) { Patterns = tool.GetPatterns() }],
342+
AllowMultiple = false,
343+
};
344+
}
327345

328-
var selected = await StorageProvider.OpenFilePickerAsync(options);
329-
if (selected.Count == 1)
346+
IReadOnlyList<IStorageFile> selected = null;
347+
try
348+
{
349+
selected = await StorageProvider.OpenFilePickerAsync(options);
350+
}
351+
catch (Exception ex)
352+
{
353+
App.RaiseException(string.Empty, $"Failed to select merge tool: {ex.Message}");
354+
}
355+
356+
if (selected is { Count: 1 })
330357
{
331358
ViewModels.Preferences.Instance.ExternalMergeToolPath = selected[0].Path.LocalPath;
332359
}

0 commit comments

Comments
 (0)