Skip to content

Commit

Permalink
Improve reload function
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 14, 2025
1 parent 7370684 commit 4ad4e27
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class MainWindowViewModel : MyReactiveObject

#endregion Menu

private bool _hasNextReloadJob = false;

#region Init

public MainWindowViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
Expand Down Expand Up @@ -534,14 +536,12 @@ private async Task OpenTheFileLocation()

#region core job

public async Task Reload(int times = 0)
public async Task Reload()
{
//If there are unfinished reload job, wait a few seconds and exec again.
//If there are unfinished reload job, marked with next job.
if (!BlReloadEnabled)
{
await Task.Delay(3000);
if (times > 3) return;
await Reload(++times);
_hasNextReloadJob = true;
return;
}

Expand All @@ -552,12 +552,19 @@ public async Task Reload(int times = 0)
await SysProxyHandler.UpdateSysProxy(_config, false);

_updateView?.Invoke(EViewAction.DispatcherReload, null);

BlReloadEnabled = true;
if (_hasNextReloadJob)
{
_hasNextReloadJob = false;
await Reload();
}
}

public void ReloadResult()
{
// BlReloadEnabled = true;
//Locator.Current.GetService<StatusBarViewModel>()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false);
BlReloadEnabled = true;
ShowClashUI = _config.IsRunningCore(ECoreType.sing_box);
if (ShowClashUI)
{
Expand Down

0 comments on commit 4ad4e27

Please sign in to comment.