Code optimization, function asynchrony

This commit is contained in:
2dust
2024-10-20 11:51:05 +08:00
parent 50449df08d
commit 394b657fc9
29 changed files with 467 additions and 526 deletions
@@ -286,8 +286,8 @@ namespace ServiceLib.ViewModels
await SysProxyHandler.UpdateSysProxy(_config, true);
ConfigHandler.SaveConfig(_config);
ProfileExHandler.Instance.SaveTo();
StatisticsHandler.Instance.SaveTo();
await ProfileExHandler.Instance.SaveTo();
await StatisticsHandler.Instance.SaveTo();
StatisticsHandler.Instance.Close();
CoreHandler.Instance.CoreStop();
@@ -383,7 +383,7 @@ namespace ServiceLib.ViewModels
await _updateView?.Invoke(EViewAction.AddServerViaClipboard, null);
return;
}
int ret = ConfigHandler.AddBatchServers(_config, clipboardData, _config.subIndexId, false);
int ret = await ConfigHandler.AddBatchServers(_config, clipboardData, _config.subIndexId, false);
if (ret > 0)
{
RefreshSubscriptions();
@@ -427,7 +427,7 @@ namespace ServiceLib.ViewModels
}
else
{
int ret = ConfigHandler.AddBatchServers(_config, result, _config.subIndexId, false);
int ret = await ConfigHandler.AddBatchServers(_config, result, _config.subIndexId, false);
if (ret > 0)
{
RefreshSubscriptions();
@@ -451,7 +451,7 @@ namespace ServiceLib.ViewModels
public async Task UpdateSubscriptionProcess(string subId, bool blProxy)
{
(new UpdateService()).UpdateSubscriptionProcess(_config, subId, blProxy, UpdateTaskHandler);
await (new UpdateService()).UpdateSubscriptionProcess(_config, subId, blProxy, UpdateTaskHandler);
}
#endregion Subscription
@@ -552,7 +552,7 @@ namespace ServiceLib.ViewModels
private async Task LoadCore()
{
await Task.Run(() =>
await Task.Run(async () =>
{
//if (_config.tunModeItem.enableTun)
//{
@@ -560,7 +560,7 @@ namespace ServiceLib.ViewModels
// WindowsUtils.RemoveTunDevice();
//}
var node = ConfigHandler.GetDefaultServer(_config);
var node = await ConfigHandler.GetDefaultServer(_config);
CoreHandler.Instance.LoadCore(node);
});
}
@@ -590,7 +590,7 @@ namespace ServiceLib.ViewModels
public async Task ApplyRegionalPreset(EPresetType type)
{
ConfigHandler.ApplyRegionalPreset(_config, type);
await ConfigHandler.ApplyRegionalPreset(_config, type);
ConfigHandler.InitRouting(_config);
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();