From 7d9607b97e9d20a3a06fffc08302bb273ec815b7 Mon Sep 17 00:00:00 2001 From: rmbgame Date: Mon, 28 Jun 2021 09:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=8A=A0=E9=80=9F=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- references/ArchiSteamFarm | 2 +- .../Views/MainWindow.axaml.cs | 16 ++++++ .../Views/Pages/CommunityProxyPage.axaml.cs | 3 +- .../UI/Views/Pages/DebugPage.axaml.cs | 3 +- .../UI/Views/Pages/DebugWebViewPage.axaml.cs | 3 +- .../UI/Views/Pages/StartPage.axaml.cs | 3 +- .../UI/Views/Pages/SteamAccountPage.axaml.cs | 3 +- .../UI/Views/Windows/FluentWindow.cs | 2 +- .../Services/Mvvm/ProxyService.cs | 32 +++++++----- .../UI/ViewModels/Base/TabItemViewModel.cs | 2 +- .../UI/ViewModels/Base/ViewModelBase.cs | 4 +- .../Pages/CommunityProxyPageViewModel.cs | 20 +++++++- .../ViewModels/Pages/GameListPageViewModel.cs | 2 +- .../Pages/LocalAuthPageViewModel.cs | 2 +- .../Pages/ProxyScriptManagePageViewModel.cs | 2 +- .../Pages/SteamAccountPageViewModel.cs | 2 +- .../ArchiSteamFarmServiceImpl.cs | 50 +++++++++++++++++++ 17 files changed, 124 insertions(+), 27 deletions(-) diff --git a/references/ArchiSteamFarm b/references/ArchiSteamFarm index 5966e0011..7aedbf79a 160000 --- a/references/ArchiSteamFarm +++ b/references/ArchiSteamFarm @@ -1 +1 @@ -Subproject commit 5966e0011d06e9cedfa3cd5ea2652ef5f315cf10 +Subproject commit 7aedbf79aca09fb6b903bf65955ff81e0bc4c764 diff --git a/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs b/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs index 370f17c90..510dc0295 100644 --- a/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs @@ -27,11 +27,27 @@ namespace System.Application.UI.Views _isOpenWindow = false; e.Cancel = true; Hide(); + + if (this.ViewModel is not null) + foreach (var tab in this.ViewModel.TabItems) + { + tab.Deactivation(); + } } #endif base.OnClosed(e); } + protected override void FluentWindow_Opened(object? sender, EventArgs e) + { + if (this.ViewModel is not null) + foreach (var tab in this.ViewModel.TabItems) + { + tab.Activation(); + } + base.FluentWindow_Opened(sender, e); + } + private void InitializeComponent() { AvaloniaXamlLoader.Load(this); 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 10f147d8f..64b7ee692 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 @@ -4,11 +4,12 @@ using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Controls.Selection; using Avalonia.Markup.Xaml; +using Avalonia.ReactiveUI; using System.Application.UI.ViewModels; namespace System.Application.UI.Views.Pages { - public class CommunityProxyPage : UserControl + public class CommunityProxyPage : ReactiveUserControl { //private ListBox _items; //private IScrollable _scroll; diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugPage.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugPage.axaml.cs index 94891a1c2..9ad522fbd 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugPage.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugPage.axaml.cs @@ -1,10 +1,11 @@ using Avalonia.Controls; using Avalonia.Markup.Xaml; +using Avalonia.ReactiveUI; using System.Application.UI.ViewModels; namespace System.Application.UI.Views.Pages { - public class DebugPage : UserControl + public class DebugPage : ReactiveUserControl { public DebugPage() { diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugWebViewPage.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugWebViewPage.axaml.cs index 95b3fa0af..efba3784d 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugWebViewPage.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/DebugWebViewPage.axaml.cs @@ -2,12 +2,13 @@ using Avalonia; using Avalonia.Controls; using Avalonia.LogicalTree; using Avalonia.Markup.Xaml; +using Avalonia.ReactiveUI; using CefNet.Avalonia; using System.Application.UI.Views.Controls; namespace System.Application.UI.Views.Pages { - public class DebugWebViewPage : UserControl, IDisposable + public class DebugWebViewPage : ReactiveUserControl, IDisposable { readonly WebView3 webView; readonly TextBox urlTextBox; diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/StartPage.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/StartPage.axaml.cs index 4204ca89c..4282d1ffb 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/StartPage.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/StartPage.axaml.cs @@ -1,10 +1,11 @@ using Avalonia.Controls; using Avalonia.Markup.Xaml; +using Avalonia.ReactiveUI; using System.Application.UI.ViewModels; namespace System.Application.UI.Views.Pages { - public class StartPage : UserControl + public class StartPage : ReactiveUserControl { public StartPage() { diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml.cs index 7c4c92a98..3c42f5894 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml.cs @@ -1,10 +1,11 @@ using Avalonia.Controls; using Avalonia.Markup.Xaml; +using Avalonia.ReactiveUI; using System.Application.UI.ViewModels; namespace System.Application.UI.Views.Pages { - public class SteamAccountPage : UserControl + public class SteamAccountPage : ReactiveUserControl { public SteamAccountPage() { diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/FluentWindow.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/FluentWindow.cs index 9c271c8ae..87b12487a 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/FluentWindow.cs +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/FluentWindow.cs @@ -180,7 +180,7 @@ namespace Avalonia.Controls } protected bool _isOpenWindow; - private void FluentWindow_Opened(object? sender, EventArgs e) + protected virtual void FluentWindow_Opened(object? sender, EventArgs e) { _isOpenWindow = true; if (this.DataContext is WindowViewModel vm) diff --git a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs index 5ff7cf278..11fa3b857 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs @@ -86,8 +86,10 @@ namespace System.Application.Services } } - private DateTime _AccelerateTime; - public DateTime AccelerateTime + private DateTimeOffset _StartAccelerateTime; + + private DateTimeOffset _AccelerateTime; + public DateTimeOffset AccelerateTime { get => _AccelerateTime; set @@ -100,6 +102,7 @@ namespace System.Application.Services } } + public bool IsEnableScript { get => ProxySettings.IsEnableScript.Value; @@ -224,7 +227,8 @@ namespace System.Application.Services } } } - StartTiming(); + _StartAccelerateTime = DateTimeOffset.Now; + StartTimer(); Toast.Show(AppResources.CommunityFix_StartProxySuccess); } else @@ -235,6 +239,7 @@ namespace System.Application.Services else { httpProxyService.StopProxy(); + StopTimer(); void OnStopRemoveHostsByTag() { var needClear = IHostsFileService.Instance.ContainsHostsByTag(); @@ -416,18 +421,21 @@ namespace System.Application.Services } } - public void StartTiming() + private Timer timer; + + public void StartTimer() { - AccelerateTime = new(); - Task.Run(() => + AccelerateTime = new DateTimeOffset().Add((DateTimeOffset.Now - _StartAccelerateTime)); + timer = new Timer((state) => { Thread.CurrentThread.IsBackground = true; - while (ProxyStatus) - { - AccelerateTime = AccelerateTime.AddSeconds(1); - Thread.Sleep(1000); - } - }); + AccelerateTime = AccelerateTime.AddSeconds(1); + }, nameof(AccelerateTime), 1000, 1000); + } + + public void StopTimer() + { + timer.Dispose(); } public static void OnExitRestoreHosts() diff --git a/src/ST.Client.Desktop/UI/ViewModels/Base/TabItemViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Base/TabItemViewModel.cs index 81557f79e..de719e029 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Base/TabItemViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Base/TabItemViewModel.cs @@ -70,7 +70,7 @@ namespace System.Application.UI.ViewModels }); } - internal async virtual void Initialize() + public async virtual void Initialize() { await Task.CompletedTask; } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs b/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs index 82eddf666..d8cdba672 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs @@ -58,7 +58,7 @@ namespace System.Application.UI.ViewModels } protected bool IsFirstActivation = true; - internal async virtual void Activation() + public async virtual void Activation() { if (IsFirstActivation) { @@ -67,7 +67,7 @@ namespace System.Application.UI.ViewModels await Task.CompletedTask; } - internal async virtual void Deactivation() + public async virtual void Deactivation() { await Task.CompletedTask; } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs index a859a630d..df5567711 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs @@ -90,9 +90,27 @@ namespace System.Application.UI.ViewModels AutoRunProxy?.CheckmarkChange(ProxySettings.ProgramStartupRunProxy.Value); } + public override void Activation() + { + if (ProxyService.Current.ProxyStatus) + { + ProxyService.Current.StartTimer(); + } + base.Activation(); + } - internal async override void Initialize() + public override void Deactivation() + { + if (ProxyService.Current.ProxyStatus) + { + ProxyService.Current.StopTimer(); + } + + base.Deactivation(); + } + + public async override void Initialize() { await Task.CompletedTask; } diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs index c4e34e04a..d5db9cbbe 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs @@ -150,7 +150,7 @@ namespace System.Application.UI.ViewModels public ReactiveCommand HideAppCommand { get; } public ReactiveCommand IdleAppCommand { get; } - internal override void Activation() + public override void Activation() { if (IsFirstActivation) { diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs index 07914669c..54394872a 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/LocalAuthPageViewModel.cs @@ -101,7 +101,7 @@ namespace System.Application.UI.ViewModels public ReactiveCommand ExportAuthCommand { get; } - internal async override void Activation() + public async override void Activation() { SourceAuthCount = await AuthService.Current.GetRealAuthenticatorCount(); //if (IsFirstActivation) diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs index 122150c52..1b7aec30f 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/ProxyScriptManagePageViewModel.cs @@ -23,7 +23,7 @@ namespace System.Application.UI.ViewModels protected set { throw new NotImplementedException(); } } - internal override void Activation() + public override void Activation() { if (IsFirstActivation) if (ProxySettings.IsAutoCheckScriptUpdate) diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs index c36b605ce..c14924adb 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs @@ -84,7 +84,7 @@ namespace System.Application.UI.ViewModels public bool IsUserEmpty => !SteamUsers.Any_Nullable(); - internal async override void Initialize() + public async override void Initialize() { var list = steamService.GetRememberUserList(); diff --git a/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs b/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs index c6ff36caa..fdc25c5f1 100644 --- a/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs @@ -1,11 +1,17 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; +using System.Threading.Tasks; +using ArchiSteamFarm.Core; +using ArchiSteamFarm.Steam; namespace System.Application.Services.Implementation { public class ArchiSteamFarmServiceImpl : IArchiSteamFarmService { + public Func>? GetConsoleWirteFunc { get; set; } + public async void Start(string[]? args = null) { try @@ -17,5 +23,49 @@ namespace System.Application.Services.Implementation Toast.Show(ex.Message); } } + + /// + /// 执行asf指令 + /// + /// + public async Task ExecuteCommand(string command) + { + Bot? targetBot = Bot.Bots?.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault(); + + if (targetBot == null) + { + //Console.WriteLine(@"<< " + Strings.ErrorNoBotsDefined); + + return null; + } + + //Console.WriteLine(@"<> " + Strings.Executing); + + ulong steamOwnerID = ASF.GlobalConfig?.SteamOwnerID ?? ArchiSteamFarm.Storage.GlobalConfig.DefaultSteamOwnerID; + + string? response = await targetBot.Commands.Response(steamOwnerID, command!).ConfigureAwait(false); + + return response; + } + + /// + /// 获取bot只读集合 + /// + /// + public IReadOnlyDictionary? GetReadOnlyAllBots() + { + return Bot.BotsReadOnly; + } + + + /// + /// 设置并保存bot + /// + /// + public void SetBot(string botName) + { + + } + } }