Compare commits

..

No commits in common. "e20c11c1a7a0759771df87bfec1fe0d9c6a3ae93" and "6f06b16c76d529faec9a49dd5881bf8635ca5c60" have entirely different histories.

View file

@ -64,6 +64,8 @@ public class MainWindowViewModel : MyReactiveObject
#endregion Menu #endregion Menu
private bool _hasNextReloadJob = false;
#region Init #region Init
public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView) public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
@ -266,6 +268,7 @@ public class MainWindowViewModel : MyReactiveObject
} }
await RefreshServers(); await RefreshServers();
SetReloadEnabled(true);
await Reload(); await Reload();
} }
@ -522,59 +525,49 @@ public class MainWindowViewModel : MyReactiveObject
#region core job #region core job
private bool _hasNextReloadJob = false;
private readonly SemaphoreSlim _reloadSemaphore = new(1, 1);
public async Task Reload() public async Task Reload()
{ {
//If there are unfinished reload job, marked with next job. //If there are unfinished reload job, marked with next job.
if (!await _reloadSemaphore.WaitAsync(0)) if (!BlReloadEnabled)
{ {
_hasNextReloadJob = true; _hasNextReloadJob = true;
return; return;
} }
try SetReloadEnabled(false);
var msgs = await ActionPrecheckManager.Instance.Check(_config.IndexId);
if (msgs.Count > 0)
{ {
SetReloadEnabled(false); foreach (var msg in msgs)
var msgs = await ActionPrecheckManager.Instance.Check(_config.IndexId);
if (msgs.Count > 0)
{ {
foreach (var msg in msgs) NoticeManager.Instance.SendMessage(msg);
{
NoticeManager.Instance.SendMessage(msg);
}
NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true));
return;
} }
NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true));
await Task.Run(async () =>
{
await LoadCore();
await SysProxyHandler.UpdateSysProxy(_config, false);
await Task.Delay(1000);
});
AppEvents.TestServerRequested.Publish();
var showClashUI = _config.IsRunningCore(ECoreType.sing_box);
if (showClashUI)
{
AppEvents.ProxiesReloadRequested.Publish();
}
ReloadResult(showClashUI);
}
finally
{
SetReloadEnabled(true); SetReloadEnabled(true);
_reloadSemaphore.Release(); return;
//If there is a next reload job, execute it. }
if (_hasNextReloadJob)
{ await Task.Run(async () =>
_hasNextReloadJob = false; {
await Reload(); await LoadCore();
} await SysProxyHandler.UpdateSysProxy(_config, false);
await Task.Delay(1000);
});
AppEvents.TestServerRequested.Publish();
var showClashUI = _config.IsRunningCore(ECoreType.sing_box);
if (showClashUI)
{
AppEvents.ProxiesReloadRequested.Publish();
}
ReloadResult(showClashUI);
SetReloadEnabled(true);
if (_hasNextReloadJob)
{
_hasNextReloadJob = false;
await Reload();
} }
} }