Code optimization, function asynchrony

This commit is contained in:
2dust
2024-10-21 09:45:33 +08:00
parent 394b657fc9
commit a866017b4c
21 changed files with 518 additions and 514 deletions
@@ -206,10 +206,10 @@ namespace ServiceLib.ViewModels
AutoHideStartup();
}
private void Init()
private async Task Init()
{
ConfigHandler.InitBuiltinRouting(_config);
ConfigHandler.InitBuiltinDNS(_config);
await ConfigHandler.InitBuiltinRouting(_config);
await ConfigHandler.InitBuiltinDNS(_config);
CoreHandler.Instance.Init(_config, UpdateHandler);
TaskHandler.Instance.RegUpdateTask(_config, UpdateTaskHandler);
@@ -218,7 +218,7 @@ namespace ServiceLib.ViewModels
StatisticsHandler.Instance.Init(_config, UpdateStatisticsHandler);
}
Reload();
await Reload();
}
#endregion Init
@@ -285,7 +285,7 @@ namespace ServiceLib.ViewModels
//if (blWindowsShutDown)
await SysProxyHandler.UpdateSysProxy(_config, true);
ConfigHandler.SaveConfig(_config);
await ConfigHandler.SaveConfig(_config);
await ProfileExHandler.Instance.SaveTo();
await StatisticsHandler.Instance.SaveTo();
StatisticsHandler.Instance.Close();
@@ -371,7 +371,7 @@ namespace ServiceLib.ViewModels
RefreshServers();
if (item.indexId == _config.indexId)
{
Reload();
await Reload();
}
}
}
@@ -464,7 +464,7 @@ namespace ServiceLib.ViewModels
if (ret == true)
{
Locator.Current.GetService<StatusBarViewModel>()?.InboundDisplayStatus();
Reload();
await Reload();
}
}
@@ -473,9 +473,9 @@ namespace ServiceLib.ViewModels
var ret = await _updateView?.Invoke(EViewAction.RoutingSettingWindow, null);
if (ret == true)
{
ConfigHandler.InitBuiltinRouting(_config);
await ConfigHandler.InitBuiltinRouting(_config);
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
Reload();
await Reload();
}
}
@@ -484,7 +484,7 @@ namespace ServiceLib.ViewModels
var ret = await _updateView?.Invoke(EViewAction.DNSSettingWindow, null);
if (ret == true)
{
Reload();
await Reload();
}
}
@@ -508,7 +508,7 @@ namespace ServiceLib.ViewModels
private async Task ClearServerStatistics()
{
StatisticsHandler.Instance.ClearAllServerStatistics();
await StatisticsHandler.Instance.ClearAllServerStatistics();
RefreshServers();
}
@@ -535,6 +535,7 @@ namespace ServiceLib.ViewModels
await LoadCore();
Locator.Current.GetService<StatusBarViewModel>()?.TestServerAvailability();
await SysProxyHandler.UpdateSysProxy(_config, false);
_updateView?.Invoke(EViewAction.DispatcherReload, null);
}
@@ -552,22 +553,21 @@ namespace ServiceLib.ViewModels
private async Task LoadCore()
{
//if (_config.tunModeItem.enableTun)
//{
// Task.Delay(1000).Wait();
// WindowsUtils.RemoveTunDevice();
//}
await Task.Run(async () =>
{
//if (_config.tunModeItem.enableTun)
//{
// Task.Delay(1000).Wait();
// WindowsUtils.RemoveTunDevice();
//}
var node = await ConfigHandler.GetDefaultServer(_config);
CoreHandler.Instance.LoadCore(node);
await CoreHandler.Instance.LoadCore(node);
});
}
public void CloseCore()
public async Task CloseCore()
{
ConfigHandler.SaveConfig(_config, false);
await ConfigHandler.SaveConfig(_config, false);
CoreHandler.Instance.CoreStop();
}
@@ -591,12 +591,12 @@ namespace ServiceLib.ViewModels
public async Task ApplyRegionalPreset(EPresetType type)
{
await ConfigHandler.ApplyRegionalPreset(_config, type);
ConfigHandler.InitRouting(_config);
await ConfigHandler.InitRouting(_config);
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
ConfigHandler.SaveConfig(_config, false);
await ConfigHandler.SaveConfig(_config, false);
await new UpdateService().UpdateGeoFileAll(_config, UpdateHandler);
Reload();
await Reload();
}
#endregion Presets