refactor(ui): dedupe path-open helper across five view models
ListsIslandViewModel.OpenInExplorer, MergeSectionViewModel.OpenWorktree,
WorktreesOverviewModalViewModel.OpenInExplorer, AboutModalViewModel.OpenPath and
TasksIslandViewModel.OpenTaskWorktree each reimplemented "open this path in the
shell" with their own existence check, launch mechanism and error handling.
Replace all five with the new ShellOpen.Path helper and route failures through
the existing ErrorReported -> footer-strip convention instead of bare catch {}.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace ClaudeDo.Ui.Services;
|
||||
|
||||
public static class ShellOpen
|
||||
{
|
||||
// "nothing to open" (blank/missing path) is not an error — callers stay silent, matching the
|
||||
// existing Directory.Exists/File.Exists guards this helper replaces.
|
||||
public static (bool Ok, string? Error) Path(string? path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path)) return (false, null);
|
||||
if (!File.Exists(path) && !Directory.Exists(path)) return (false, null);
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo { FileName = path, UseShellExecute = true });
|
||||
return (true, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return (false, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user