mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 13:42:24 +00:00
Improve reload function
This commit is contained in:
parent
780ccb1932
commit
5ae58e6a98
2 changed files with 21 additions and 28 deletions
|
@ -67,13 +67,17 @@ namespace ServiceLib.Handler
|
|||
return;
|
||||
}
|
||||
|
||||
UpdateFunc(true, $"{node.GetSummary()}");
|
||||
UpdateFunc(false, $"{node.GetSummary()}");
|
||||
UpdateFunc(false, $"{Utils.GetRuntimeInfo()}");
|
||||
UpdateFunc(false, string.Format(ResUI.StartService, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
|
||||
await CoreStop();
|
||||
await Task.Delay(100);
|
||||
await CoreStart(node);
|
||||
await CoreStartPreService(node);
|
||||
if (_process != null)
|
||||
{
|
||||
UpdateFunc(true, $"{node.GetSummary()}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> LoadCoreConfigSpeedtest(List<ServerTestItem> selecteds)
|
||||
|
@ -220,8 +224,6 @@ namespace ServiceLib.Handler
|
|||
await RunProcessAsLinuxSudo(proc, fileName, coreInfo, configPath);
|
||||
}
|
||||
|
||||
var startUpErrorMessage = new StringBuilder();
|
||||
var startUpSuccessful = false;
|
||||
if (displayLog)
|
||||
{
|
||||
proc.OutputDataReceived += (sender, e) =>
|
||||
|
@ -233,11 +235,6 @@ namespace ServiceLib.Handler
|
|||
{
|
||||
if (Utils.IsNullOrEmpty(e.Data)) return;
|
||||
UpdateFunc(false, e.Data + Environment.NewLine);
|
||||
|
||||
if (!startUpSuccessful)
|
||||
{
|
||||
startUpErrorMessage.Append(e.Data + Environment.NewLine);
|
||||
}
|
||||
};
|
||||
}
|
||||
proc.Start();
|
||||
|
@ -258,18 +255,12 @@ namespace ServiceLib.Handler
|
|||
proc.BeginErrorReadLine();
|
||||
}
|
||||
|
||||
await Task.Delay(500);
|
||||
AppHandler.Instance.AddProcess(proc.Handle);
|
||||
if (proc.WaitForExit(1000))
|
||||
if (proc is null or { HasExited: true })
|
||||
{
|
||||
proc.CancelErrorRead();
|
||||
throw new Exception(displayLog ? startUpErrorMessage.ToString() : "启动进程失败并退出 (Failed to start the process and exited)");
|
||||
throw new Exception(ResUI.FailedToRunCore);
|
||||
}
|
||||
else
|
||||
{
|
||||
startUpSuccessful = true;
|
||||
}
|
||||
|
||||
AppHandler.Instance.AddProcess(proc.Handle);
|
||||
return proc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -222,6 +222,7 @@ namespace ServiceLib.ViewModels
|
|||
await StatisticsHandler.Instance.Init(_config, UpdateStatisticsHandler);
|
||||
}
|
||||
|
||||
BlReloadEnabled = true;
|
||||
await Reload();
|
||||
await AutoHideStartup();
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
|
@ -533,8 +534,17 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
#region core job
|
||||
|
||||
public async Task Reload()
|
||||
public async Task Reload(int times = 0)
|
||||
{
|
||||
//If there are unfinished reload job, wait a few seconds and exec again.
|
||||
if (!BlReloadEnabled)
|
||||
{
|
||||
await Task.Delay(3000);
|
||||
if (times > 3) return;
|
||||
await Reload(++times);
|
||||
return;
|
||||
}
|
||||
|
||||
BlReloadEnabled = false;
|
||||
|
||||
await LoadCore();
|
||||
|
@ -557,17 +567,9 @@ namespace ServiceLib.ViewModels
|
|||
}
|
||||
|
||||
private async Task LoadCore()
|
||||
{
|
||||
//if (_config.tunModeItem.enableTun)
|
||||
//{
|
||||
// Task.Delay(1000).Wait();
|
||||
// WindowsUtils.RemoveTunDevice();
|
||||
//}
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var node = await ConfigHandler.GetDefaultServer(_config);
|
||||
await CoreHandler.Instance.LoadCore(node);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task CloseCore()
|
||||
|
|
Loading…
Reference in a new issue