Skip to content

Commit

Permalink
改进加速计时逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Jun 29, 2021
1 parent ebfcb97 commit 7d9607b
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 27 deletions.
2 changes: 1 addition & 1 deletion references/ArchiSteamFarm
16 changes: 16 additions & 0 deletions src/ST.Client.Desktop.Avalonia.App/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,27 @@ protected override void OnClosing(CancelEventArgs e)
_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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
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<CommunityProxyPageViewModel>
{
//private ListBox _items;
//private IScrollable _scroll;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DebugPageViewModel>
{
public DebugPage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
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<DebugWebViewPage>, IDisposable
{
readonly WebView3 webView;
readonly TextBox urlTextBox;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StartPageViewModel>
{
public StartPage()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SteamAccountPageViewModel>
{
public SteamAccountPage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void FluentWindow_PositionChanged(object? sender, PixelPointEventArgs e)
}

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)
Expand Down
32 changes: 20 additions & 12 deletions src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ public IReadOnlyCollection<ScriptDTO>? EnableProxyScripts
}
}

private DateTime _AccelerateTime;
public DateTime AccelerateTime
private DateTimeOffset _StartAccelerateTime;

private DateTimeOffset _AccelerateTime;
public DateTimeOffset AccelerateTime
{
get => _AccelerateTime;
set
Expand All @@ -100,6 +102,7 @@ public DateTime AccelerateTime
}
}


public bool IsEnableScript
{
get => ProxySettings.IsEnableScript.Value;
Expand Down Expand Up @@ -224,7 +227,8 @@ public bool ProxyStatus
}
}
}
StartTiming();
_StartAccelerateTime = DateTimeOffset.Now;
StartTimer();
Toast.Show(AppResources.CommunityFix_StartProxySuccess);
}
else
Expand All @@ -235,6 +239,7 @@ public bool ProxyStatus
else
{
httpProxyService.StopProxy();
StopTimer();
void OnStopRemoveHostsByTag()
{
var needClear = IHostsFileService.Instance.ContainsHostsByTag();
Expand Down Expand Up @@ -416,18 +421,21 @@ public async void BasicsInfo()
}
}

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected TabItemViewModel()
});
}

internal async virtual void Initialize()
public async virtual void Initialize()
{
await Task.CompletedTask;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ST.Client.Desktop/UI/ViewModels/Base/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected virtual void Dispose(bool disposing)
}

protected bool IsFirstActivation = true;
internal async virtual void Activation()
public async virtual void Activation()
{
if (IsFirstActivation)
{
Expand All @@ -67,7 +67,7 @@ internal async virtual void Activation()
await Task.CompletedTask;
}

internal async virtual void Deactivation()
public async virtual void Deactivation()
{
await Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,27 @@ public CommunityProxyPageViewModel()

AutoRunProxy?.CheckmarkChange(ProxySettings.ProgramStartupRunProxy.Value);
}
public override void Activation()
{
if (ProxyService.Current.ProxyStatus)
{
ProxyService.Current.StartTimer();
}

base.Activation();
}

public override void Deactivation()
{
if (ProxyService.Current.ProxyStatus)
{
ProxyService.Current.StopTimer();
}

base.Deactivation();
}

internal async override void Initialize()
public async override void Initialize()
{
await Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void OpenIdleAppWindow()
public ReactiveCommand<Unit, Unit> HideAppCommand { get; }
public ReactiveCommand<Unit, Unit> IdleAppCommand { get; }

internal override void Activation()
public override void Activation()
{
if (IsFirstActivation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override string Name

public ReactiveCommand<Unit, Unit> ExportAuthCommand { get; }

internal async override void Activation()
public async override void Activation()
{
SourceAuthCount = await AuthService.Current.GetRealAuthenticatorCount();
//if (IsFirstActivation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override string Name
protected set { throw new NotImplementedException(); }
}

internal override void Activation()
public override void Activation()
{
if (IsFirstActivation)
if (ProxySettings.IsAutoCheckScriptUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void OpenShareManageWindow()

public bool IsUserEmpty => !SteamUsers.Any_Nullable();

internal async override void Initialize()
public async override void Initialize()
{
var list = steamService.GetRememberUserList();

Expand Down
50 changes: 50 additions & 0 deletions src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs
Original file line number Diff line number Diff line change
@@ -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<string, Task<string?>>? GetConsoleWirteFunc { get; set; }

public async void Start(string[]? args = null)
{
try
Expand All @@ -17,5 +23,49 @@ public async void Start(string[]? args = null)
Toast.Show(ex.Message);
}
}

/// <summary>
/// 执行asf指令
/// </summary>
/// <param name="command"></param>
public async Task<string?> 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;
}

/// <summary>
/// 获取bot只读集合
/// </summary>
/// <returns></returns>
public IReadOnlyDictionary<string, Bot>? GetReadOnlyAllBots()
{
return Bot.BotsReadOnly;
}


/// <summary>
/// 设置并保存bot
/// </summary>
/// <returns></returns>
public void SetBot(string botName)
{

}

}
}

0 comments on commit 7d9607b

Please sign in to comment.