From d3eca59036b118e22d0b8fabc7fffcaa235497ab Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 21 Nov 2024 12:14:11 +0800 Subject: [PATCH] refactor: rewrite the way to make sure scan repositories panel shows at least 0.5s (#728) Signed-off-by: leo --- src/ViewModels/ScanRepositories.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/ScanRepositories.cs b/src/ViewModels/ScanRepositories.cs index 115edf2d..7b52c670 100644 --- a/src/ViewModels/ScanRepositories.cs +++ b/src/ViewModels/ScanRepositories.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Threading.Tasks; + using Avalonia.Threading; namespace SourceGit.ViewModels @@ -28,8 +30,8 @@ namespace SourceGit.ViewModels return Task.Run(() => { - // If it is too fast, the panel will disappear very quickly, then we'll have a bad experience. - Task.Delay(500).Wait(); + var watch = new Stopwatch(); + watch.Start(); var rootDir = new DirectoryInfo(RootDir); var founded = new List(); @@ -62,6 +64,12 @@ namespace SourceGit.ViewModels Welcome.Instance.Refresh(); }); + // Make sure this task takes at least 0.5s to avoid that the popup panel do not disappear very quickly. + var remain = 500 - (int)watch.Elapsed.TotalMilliseconds; + watch.Stop(); + if (remain > 0) + Task.Delay(remain).Wait(); + return true; }); }