refactor: rewrite the way to make sure scan repositories panel shows at least 0.5s (#728)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-11-21 12:14:11 +08:00
parent 8342702103
commit d3eca59036
No known key found for this signature in database

View file

@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Threading; using Avalonia.Threading;
namespace SourceGit.ViewModels namespace SourceGit.ViewModels
@ -28,8 +30,8 @@ namespace SourceGit.ViewModels
return Task.Run(() => return Task.Run(() =>
{ {
// If it is too fast, the panel will disappear very quickly, then we'll have a bad experience. var watch = new Stopwatch();
Task.Delay(500).Wait(); watch.Start();
var rootDir = new DirectoryInfo(RootDir); var rootDir = new DirectoryInfo(RootDir);
var founded = new List<string>(); var founded = new List<string>();
@ -62,6 +64,12 @@ namespace SourceGit.ViewModels
Welcome.Instance.Refresh(); 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; return true;
}); });
} }