Optimizing reload core

pull/3380/head
2dust 2023-02-28 20:23:15 +08:00
parent eeab8e4a90
commit 1f7eb2d48a
4 changed files with 39 additions and 55 deletions

View File

@ -124,7 +124,6 @@
#region global variable #region global variable
public static bool reloadCore { get; set; }
public static int statePort { get; set; } public static int statePort { get; set; }
public static Job processJob { get; set; } public static Job processJob { get; set; }
public static bool ShowInTaskbar { get; set; } public static bool ShowInTaskbar { get; set; }

View File

@ -195,16 +195,6 @@ namespace v2rayN.Handler
config.guiItem.statisticsFreshRate = 1; config.guiItem.statisticsFreshRate = 1;
} }
if (config == null)
{
Global.reloadCore = false;
}
else
{
Global.reloadCore = true;
}
LazyConfig.Instance.SetConfig(config); LazyConfig.Instance.SetConfig(config);
return 0; return 0;
} }
@ -215,7 +205,6 @@ namespace v2rayN.Handler
/// <returns></returns> /// <returns></returns>
public static int SaveConfig(ref Config config, bool reload = true) public static int SaveConfig(ref Config config, bool reload = true)
{ {
Global.reloadCore = reload;
ToJsonFile(config); ToJsonFile(config);
@ -446,7 +435,6 @@ namespace v2rayN.Handler
} }
config.indexId = indexId; config.indexId = indexId;
Global.reloadCore = true;
ToJsonFile(config); ToJsonFile(config);
@ -856,7 +844,6 @@ namespace v2rayN.Handler
} }
else if (profileItem.indexId == config.indexId) else if (profileItem.indexId == config.indexId)
{ {
Global.reloadCore = true;
} }
if (SqliteHelper.Instance.Replace(profileItem) > 0) if (SqliteHelper.Instance.Replace(profileItem) > 0)
@ -1461,8 +1448,6 @@ namespace v2rayN.Handler
config.routingBasicItem.routingIndexId = routingItem.id; config.routingBasicItem.routingIndexId = routingItem.id;
} }
Global.reloadCore = true;
ToJsonFile(config); ToJsonFile(config);
return 0; return 0;

View File

@ -27,46 +27,43 @@ namespace v2rayN.Handler
public void LoadCore(Config config) public void LoadCore(Config config)
{ {
if (Global.reloadCore) var node = ConfigHandler.GetDefaultServer(ref config);
if (node == null)
{ {
var node = ConfigHandler.GetDefaultServer(ref config); ShowMsg(false, ResUI.CheckServerSettings);
if (node == null) return;
{ }
ShowMsg(false, ResUI.CheckServerSettings);
return;
}
if (SetCore(config, node) != 0) if (SetCore(config, node) != 0)
{ {
ShowMsg(false, ResUI.CheckServerSettings); ShowMsg(false, ResUI.CheckServerSettings);
return; return;
} }
string fileName = Utils.GetConfigPath(_coreCConfigRes); string fileName = Utils.GetConfigPath(_coreCConfigRes);
if (CoreConfigHandler.GenerateClientConfig(node, fileName, out string msg, out string content) != 0) if (CoreConfigHandler.GenerateClientConfig(node, fileName, out string msg, out string content) != 0)
{ {
ShowMsg(false, msg); ShowMsg(false, msg);
} }
else else
{ {
ShowMsg(false, msg); ShowMsg(false, msg);
ShowMsg(true, $"{node.GetSummary()}"); ShowMsg(true, $"{node.GetSummary()}");
CoreStop(); CoreStop();
CoreStart(node); CoreStart(node);
} }
//start a socks service //start a socks service
if (_process != null && !_process.HasExited && node.configType == EConfigType.Custom && node.preSocksPort > 0) if (_process != null && !_process.HasExited && node.configType == EConfigType.Custom && node.preSocksPort > 0)
{
var itemSocks = new ProfileItem()
{ {
var itemSocks = new ProfileItem() configType = EConfigType.Socks,
{ address = Global.Loopback,
configType = EConfigType.Socks, port = node.preSocksPort
address = Global.Loopback, };
port = node.preSocksPort if (CoreConfigHandler.GenerateClientConfig(itemSocks, null, out string msg2, out string configStr) == 0)
}; {
if (CoreConfigHandler.GenerateClientConfig(itemSocks, null, out string msg2, out string configStr) == 0) _processId = CoreStartViaString(configStr);
{
_processId = CoreStartViaString(configStr);
}
} }
} }
} }

View File

@ -540,8 +540,12 @@ namespace v2rayN.ViewModels
_noticeHandler?.SendMessage(msg); _noticeHandler?.SendMessage(msg);
if (success) if (success)
{ {
var indexIdOld = _config.indexId;
RefreshServers(); RefreshServers();
Reload(); if (indexIdOld != _config.indexId)
{
Reload();
}
if (_config.uiItem.enableAutoAdjustMainLvColWidth) if (_config.uiItem.enableAutoAdjustMainLvColWidth)
{ {
_updateView("AdjustMainLvColWidth"); _updateView("AdjustMainLvColWidth");
@ -740,6 +744,7 @@ namespace v2rayN.ViewModels
subRemarks = t.subRemarks, subRemarks = t.subRemarks,
isActive = t.indexId == _config.indexId, isActive = t.indexId == _config.indexId,
sort = t33 == null ? 0 : t33.sort, sort = t33 == null ? 0 : t33.sort,
delay = t33 == null ? 0 : t33.delay,
delayVal = t33?.delay != 0 ? $"{t33?.delay} {Global.DelayUnit}" : string.Empty, delayVal = t33?.delay != 0 ? $"{t33?.delay} {Global.DelayUnit}" : string.Empty,
speedVal = t33?.speed != 0 ? $"{t33?.speed} {Global.SpeedUnit}" : string.Empty, speedVal = t33?.speed != 0 ? $"{t33?.speed} {Global.SpeedUnit}" : string.Empty,
todayDown = t22 == null ? "" : Utils.HumanFy(t22.todayDown), todayDown = t22 == null ? "" : Utils.HumanFy(t22.todayDown),
@ -1367,7 +1372,6 @@ namespace v2rayN.ViewModels
public void Reload() public void Reload()
{ {
Global.reloadCore = true;
_ = LoadV2ray(); _ = LoadV2ray();
} }
@ -1387,7 +1391,6 @@ namespace v2rayN.ViewModels
{ {
_coreHandler.LoadCore(_config); _coreHandler.LoadCore(_config);
Global.reloadCore = false;
//ConfigHandler.SaveConfig(ref _config, false); //ConfigHandler.SaveConfig(ref _config, false);
ChangeSystemProxyStatus(_config.sysProxyType, false); ChangeSystemProxyStatus(_config.sysProxyType, false);