-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3471 from BeyondDimension/feature/ipv6check
Feature/ipv6check
- Loading branch information
Showing
10 changed files
with
413 additions
and
367 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/BD.WTTS.Client.Plugins.Accelerator/Models/ProxyDomainGroupViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using FluentAvalonia.Core; | ||
using System.Reactive; | ||
|
||
namespace BD.WTTS.Models; | ||
|
||
public class ProxyDomainGroupViewModel : ReactiveObject | ||
{ | ||
private readonly INetworkTestService networkTestService = INetworkTestService.Instance; | ||
|
||
public string Name { get; set; } = string.Empty; | ||
|
||
public string IconUrl { get; set; } = string.Empty; | ||
|
||
public ReadOnlyCollection<ProxyDomainViewModel>? EnableProxyDomainVMs { get; set; } | ||
|
||
public ReactiveCommand<Unit, Unit> ConnectTestCommand { get; set; } | ||
|
||
public ProxyDomainGroupViewModel() | ||
{ | ||
ConnectTestCommand = ReactiveCommand.CreateFromTask(async () => | ||
{ | ||
if (EnableProxyDomainVMs == null) | ||
{ | ||
Toast.Show(ToastIcon.Warning, "没有可测试的项目"); | ||
return; | ||
} | ||
var tasks = EnableProxyDomainVMs.Select(async enableDomain => | ||
{ | ||
enableDomain.DelayMillseconds = "- ms"; | ||
var (success, delayMs) = await networkTestService.TestOpenUrlAsync(enableDomain.Url); | ||
enableDomain.DelayMillseconds = success switch | ||
{ | ||
true when delayMs > 20000 => "Timeout", | ||
true => delayMs.ToString() + " ms", | ||
false => "error", | ||
}; | ||
}); | ||
await Task.WhenAll(tasks); | ||
if (EnableProxyDomainVMs.Count(x => x.DelayMillseconds == "Timeout") == EnableProxyDomainVMs.Count) | ||
{ | ||
Toast.Show(ToastIcon.Error, "当前测试项全部未通过,请检查网络链接状况,以及代理设置里的设置项是否正常。"); | ||
} | ||
}); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/BD.WTTS.Client.Plugins.Accelerator/Models/ProxyDomainViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Avalonia.Media; | ||
|
||
namespace BD.WTTS.Models; | ||
|
||
public class ProxyDomainViewModel : ReactiveObject | ||
{ | ||
private readonly INetworkTestService networkTestService = INetworkTestService.Instance; | ||
|
||
public string Name { get; } | ||
|
||
public ProxyType ProxyType { get; } | ||
|
||
public string Url { get; } | ||
|
||
[Reactive] | ||
public string DelayMillseconds { get; set; } = string.Empty; | ||
|
||
[ObservableAsProperty] | ||
public bool RetestButtonVisible { get; } | ||
|
||
[ObservableAsProperty] | ||
public IBrush DelayColor { get; } = null!; | ||
|
||
public ReadOnlyCollection<ProxyDomainViewModel>? Children { get; } | ||
|
||
public ProxyDomainViewModel(string name, ProxyType proxyType, string url, List<ProxyDomainViewModel>? children = null) | ||
{ | ||
Name = name; | ||
ProxyType = proxyType; | ||
Url = url; | ||
Children = children?.AsReadOnly(); | ||
|
||
this.WhenAnyValue(x => x.DelayMillseconds) | ||
.Subscribe(delay => Children?.ForEach(child => child.DelayMillseconds = delay)); | ||
|
||
this.WhenAnyValue(x => x.DelayMillseconds) | ||
.Select(d => d != string.Empty && d != "-") | ||
.ToPropertyEx(this, x => x.RetestButtonVisible); | ||
|
||
const int DelayMiddle = 1000; | ||
this.WhenAnyValue(x => x.DelayMillseconds) | ||
.Select(d => d switch | ||
{ | ||
"Timeout" or "error" => Brushes.Red, | ||
var s when s.Split(' ') is [var num, "ms"] && int.TryParse(num, out int ms) | ||
=> ms switch | ||
{ | ||
<= DelayMiddle => Brushes.Green, | ||
> DelayMiddle => Brushes.Orange, | ||
}, | ||
_ => Brushes.Gray, | ||
}) | ||
.ToPropertyEx(this, x => x.DelayColor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.