Skip to content

Commit af20ab2

Browse files
committed
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 <[email protected]>
1 parent 10fba08 commit af20ab2

File tree

7 files changed

+49
-3
lines changed

7 files changed

+49
-3
lines changed

src/Commands/ExecuteCustomAction.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,37 @@ namespace SourceGit.Commands
88
{
99
public static class ExecuteCustomAction
1010
{
11-
public static void Run(string repo, string file, string args, Action<string> outputHandler)
11+
public static void Run(string repo, string file, string args)
12+
{
13+
var start = new ProcessStartInfo();
14+
start.FileName = file;
15+
start.Arguments = args;
16+
start.UseShellExecute = false;
17+
start.CreateNoWindow = true;
18+
start.WorkingDirectory = repo;
19+
20+
// Force using en_US.UTF-8 locale to avoid GCM crash
21+
if (OperatingSystem.IsLinux())
22+
start.Environment.Add("LANG", "en_US.UTF-8");
23+
24+
// Fix macOS `PATH` env
25+
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
26+
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
27+
28+
try
29+
{
30+
Process.Start(start);
31+
}
32+
catch (Exception e)
33+
{
34+
Dispatcher.UIThread.Invoke(() =>
35+
{
36+
App.RaiseException(repo, e.Message);
37+
});
38+
}
39+
}
40+
41+
public static void RunAndWait(string repo, string file, string args, Action<string> outputHandler)
1242
{
1343
var start = new ProcessStartInfo();
1444
start.FileName = file;

src/Models/CustomAction.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ public string Arguments
3434
set => SetProperty(ref _arguments, value);
3535
}
3636

37+
public bool WaitForExit
38+
{
39+
get => _waitForExit;
40+
set => SetProperty(ref _waitForExit, value);
41+
}
42+
3743
private string _name = string.Empty;
3844
private CustomActionScope _scope = CustomActionScope.Repository;
3945
private string _executable = string.Empty;
4046
private string _arguments = string.Empty;
47+
private bool _waitForExit = true;
4148
}
4249
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">Scope:</x:String>
159159
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">Commit</x:String>
160160
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">Repository</x:String>
161+
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">Wait for action done</x:String>
161162
<x:String x:Key="Text.Configure.Email" xml:space="preserve">Email Address</x:String>
162163
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">Email address</x:String>
163164
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">作用目标 :</x:String>
162162
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">选中的提交</x:String>
163163
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">仓库</x:String>
164+
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待操作执行完成</x:String>
164165
<x:String x:Key="Text.Configure.Email" xml:space="preserve">电子邮箱</x:String>
165166
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">邮箱地址</x:String>
166167
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT配置</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">執行範圍:</x:String>
162162
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">選取的提交</x:String>
163163
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">存放庫</x:String>
164+
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待自訂操作退出</x:String>
164165
<x:String x:Key="Text.Configure.Email" xml:space="preserve">電子郵件</x:String>
165166
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">電子郵件地址</x:String>
166167
<x:String x:Key="Text.Configure.Git" xml:space="preserve">Git 設定</x:String>

src/ViewModels/ExecuteCustomAction.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ public override Task<bool> Sure()
2828

2929
return Task.Run(() =>
3030
{
31-
Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, _args, SetProgressDescription);
31+
if (CustomAction.WaitForExit)
32+
Commands.ExecuteCustomAction.RunAndWait(_repo.FullPath, CustomAction.Executable, _args, SetProgressDescription);
33+
else
34+
Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, _args);
35+
3236
CallUIThread(() => _repo.SetWatcherEnabled(true));
3337
return true;
3438
});

src/Views/RepositoryConfigure.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Configure.CustomAction}"/>
342342
</TabItem.Header>
343343

344-
<Grid ColumnDefinitions="200,*" Height="250" Margin="0,8,0,16">
344+
<Grid ColumnDefinitions="200,*" Height="300" Margin="0,8,0,16">
345345
<Border Grid.Column="0"
346346
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
347347
Background="{DynamicResource Brush.Contents}">
@@ -439,6 +439,8 @@
439439
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CustomAction.Arguments}"/>
440440
<TextBox Margin="0,4,0,0" CornerRadius="3" Height="28" Text="{Binding Arguments, Mode=TwoWay}"/>
441441
<TextBlock Margin="0,2,0,0" TextWrapping="Wrap" Text="{DynamicResource Text.Configure.CustomAction.Arguments.Tip}" Foreground="{DynamicResource Brush.FG2}"/>
442+
443+
<CheckBox Margin="0,8,0,0" Content="{DynamicResource Text.Configure.CustomAction.WaitForExit}" IsChecked="{Binding WaitForExit, Mode=TwoWay}"/>
442444
</StackPanel>
443445
</DataTemplate>
444446
</ContentControl.DataTemplates>

0 commit comments

Comments
 (0)