Skip to content

Commit 0621790

Browse files
committed
fix: crashes when trying to close a repository with a action that is still running (#2289)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 3176bcc commit 0621790

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎src/Models/RepositoryUIStates.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,10 @@ public static RepositoryUIStates Load(string gitDir)
246246
return states;
247247
}
248248

249-
public void Unload(string lastCommitMessage)
249+
public void Unload()
250250
{
251251
try
252252
{
253-
LastCommitMessage = lastCommitMessage;
254253
using var stream = File.Create(_file);
255254
JsonSerializer.Serialize(stream, this, JsonCodeGen.Default.RepositoryUIStates);
256255
}

‎src/ViewModels/Launcher.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void CloseTab(LauncherPage page)
230230
_activeWorkspace.Repositories.Clear();
231231
_activeWorkspace.ActiveIdx = 0;
232232

233-
repo.Close();
233+
repo.Close(last.Popup is { InProgress: true });
234234

235235
Welcome.Instance.ClearSearchFilter();
236236
last.Node = new RepositoryNode() { Id = Guid.NewGuid().ToString() };
@@ -434,7 +434,7 @@ private void CloseRepositoryInTab(LauncherPage page, bool removeFromWorkspace =
434434
if (removeFromWorkspace)
435435
_activeWorkspace.Repositories.Remove(repo.FullPath);
436436

437-
repo.Close();
437+
repo.Close(page.Popup is { InProgress: true });
438438
}
439439

440440
page.Popup?.Cleanup();

‎src/ViewModels/Repository.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,13 @@ public void Open()
481481
RefreshAll();
482482
}
483483

484-
public void Close()
484+
public void Close(bool hasRunningAction)
485485
{
486486
SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect
487487
Logs.Clear();
488488

489-
_uiStates.Unload(_workingCopy.CommitMessage);
489+
_uiStates.LastCommitMessage = _workingCopy.CommitMessage;
490+
_uiStates.Unload();
490491

491492
if (_cancellationRefreshBranches is { IsCancellationRequested: false })
492493
_cancellationRefreshBranches.Cancel();
@@ -502,6 +503,9 @@ public void Close()
502503
_autoFetchTimer.Dispose();
503504
_autoFetchTimer = null;
504505

506+
if (hasRunningAction)
507+
return;
508+
505509
_settings = null;
506510
_uiStates = null;
507511
_historyFilterMode = Models.FilterMode.None;

0 commit comments

Comments
 (0)