mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-27 21:43:14 +08:00
缓存成功时的加速项目列表在失败时请求
This commit is contained in:
@@ -35,8 +35,8 @@
|
||||
Classes="paper"
|
||||
Background="{DynamicResource ThemeBrushKey}">
|
||||
<ListBox x:Name="items" Classes="metro" Width="350"
|
||||
Items="{Binding Source={x:Static service:ProxyService.Current},Path=ProxyDomains,Mode=OneWay}"
|
||||
SelectedItem="{Binding Source={x:Static service:ProxyService.Current},Path=SelectGroup,Mode=TwoWay}"
|
||||
Items="{ReflectionBinding Source={x:Static service:ProxyService.Current},Path=ProxyDomainsList,Mode=OneWay}"
|
||||
SelectedItem="{ReflectionBinding Source={x:Static service:ProxyService.Current},Path=SelectGroup,Mode=TwoWay}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
AutoScrollToSelectedItem="True"
|
||||
Background="Transparent">
|
||||
|
||||
+29
-28
@@ -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()
|
||||
{
|
||||
|
||||
@@ -26,23 +26,23 @@ namespace System.Application.Services
|
||||
|
||||
public ProxyService()
|
||||
{
|
||||
ProxyDomains = new SourceList<AccelerateProjectGroupDTO>();
|
||||
ProxyScripts = new SourceList<ScriptDTO>();
|
||||
httpProxyService.CertificateEngine = Titanium.Web.Proxy.Network.CertificateEngine.BouncyCastle;
|
||||
|
||||
this.ProxyDomains
|
||||
.Connect()
|
||||
//.Filter(scriptFilter)
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Sort(SortExpressionComparer<AccelerateProjectGroupDTO>.Ascending(x => x.Order).ThenBy(x => x.Name))
|
||||
.Bind(out _ProxyDomainsList)
|
||||
.Subscribe(_ => SelectGroup = ProxyDomains.Items.FirstOrDefault());
|
||||
}
|
||||
|
||||
private ReadOnlyObservableCollection<AccelerateProjectGroupDTO>? _ProxyDomains;
|
||||
public ReadOnlyObservableCollection<AccelerateProjectGroupDTO>? ProxyDomains
|
||||
{
|
||||
get => _ProxyDomains;
|
||||
set
|
||||
{
|
||||
if (_ProxyDomains != value)
|
||||
{
|
||||
_ProxyDomains = value;
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
public SourceList<AccelerateProjectGroupDTO> ProxyDomains { get; }
|
||||
|
||||
private ReadOnlyObservableCollection<AccelerateProjectGroupDTO>? _ProxyDomainsList;
|
||||
public ReadOnlyObservableCollection<AccelerateProjectGroupDTO>? 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<IDesktopPlatformService>().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<IDesktopPlatformService>().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<AccelerateProjectGroupDTO>(new ObservableCollection<AccelerateProjectGroupDTO>(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<AccelerateProjectDTO>())
|
||||
.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<AccelerateProjectDTO>())
|
||||
.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<List<AccelerateProjectGroupDTO>>(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"));
|
||||
|
||||
@@ -28,8 +28,7 @@ namespace System.Application.UI.ViewModels
|
||||
Activator = new ViewModelActivator();
|
||||
this.WhenActivated((R_CompositeDisposable disposables) =>
|
||||
{
|
||||
disposables
|
||||
.DisposeWith(disposables);
|
||||
disposables.DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user