Optimizing reload core

This commit is contained in:
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

@ -26,8 +26,6 @@ namespace v2rayN.Handler
} }
public void LoadCore(Config config) public void LoadCore(Config config)
{
if (Global.reloadCore)
{ {
var node = ConfigHandler.GetDefaultServer(ref config); var node = ConfigHandler.GetDefaultServer(ref config);
if (node == null) if (node == null)
@ -69,7 +67,6 @@ namespace v2rayN.Handler
} }
} }
} }
}
public int LoadCoreConfigString(Config config, List<ServerTestItem> _selecteds) public int LoadCoreConfigString(Config config, List<ServerTestItem> _selecteds)
{ {

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();
if (indexIdOld != _config.indexId)
{
Reload(); 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);