Skip to content

Commit 5339ade

Browse files
committed
refactor: use async instead of Task.Run
Signed-off-by: leo <[email protected]>
1 parent 6b9ba59 commit 5339ade

File tree

6 files changed

+52
-56
lines changed

6 files changed

+52
-56
lines changed

src/ViewModels/Repository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,14 +1126,14 @@ public void StashAll(bool autoStart)
11261126
_workingCopy?.StashAll(autoStart);
11271127
}
11281128

1129-
public void SkipMerge()
1129+
public async Task SkipMergeAsync()
11301130
{
1131-
_workingCopy?.SkipMerge();
1131+
await _workingCopy?.SkipMergeAsync();
11321132
}
11331133

1134-
public void AbortMerge()
1134+
public async Task AbortMergeAsync()
11351135
{
1136-
_workingCopy?.AbortMerge();
1136+
await _workingCopy?.AbortMergeAsync();
11371137
}
11381138

11391139
public List<(Models.CustomAction, CustomActionContextMenuLabel)> GetCustomActions(Models.CustomActionScope scope)

src/ViewModels/WorkingCopy.cs

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -545,88 +545,67 @@ public void UseExternalDiffTool(Models.Change change, bool isUnstaged)
545545
new Commands.DiffTool(_repo.FullPath, toolType, toolPath, opt).Open();
546546
}
547547

548-
public void ContinueMerge()
548+
public async Task ContinueMergeAsync()
549549
{
550-
IsCommitting = true;
551-
552550
if (_inProgressContext != null)
553551
{
552+
IsCommitting = true;
554553
_repo.SetWatcherEnabled(false);
555-
Task.Run(async () =>
556-
{
557-
var mergeMsgFile = Path.Combine(_repo.GitDir, "MERGE_MSG");
558-
if (File.Exists(mergeMsgFile) && !string.IsNullOrWhiteSpace(_commitMessage))
559-
await File.WriteAllTextAsync(mergeMsgFile, _commitMessage);
560554

561-
var succ = await _inProgressContext.ContinueAsync();
562-
await Dispatcher.UIThread.InvokeAsync(() =>
563-
{
564-
if (succ)
565-
CommitMessage = string.Empty;
555+
var mergeMsgFile = Path.Combine(_repo.GitDir, "MERGE_MSG");
556+
if (File.Exists(mergeMsgFile) && !string.IsNullOrWhiteSpace(_commitMessage))
557+
await File.WriteAllTextAsync(mergeMsgFile, _commitMessage);
566558

567-
_repo.SetWatcherEnabled(true);
568-
IsCommitting = false;
569-
});
570-
});
559+
var succ = await _inProgressContext.ContinueAsync();
560+
if (succ)
561+
CommitMessage = string.Empty;
562+
563+
_repo.SetWatcherEnabled(true);
564+
IsCommitting = false;
571565
}
572566
else
573567
{
574568
_repo.MarkWorkingCopyDirtyManually();
575-
IsCommitting = false;
576569
}
577570
}
578571

579-
public void SkipMerge()
572+
public async Task SkipMergeAsync()
580573
{
581-
IsCommitting = true;
582-
583574
if (_inProgressContext != null)
584575
{
576+
IsCommitting = true;
585577
_repo.SetWatcherEnabled(false);
586-
Task.Run(async () =>
587-
{
588-
var succ = await _inProgressContext.SkipAsync();
589-
await Dispatcher.UIThread.InvokeAsync(() =>
590-
{
591-
if (succ)
592-
CommitMessage = string.Empty;
593578

594-
_repo.SetWatcherEnabled(true);
595-
IsCommitting = false;
596-
});
597-
});
579+
var succ = await _inProgressContext.SkipAsync();
580+
if (succ)
581+
CommitMessage = string.Empty;
582+
583+
_repo.SetWatcherEnabled(true);
584+
IsCommitting = false;
598585
}
599586
else
600587
{
601588
_repo.MarkWorkingCopyDirtyManually();
602-
IsCommitting = false;
603589
}
604590
}
605591

606-
public void AbortMerge()
592+
public async Task AbortMergeAsync()
607593
{
608-
IsCommitting = true;
609-
610594
if (_inProgressContext != null)
611595
{
596+
IsCommitting = true;
612597
_repo.SetWatcherEnabled(false);
613-
Task.Run(async () =>
614-
{
615-
var succ = await _inProgressContext.AbortAsync();
616-
await Dispatcher.UIThread.InvokeAsync(() =>
617-
{
618-
if (succ)
619-
CommitMessage = string.Empty;
620598

621-
_repo.SetWatcherEnabled(true);
622-
IsCommitting = false;
623-
});
624-
});
599+
var succ = await _inProgressContext.AbortAsync();
600+
if (succ)
601+
CommitMessage = string.Empty;
602+
603+
_repo.SetWatcherEnabled(true);
604+
IsCommitting = false;
625605
}
626606
else
627607
{
628608
_repo.MarkWorkingCopyDirtyManually();
629-
IsCommitting = false;
630609
}
631610
}
632611

src/Views/Repository.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@
685685
BorderThickness="0"
686686
Content="{DynamicResource Text.Repository.Abort}"
687687
Padding="8,2" Margin="0,0,8,0"
688-
Command="{Binding AbortMerge}"/>
688+
Click="OnAbortInProgress"/>
689689
</Grid>
690690

691691
<Grid Grid.Row="1"

src/Views/Repository.axaml.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,18 @@ private void OnOpenSortTagMenu(object sender, RoutedEventArgs e)
643643
e.Handled = true;
644644
}
645645

646-
private void OnSkipInProgress(object sender, RoutedEventArgs e)
646+
private async void OnSkipInProgress(object sender, RoutedEventArgs e)
647647
{
648648
if (DataContext is ViewModels.Repository repo)
649-
repo.SkipMerge();
649+
await repo.SkipMergeAsync();
650+
651+
e.Handled = true;
652+
}
653+
654+
private async void OnAbortInProgress(object sender, RoutedEventArgs e)
655+
{
656+
if (DataContext is ViewModels.Repository repo)
657+
await repo.AbortMergeAsync();
650658

651659
e.Handled = true;
652660
}

src/Views/WorkingCopy.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
Height="28"
285285
Margin="8,0,0,0"
286286
Padding="8,0"
287-
Command="{Binding ContinueMerge}"
287+
Click="OnContinue"
288288
IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}">
289289
<SplitButton.IsEnabled>
290290
<MultiBinding Converter="{x:Static BoolConverters.And}">

src/Views/WorkingCopy.axaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ private async void OnOpenExternalMergeToolAllConflicts(object _, RoutedEventArgs
181181
{
182182
if (DataContext is ViewModels.WorkingCopy vm)
183183
await vm.UseExternalMergeToolAsync(null);
184+
185+
e.Handled = true;
186+
}
187+
188+
private async void OnContinue(object _, RoutedEventArgs e)
189+
{
190+
if (DataContext is ViewModels.WorkingCopy vm)
191+
await vm.ContinueMergeAsync();
192+
184193
e.Handled = true;
185194
}
186195

0 commit comments

Comments
 (0)