Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d0a32eb

Browse files
feature: makes Clone popup cancellable (#1012)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 328592f commit d0a32eb

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

‎src/Commands/Command.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public bool Exec()
7575
{
7676
CancellationToken.Register(() =>
7777
{
78-
if (_proc !=null&&!_isDone)
78+
if (_proc is{HasExited:false})
7979
Native.OS.TerminateSafely(_proc);
8080
});
8181
}
@@ -92,7 +92,6 @@ public bool Exec()
9292
return false;
9393
}
9494

95-
_isDone = false;
9695
_proc = proc;
9796

9897
int exitCode;
@@ -102,7 +101,6 @@ public bool Exec()
102101
proc.BeginErrorReadLine();
103102
proc.WaitForExit();
104103

105-
_isDone = true;
106104
exitCode = proc.ExitCode;
107105
proc.Close();
108106
}
@@ -111,7 +109,10 @@ public bool Exec()
111109
_proc = null;
112110
}
113111

114-
if (!CancellationToken.IsCancellationRequested && exitCode != 0)
112+
if (CancellationToken.IsCancellationRequested)
113+
return false;
114+
115+
if (exitCode != 0)
115116
{
116117
if (RaiseError)
117118
{
@@ -223,6 +224,5 @@ private ProcessStartInfo CreateGitStartInfo()
223224
private static partial Regex REG_PROGRESS();
224225

225226
private Process _proc = null;
226-
private bool _isDone = false;
227227
}
228228
}

‎src/ViewModels/Clone.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public bool InitAndUpdateSubmodules
6262
public Clone(string pageId)
6363
{
6464
_pageId = pageId;
65+
66+
CanCancelInProgress = true;
6567
View = new Views.Clone() { DataContext = this };
6668

6769
Task.Run(async () =>
@@ -102,6 +104,7 @@ public override Task<bool> Sure()
102104
return Task.Run(() =>
103105
{
104106
var cmd = new Commands.Clone(_pageId, _parentFolder, _remote, _local, _useSSH ? _sshKey : "", _extraArgs, SetProgressDescription);
107+
cmd.CancellationToken = CancelInProgressTokenSource.Token;
105108
if (!cmd.Exec())
106109
return false;
107110

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /