From 69b85908819e29d60e8a154887a505ccc6114346 Mon Sep 17 00:00:00 2001 From: k1mlka Date: Fri, 6 Sep 2024 11:56:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=90=AF?= =?UTF-8?q?=E7=94=A8=20=E2=80=9C=E5=90=AF=E5=8A=A8=E6=97=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8A=A0=E9=80=9F=E2=80=9D=20=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=A1=B5=E9=9D=A2=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Mvvm/ProxyService.cs | 3 +++ .../UI/ViewModels/AcceleratorPageViewModel.cs | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs b/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs index 76690118733..433a132af3b 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs @@ -114,6 +114,8 @@ public AccelerateProjectGroupDTO? SelectGroup public SourceList ProxyScripts { get; } + public event EventHandler? OnStartOrStopProxyService; + public async Task StartOrStopProxyService(bool startOrStop) { if (startOrStop == ProxyStatus) @@ -153,6 +155,7 @@ public async Task StartOrStopProxyService(bool startOrStop) ProxyStarting = false; ProxyStatus = startOrStop; IsAnyProxyScripts = ProxyStatus && IsEnableScript; + OnStartOrStopProxyService?.Invoke(this, startOrStop); } } diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs index 938b825b7f7..298ebb3b000 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs @@ -17,15 +17,9 @@ public sealed partial class AcceleratorPageViewModel public AcceleratorPageViewModel() { - StartProxyCommand = ReactiveCommand.CreateFromTask(async _ => + ProxyService.Current.OnStartOrStopProxyService += (_, start) => { -#if LINUX - if (!EnvironmentCheck()) return; -#endif - //ProxyService.Current.ProxyStatus = !ProxyService.Current.ProxyStatus; - await ProxyService.Current.StartOrStopProxyService(!ProxyService.Current.ProxyStatus); - - if (ProxyService.Current.ProxyStatus == false) + if (start == false) return; // Create new ProxyEnableDomain for 加速服务 page @@ -47,6 +41,15 @@ public AcceleratorPageViewModel() .ToList(); EnableProxyDomainGroupVMs = enableGroupDomain.AsReadOnly(); + }; + + StartProxyCommand = ReactiveCommand.CreateFromTask(async _ => + { +#if LINUX + if (!EnvironmentCheck()) return; +#endif + //ProxyService.Current.ProxyStatus = !ProxyService.Current.ProxyStatus; + await ProxyService.Current.StartOrStopProxyService(!ProxyService.Current.ProxyStatus); }); RefreshCommand = ReactiveCommand.Create(async () => From 2e97c2edc24b1ad432d926c46a0be76bc18260c0 Mon Sep 17 00:00:00 2001 From: k1mlka Date: Thu, 12 Sep 2024 17:03:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E4=BB=BB?= =?UTF-8?q?=E6=84=8F=E8=BE=93=E5=85=A5=E9=94=99=E8=AF=AF=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E8=BF=94=E5=9B=9E=E5=BB=B6=E8=BF=9F=E5=92=8C=E7=A9=BA?= =?UTF-8?q?ip=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/ViewModels/AcceleratorPageViewModel.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs index 298ebb3b000..6a375e77368 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs @@ -20,7 +20,10 @@ public AcceleratorPageViewModel() ProxyService.Current.OnStartOrStopProxyService += (_, start) => { if (start == false) + { + EnableProxyDomainGroupVMs = null; return; + } // Create new ProxyEnableDomain for 加速服务 page var enableGroupDomain = ProxyService.Current.ProxyDomainsList @@ -113,8 +116,11 @@ public AcceleratorPageViewModel() var configDns = ProxySettings.ProxyMasterDns.Value ?? string.Empty; (delayMs, address) = await networkTestService.TestDNSAsync(testDomain, configDns, 53); } + if (address.Length == 0) + throw new Exception("Parsing failed. Return empty ip address."); + DNSTestDelay = delayMs + "ms "; - DNSTestResult = "" + address.FirstOrDefault() ?? "0.0.0.0"; + DNSTestResult = string.Empty + address.FirstOrDefault(); } catch (Exception ex) { From a9e913434a919bea73fcd06271d2bac56755ec92 Mon Sep 17 00:00:00 2001 From: k1mlka Date: Mon, 23 Sep 2024 11:28:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=9A=A7=20=E9=87=8D=E6=96=B0=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0EnableProxyDomainGroupVMs=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Mvvm/ProxyService.cs | 3 -- .../UI/ViewModels/AcceleratorPageViewModel.cs | 50 +++++++++---------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs b/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs index 433a132af3b..76690118733 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/Services/Mvvm/ProxyService.cs @@ -114,8 +114,6 @@ public AccelerateProjectGroupDTO? SelectGroup public SourceList ProxyScripts { get; } - public event EventHandler? OnStartOrStopProxyService; - public async Task StartOrStopProxyService(bool startOrStop) { if (startOrStop == ProxyStatus) @@ -155,7 +153,6 @@ public async Task StartOrStopProxyService(bool startOrStop) ProxyStarting = false; ProxyStatus = startOrStop; IsAnyProxyScripts = ProxyStatus && IsEnableScript; - OnStartOrStopProxyService?.Invoke(this, startOrStop); } } diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs index 6a375e77368..490ff3bbfed 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/AcceleratorPageViewModel.cs @@ -17,34 +17,30 @@ public sealed partial class AcceleratorPageViewModel public AcceleratorPageViewModel() { - ProxyService.Current.OnStartOrStopProxyService += (_, start) => - { - if (start == false) + ProxyService.Current.WhenValueChanged(x => x.ProxyStatus) + .Where(x => x == true) + .Subscribe(_ => { - EnableProxyDomainGroupVMs = null; - return; - } - - // Create new ProxyEnableDomain for 加速服务 page - var enableGroupDomain = ProxyService.Current.ProxyDomainsList - .Where(list => list.ThreeStateEnable == true || list.ThreeStateEnable == null) - .Select(list => new ProxyDomainGroupViewModel - { - Name = list.Name, - IconUrl = list.IconUrl ?? string.Empty, - EnableProxyDomainVMs = new( - list.Items! - .Where(i => i.ThreeStateEnable == true) - .Select(i => new ProxyDomainViewModel(i.Name, i.ProxyType, "https://" + i.ListenDomainNames.Split(";")[0], - i.Items? - .Select(c => new ProxyDomainViewModel(c.Name, c.ProxyType, "https://" + c.ListenDomainNames.Split(';')[0])) - .ToList())) - .ToList()), - }) - .ToList(); - - EnableProxyDomainGroupVMs = enableGroupDomain.AsReadOnly(); - }; + // Create new ProxyEnableDomain for 加速服务 page + var enableGroupDomain = ProxyService.Current.ProxyDomainsList + .Where(list => list.ThreeStateEnable == true || list.ThreeStateEnable == null) + .Select(list => new ProxyDomainGroupViewModel + { + Name = list.Name, + IconUrl = list.IconUrl ?? string.Empty, + EnableProxyDomainVMs = new( + list.Items! + .Where(i => i.ThreeStateEnable == true) + .Select(i => new ProxyDomainViewModel(i.Name, i.ProxyType, "https://" + i.ListenDomainNames.Split(";")[0], + i.Items? + .Select(c => new ProxyDomainViewModel(c.Name, c.ProxyType, "https://" + c.ListenDomainNames.Split(';')[0])) + .ToList())) + .ToList()), + }) + .ToList(); + + EnableProxyDomainGroupVMs = enableGroupDomain.AsReadOnly(); + }); StartProxyCommand = ReactiveCommand.CreateFromTask(async _ => {