From af20ab2448a2b46dfd687c0ff95a12716d2f9543 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 11 Feb 2025 14:34:14 +0800 Subject: [PATCH] feature: add `Wait for action done` option to control whether or not to wait for the custom action execution to complete (#951) Signed-off-by: leo --- src/Commands/ExecuteCustomAction.cs | 32 ++++++++++++++++++++++++++- src/Models/CustomAction.cs | 7 ++++++ src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/Resources/Locales/zh_TW.axaml | 1 + src/ViewModels/ExecuteCustomAction.cs | 6 ++++- src/Views/RepositoryConfigure.axaml | 4 +++- 7 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/Commands/ExecuteCustomAction.cs b/src/Commands/ExecuteCustomAction.cs index a10f5387..3a77ec01 100644 --- a/src/Commands/ExecuteCustomAction.cs +++ b/src/Commands/ExecuteCustomAction.cs @@ -8,7 +8,37 @@ namespace SourceGit.Commands { public static class ExecuteCustomAction { - public static void Run(string repo, string file, string args, Action outputHandler) + public static void Run(string repo, string file, string args) + { + var start = new ProcessStartInfo(); + start.FileName = file; + start.Arguments = args; + start.UseShellExecute = false; + start.CreateNoWindow = true; + start.WorkingDirectory = repo; + + // Force using en_US.UTF-8 locale to avoid GCM crash + if (OperatingSystem.IsLinux()) + start.Environment.Add("LANG", "en_US.UTF-8"); + + // Fix macOS `PATH` env + if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv)) + start.Environment.Add("PATH", Native.OS.CustomPathEnv); + + try + { + Process.Start(start); + } + catch (Exception e) + { + Dispatcher.UIThread.Invoke(() => + { + App.RaiseException(repo, e.Message); + }); + } + } + + public static void RunAndWait(string repo, string file, string args, Action outputHandler) { var start = new ProcessStartInfo(); start.FileName = file; diff --git a/src/Models/CustomAction.cs b/src/Models/CustomAction.cs index 8452a42d..bd56d6ae 100644 --- a/src/Models/CustomAction.cs +++ b/src/Models/CustomAction.cs @@ -34,9 +34,16 @@ namespace SourceGit.Models set => SetProperty(ref _arguments, value); } + public bool WaitForExit + { + get => _waitForExit; + set => SetProperty(ref _waitForExit, value); + } + private string _name = string.Empty; private CustomActionScope _scope = CustomActionScope.Repository; private string _executable = string.Empty; private string _arguments = string.Empty; + private bool _waitForExit = true; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 018b54d7..40f95793 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -158,6 +158,7 @@ Scope: Commit Repository + Wait for action done Email Address Email address GIT diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 66d1f37e..ef31972a 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -161,6 +161,7 @@ 作用目标 : 选中的提交 仓库 + 等待操作执行完成 电子邮箱 邮箱地址 GIT配置 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index f8255947..506a618f 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -161,6 +161,7 @@ 執行範圍: 選取的提交 存放庫 + 等待自訂操作退出 電子郵件 電子郵件地址 Git 設定 diff --git a/src/ViewModels/ExecuteCustomAction.cs b/src/ViewModels/ExecuteCustomAction.cs index 920b9f43..848faaaf 100644 --- a/src/ViewModels/ExecuteCustomAction.cs +++ b/src/ViewModels/ExecuteCustomAction.cs @@ -28,7 +28,11 @@ namespace SourceGit.ViewModels return Task.Run(() => { - Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, _args, SetProgressDescription); + if (CustomAction.WaitForExit) + Commands.ExecuteCustomAction.RunAndWait(_repo.FullPath, CustomAction.Executable, _args, SetProgressDescription); + else + Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, _args); + CallUIThread(() => _repo.SetWatcherEnabled(true)); return true; }); diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml index 5e9374f9..d9383743 100644 --- a/src/Views/RepositoryConfigure.axaml +++ b/src/Views/RepositoryConfigure.axaml @@ -341,7 +341,7 @@ - + @@ -439,6 +439,8 @@ + +