From e4a64f36f77a09514b17dbc1a0dc212020929958 Mon Sep 17 00:00:00 2001 From: rmbgame Date: Fri, 4 Jun 2021 19:48:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=88=90=E5=8A=9F=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=8A=A0=E9=80=9F=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=9C=A8=E5=A4=B1=E8=B4=A5=E6=97=B6=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Views/Pages/CommunityProxyPage.axaml | 4 +- .../Views/Pages/CommunityProxyPage.axaml.cs | 57 ++++---- .../Services/Mvvm/ProxyService.cs | 137 +++++++++++------- .../UI/ViewModels/Base/ViewModelBase.cs | 3 +- .../Pages/CommunityProxyPageViewModel.cs | 3 + 5 files changed, 118 insertions(+), 86 deletions(-) diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml index 839e829fc..eb62d993b 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml @@ -35,8 +35,8 @@ Classes="paper" Background="{DynamicResource ThemeBrushKey}"> diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml.cs index b75b8bfdb..10f147d8f 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/CommunityProxyPage.axaml.cs @@ -11,7 +11,7 @@ namespace System.Application.UI.Views.Pages public class CommunityProxyPage : UserControl { //private ListBox _items; - private IScrollable _scroll; + //private IScrollable _scroll; //private Button _left; //private Button _right; @@ -20,37 +20,38 @@ namespace System.Application.UI.Views.Pages InitializeComponent(); //_scroll = _items.Scroll; //_items.PointerWheelChanged += _items_PointerWheelChanged; + } - private void _items_PointerWheelChanged(object sender, Avalonia.Input.PointerWheelEventArgs e) - { - var Extent = _scroll.Extent; - var Offset = _scroll.Offset; - var Viewport = _scroll.Viewport; - if (Extent.Height > Viewport.Height || Extent.Width > Viewport.Width) - { - double x = Offset.X; - double y = Offset.Y; + //private void _items_PointerWheelChanged(object sender, Avalonia.Input.PointerWheelEventArgs e) + //{ + // var Extent = _scroll.Extent; + // var Offset = _scroll.Offset; + // var Viewport = _scroll.Viewport; + // if (Extent.Height > Viewport.Height || Extent.Width > Viewport.Width) + // { + // double x = Offset.X; + // double y = Offset.Y; - if (Extent.Height > Viewport.Height) - { - double height = 50; - y += -e.Delta.Y * height; - y = Math.Max(y, 0); - y = Math.Min(y, Extent.Height - Viewport.Height); - } - if (Extent.Height == Viewport.Height + y && Extent.Width > Viewport.Width) - { - double width = 50; - x += -e.Delta.Y * width; - x = Math.Max(x, 0); - x = Math.Min(x, Extent.Width - Viewport.Width); - } + // if (Extent.Height > Viewport.Height) + // { + // double height = 50; + // y += -e.Delta.Y * height; + // y = Math.Max(y, 0); + // y = Math.Min(y, Extent.Height - Viewport.Height); + // } + // if (Extent.Height == Viewport.Height + y && Extent.Width > Viewport.Width) + // { + // double width = 50; + // x += -e.Delta.Y * width; + // x = Math.Max(x, 0); + // x = Math.Min(x, Extent.Width - Viewport.Width); + // } - _scroll.Offset = new Vector(x, y); - e.Handled = true; - } - } + // _scroll.Offset = new Vector(x, y); + // e.Handled = true; + // } + //} private void InitializeComponent() { diff --git a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs index b611a1256..7a479caf9 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs @@ -26,23 +26,23 @@ namespace System.Application.Services public ProxyService() { + ProxyDomains = new SourceList(); ProxyScripts = new SourceList(); httpProxyService.CertificateEngine = Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle; + + this.ProxyDomains + .Connect() + //.Filter(scriptFilter) + .ObserveOn(RxApp.MainThreadScheduler) + .Sort(SortExpressionComparer.Ascending(x => x.Order).ThenBy(x => x.Name)) + .Bind(out _ProxyDomainsList) + .Subscribe(_ => SelectGroup = ProxyDomains.Items.FirstOrDefault()); } - private ReadOnlyObservableCollection? _ProxyDomains; - public ReadOnlyObservableCollection? ProxyDomains - { - get => _ProxyDomains; - set - { - if (_ProxyDomains != value) - { - _ProxyDomains = value; - this.RaisePropertyChanged(); - } - } - } + public SourceList ProxyDomains { get; } + + private ReadOnlyObservableCollection? _ProxyDomainsList; + public ReadOnlyObservableCollection? ProxyDomainsList => _ProxyDomainsList; bool _IsLoading; public bool IsLoading @@ -64,9 +64,9 @@ namespace System.Application.Services { get { - if (!ProxyDomains.Any_Nullable()) + if (!ProxyDomains.Items.Any_Nullable()) return null; - return ProxyDomains!.SelectMany(s => + return ProxyDomains.Items.SelectMany(s => { return s.Items.Where(w => w.Enable); }).ToArray(); @@ -166,28 +166,28 @@ namespace System.Application.Services if (!ProxySettings.EnableWindowsProxy.Value) { - if (DI.Platform == Platform.Windows) + //if (DI.Platform == Platform.Windows) + //{ + // var inUse = httpProxyService.PortInUse(443); + // if (inUse) + // { + // var p = DI.Get().GetProcessByPortOccupy(443, true); + // if (p != null) + // { + // Toast.Show(string.Format(AppResources.CommunityFix_StartProxyFaild443, p.ProcessName)); + // return; + // } + // } + //} + //else + //{ + var inUse = httpProxyService.PortInUse(443); + if (inUse) { - var inUse = httpProxyService.PortInUse(443); - if (inUse) - { - var p = DI.Get().GetProcessByPortOccupy(443, true); - if (p != null) - { - Toast.Show(string.Format(AppResources.CommunityFix_StartProxyFaild443, p.ProcessName)); - return; - } - } - } - else - { - var inUse = httpProxyService.PortInUse(443); - if (inUse) - { - Toast.Show(string.Format(AppResources.CommunityFix_StartProxyFaild443, "")); - return; - } + Toast.Show(string.Format(AppResources.CommunityFix_StartProxyFaild443, "")); + return; } + //} } var isRun = httpProxyService.StartProxy(ProxySettings.EnableWindowsProxy.Value, ProxySettings.IsProxyGOG.Value); @@ -291,30 +291,34 @@ namespace System.Application.Services } } - ProxyDomains = new ReadOnlyObservableCollection(new ObservableCollection(result.Content!)); + ProxyDomains.Clear(); + ProxyDomains.AddRange(result.Content); + } - foreach (var item in ProxyDomains) + LoadOrSaveLocalAccelerate(); + + if (ProxyDomains.Items.Any_Nullable()) + { + foreach (var item in ProxyDomains.Items) { item.ImageStream = IHttpService.Instance.GetImageAsync(ImageUrlHelper.GetImageApiUrlById(item.ImageId), ImageChannelType.AccelerateGroup); } - - SelectGroup = ProxyDomains.FirstOrDefault(); - - this.WhenAnyValue(v => v.ProxyDomains) - .Subscribe(domain => domain? - .ToObservableChangeSet() - .AutoRefresh(x => x.ObservableItems) - .TransformMany(t => t.ObservableItems ?? new ObservableCollection()) - .AutoRefresh(x => x.Enable) - .WhenPropertyChanged(x => x.Enable, false) - .Subscribe(_ => - { - if (EnableProxyDomains != null) - { - ProxySettings.SupportProxyServicesStatus.Value = EnableProxyDomains.Select(k => k.Id.ToString()).ToList(); - } - })); } + + this.WhenAnyValue(v => v.ProxyDomainsList) + .Subscribe(domain => domain? + .ToObservableChangeSet() + .AutoRefresh(x => x.ObservableItems) + .TransformMany(t => t.ObservableItems ?? new ObservableCollection()) + .AutoRefresh(x => x.Enable) + .WhenPropertyChanged(x => x.Enable, false) + .Subscribe(_ => + { + if (EnableProxyDomains != null) + { + ProxySettings.SupportProxyServicesStatus.Value = EnableProxyDomains.Select(k => k.Id.ToString()).ToList(); + } + })); #endregion } @@ -358,6 +362,31 @@ namespace System.Application.Services #endregion } + private void LoadOrSaveLocalAccelerate() + { + var filepath = Path.Combine(IOPath.AppDataDirectory, "Accelerates.json"); + var file = new FileInfo(filepath); + if (ProxyDomains.Items.Any_Nullable()) + { + using var stream = file.Open(FileMode.Create, FileAccess.Write); + var content = Serializable.SJSON(ProxyDomains.Items); + stream.Write(Text.Encoding.ASCII.GetBytes(content)); + stream.Close(); + } + else + { + if (file.Exists) + { + using var stream = file.Open(FileMode.Open, FileAccess.ReadWrite); + ProxyDomains.Clear(); + var accelerates = Serializable.DJSON>(stream.ReadStringAscii()); + if (accelerates.Any_Nullable()) + ProxyDomains.AddRange(accelerates!); + stream.Close(); + } + } + } + public async void BasicsInfo() { var basicsItem = ProxyScripts.Items.FirstOrDefault(x => x.Id == Guid.Parse("00000000-0000-0000-0000-000000000001")); diff --git a/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs b/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs index 1d0aab282..2f56943de 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs @@ -28,8 +28,7 @@ namespace System.Application.UI.ViewModels Activator = new ViewModelActivator(); this.WhenActivated((R_CompositeDisposable disposables) => { - disposables - .DisposeWith(disposables); + disposables.DisposeWith(disposables); }); } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs index d8d703411..3c3835143 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs @@ -1,3 +1,5 @@ +using DynamicData; +using DynamicData.Binding; using ReactiveUI; using System.Application.Models; using System.Application.Models.Settings; @@ -8,6 +10,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Properties; using System.Reactive; +using System.Reactive.Linq; using System.Threading.Tasks; namespace System.Application.UI.ViewModels