mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-25 06:34:59 +03:00
Add periodic update checks and core support
This commit is contained in:
@@ -50,6 +50,50 @@ public sealed class CoreInfoManager
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public List<ECoreType> GetCheckUpdateCoreTypes()
|
||||
{
|
||||
var lst = new List<ECoreType>();
|
||||
|
||||
if (RuntimeInformation.ProcessArchitecture != Architecture.X86)
|
||||
{
|
||||
if (IsCheckUpdateSupported(ECoreType.v2rayN))
|
||||
{
|
||||
lst.Add(ECoreType.v2rayN);
|
||||
}
|
||||
|
||||
if (!(Utils.IsWindows() && Environment.OSVersion.Version.Major < 10))
|
||||
{
|
||||
lst.Add(ECoreType.Xray);
|
||||
lst.Add(ECoreType.mihomo);
|
||||
lst.Add(ECoreType.sing_box);
|
||||
}
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
public bool IsCheckUpdateSupported(ECoreType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
ECoreType.v2rayN => !Utils.IsPackagedInstall(),
|
||||
ECoreType.Xray => true,
|
||||
ECoreType.mihomo => true,
|
||||
ECoreType.sing_box => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
public bool GetCheckPreRelease(ECoreType type, bool preRelease)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
ECoreType.v2rayN => preRelease,
|
||||
ECoreType.Xray => preRelease,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
private void InitCoreInfo()
|
||||
{
|
||||
var urlN = GetCoreUrl(ECoreType.v2rayN);
|
||||
|
||||
@@ -70,6 +70,18 @@ public class TaskManager
|
||||
}
|
||||
}
|
||||
|
||||
//Execute once 24 hour
|
||||
if (numOfExecuted % 1440 == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UpdateTaskRunCheckUpdate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog("ScheduledTasks - UpdateTaskRunCheckUpdate", ex);
|
||||
}
|
||||
}
|
||||
numOfExecuted++;
|
||||
}
|
||||
}
|
||||
@@ -117,4 +129,18 @@ public class TaskManager
|
||||
}).UpdateGeoFileAll();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateTaskRunCheckUpdate()
|
||||
{
|
||||
Logging.SaveLog("Execute check update");
|
||||
|
||||
var updateService = new UpdateService(_config, async (success, msg) => await Task.CompletedTask);
|
||||
|
||||
var msgs = await updateService.CheckHasUpdateOnlyAll(_config.CheckUpdateItem.CheckPreReleaseUpdate);
|
||||
foreach (var msg in msgs)
|
||||
{
|
||||
await _updateFunc?.Invoke(false, msg);
|
||||
}
|
||||
NoticeManager.Instance.Enqueue(string.Join("\n", msgs));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user