perf: Optimized the startup time of the tool.

This commit is contained in:
real-zony 2023-05-25 09:05:39 +08:00
parent 6e2848a9de
commit b240564cf7

View File

@ -23,6 +23,11 @@ public class DefaultUpdater : IUpdater, ISingletonDependency
public async Task CheckUpdateAsync()
{
if (!IsCheckUpdate())
{
return;
}
var response = await _warpHttpClient.GetAsync<NewVersionResponse?>(UpdateUrl);
if (response == null)
{
@ -56,4 +61,27 @@ public class DefaultUpdater : IUpdater, ISingletonDependency
}
}
}
private bool IsCheckUpdate()
{
var lockFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "update.lock");
if (!File.Exists(lockFile))
{
File.WriteAllText(lockFile, DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
return true;
}
if (long.TryParse(File.ReadAllText(lockFile), out var time))
{
var now = DateTimeOffset.Now.ToUnixTimeSeconds();
if (now - time <= 86400 /* 1 Day */)
{
return false;
}
}
File.WriteAllText(lockFile, DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
return true;
}
}