mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 12:11:13 +00:00
perf: Optimized the startup time of the tool.
This commit is contained in:
parent
6e2848a9de
commit
b240564cf7
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user