AI-optimized code
Some checks failed
release Linux / build (Release) (push) Has been cancelled
release macOS / build (Release) (push) Has been cancelled
release Windows desktop (Avalonia UI) / build (Release) (push) Has been cancelled
release Windows / build (Release) (push) Has been cancelled

This commit is contained in:
2dust 2025-03-07 12:11:19 +08:00
parent bcf43e2928
commit e6011cfede
7 changed files with 54 additions and 63 deletions

View file

@ -11,9 +11,9 @@ namespace ServiceLib.Handler
private Dictionary<string, ProxiesItem>? _proxies;
public Dictionary<string, object> ProfileContent { get; set; }
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync(Config config)
public async Task<Tuple<ClashProxies, ClashProviders>?> GetClashProxiesAsync()
{
for (var i = 0; i < 5; i++)
for (var i = 0; i < 3; i++)
{
var url = $"{GetApiUrl()}/proxies";
var result = await HttpClientHelper.Instance.TryGetAsync(url);
@ -41,34 +41,26 @@ namespace ServiceLib.Handler
{
if (blAll)
{
for (var i = 0; i < 5; i++)
{
if (_proxies != null)
{
break;
}
await Task.Delay(5000);
}
if (_proxies == null)
{
return;
await GetClashProxiesAsync();
}
lstProxy = new List<ClashProxyModel>();
foreach (var kv in _proxies)
foreach (var kv in _proxies ?? [])
{
if (Global.notAllowTestType.Contains(kv.Value.type.ToLower()))
if (Global.notAllowTestType.Contains(kv.Value.type?.ToLower()))
{
continue;
}
lstProxy.Add(new ClashProxyModel()
{
Name = kv.Value.name,
Type = kv.Value.type.ToLower(),
Type = kv.Value.type?.ToLower(),
});
}
}
if (lstProxy == null)
if (lstProxy is not { Count: > 0 })
{
return;
}
@ -157,7 +149,7 @@ namespace ServiceLib.Handler
}
}
public async Task<ClashConnections?> GetClashConnectionsAsync(Config config)
public async Task<ClashConnections?> GetClashConnectionsAsync()
{
try
{

View file

@ -582,7 +582,7 @@ namespace ServiceLib.Services.CoreConfig
var it = JsonUtils.DeepCopy(rule);
it.ip = null;
it.type = "field";
for (int k = it.domain.Count - 1; k >= 0; k--)
for (var k = it.domain.Count - 1; k >= 0; k--)
{
if (it.domain[k].StartsWith("#"))
{

View file

@ -74,6 +74,14 @@ namespace ServiceLib.ViewModels
}
private async Task CheckUpdate()
{
await Task.Run(async () =>
{
await CheckUpdateTask();
});
}
private async Task CheckUpdateTask()
{
_lstUpdated.Clear();
_lstUpdated = _checkUpdateModel.Where(x => x.IsSelected == true)

View file

@ -58,7 +58,7 @@ namespace ServiceLib.ViewModels
private async Task GetClashConnections()
{
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(_config);
var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync();
if (ret == null)
{
return;

View file

@ -13,7 +13,7 @@ namespace ServiceLib.ViewModels
{
private Dictionary<string, ProxiesItem>? _proxies;
private Dictionary<string, ProvidersItem>? _providers;
private int _delayTimeout = 99999999;
private readonly int _delayTimeout = 99999999;
private IObservableCollection<ClashProxyModel> _proxyGroups = new ObservableCollectionExtended<ClashProxyModel>();
private IObservableCollection<ClashProxyModel> _proxyDetails = new ObservableCollectionExtended<ClashProxyModel>();
@ -28,8 +28,8 @@ namespace ServiceLib.ViewModels
public ClashProxyModel SelectedDetail { get; set; }
public ReactiveCommand<Unit, Unit> ProxiesReloadCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesDelaytestCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesDelaytestPartCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesDelayTestCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesDelayTestPartCmd { get; }
public ReactiveCommand<Unit, Unit> ProxiesSelectActivityCmd { get; }
[Reactive]
@ -50,12 +50,12 @@ namespace ServiceLib.ViewModels
{
await ProxiesReload();
});
ProxiesDelaytestCmd = ReactiveCommand.CreateFromTask(async () =>
ProxiesDelayTestCmd = ReactiveCommand.CreateFromTask(async () =>
{
await ProxiesDelayTest(true);
});
ProxiesDelaytestPartCmd = ReactiveCommand.CreateFromTask(async () =>
ProxiesDelayTestPartCmd = ReactiveCommand.CreateFromTask(async () =>
{
await ProxiesDelayTest(false);
});
@ -78,7 +78,7 @@ namespace ServiceLib.ViewModels
this.WhenAnyValue(
x => x.RuleModeSelected,
y => y >= 0)
.Subscribe(async c => await DoRulemodeSelected(c));
.Subscribe(async c => await DoRuleModeSelected(c));
this.WhenAnyValue(
x => x.SortingSelected,
@ -98,7 +98,7 @@ namespace ServiceLib.ViewModels
_ = DelayTestTask();
}
private async Task DoRulemodeSelected(bool c)
private async Task DoRuleModeSelected(bool c)
{
if (!c)
{
@ -158,7 +158,7 @@ namespace ServiceLib.ViewModels
private async Task GetClashProxies(bool refreshUI)
{
var ret = await ClashApiHandler.Instance.GetClashProxiesAsync(_config);
var ret = await ClashApiHandler.Instance.GetClashProxiesAsync();
if (ret?.Item1 == null || ret.Item2 == null)
{
return;
@ -255,29 +255,23 @@ namespace ServiceLib.ViewModels
}
_proxies.TryGetValue(name, out var proxy);
if (proxy == null || proxy.all == null)
if (proxy?.all == null)
{
return;
}
var lstDetails = new List<ClashProxyModel>();
foreach (var item in proxy.all)
{
var IsActive = item == proxy.now;
var proxy2 = TryGetProxy(item);
if (proxy2 == null)
{
continue;
}
int delay = -1;
if (proxy2.history.Count > 0)
{
delay = proxy2.history[proxy2.history.Count - 1].delay;
}
var delay = proxy2.history?.Count > 0 ? proxy2.history.Last().delay : -1;
lstDetails.Add(new ClashProxyModel()
{
IsActive = IsActive,
IsActive = item == proxy.now,
Name = item,
Type = proxy2.type,
Delay = delay <= 0 ? _delayTimeout : delay,
@ -374,12 +368,7 @@ namespace ServiceLib.ViewModels
{
ClashApiHandler.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) =>
{
if (item == null)
{
await GetClashProxies(true);
return;
}
if (result.IsNullOrEmpty())
if (item == null || result.IsNullOrEmpty())
{
return;
}
@ -393,8 +382,11 @@ namespace ServiceLib.ViewModels
{
//UpdateHandler(false, $"{item.name}={result}");
var detail = _proxyDetails.FirstOrDefault(it => it.Name == result.IndexId);
if (detail != null)
if (detail == null)
{
return;
}
var dicResult = JsonUtils.Deserialize<Dictionary<string, object>>(result.Delay);
if (dicResult != null && dicResult.TryGetValue("delay", out var value))
{
@ -413,7 +405,6 @@ namespace ServiceLib.ViewModels
}
_proxyDetails.Replace(detail, JsonUtils.DeepCopy(detail));
}
}
#endregion proxy function

View file

@ -27,9 +27,9 @@ namespace v2rayN.Desktop.Views
this.Bind(ViewModel, vm => vm.SelectedDetail, v => v.lstProxyDetails.SelectedItem).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesReloadCmd, v => v.menuProxiesReload).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesSelectActivityCmd, v => v.menuProxiesSelectActivity).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.RuleModeSelected, v => v.cmbRulemode.SelectedIndex).DisposeWith(disposables);

View file

@ -28,9 +28,9 @@ namespace v2rayN.Views
this.Bind(ViewModel, vm => vm.SelectedDetail, v => v.lstProxyDetails.SelectedItem).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesReloadCmd, v => v.menuProxiesReload).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestCmd, v => v.menuProxiesDelaytest).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelaytestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesDelayTestPartCmd, v => v.menuProxiesDelaytestPart).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProxiesSelectActivityCmd, v => v.menuProxiesSelectActivity).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.RuleModeSelected, v => v.cmbRulemode.SelectedIndex).DisposeWith(disposables);