Skip to content

Commit

Permalink
🚧 Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Oct 13, 2023
1 parent 0ed0416 commit a6a45e5
Show file tree
Hide file tree
Showing 10 changed files with 373 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="UI\Views\Pages\IdleCardPage.axaml.cs">
<DependentUpon>IdleCardPage.axaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,49 @@ public override void Activation()
{
base.Activation();

IdleRunStartOrStop_Click();
//IdleRunStartOrStop_Click();
}

/// <summary>
/// 启动或停止挂卡
/// </summary>
public async void IdleRunStartOrStop_Click()
{
if (SteamConnectService.Current.IsConnectToSteam) // 是否登录 Steam 客户端
if (!SteamTool.IsRunningSteamProcess)
{
if (!await LoginSteam()) // 登录 Steam Web
return;
await MessageBox.ShowAsync(Strings.Idle_SteamNotRuning, button: MessageBox.Button.OK);
return;
}

if (SteamTool.IsRunningSteamProcess)
{
if (!RunLoaingState)
{
RunLoaingState = true;
RunState = !RunState;
if (!SteamConnectService.Current.IsConnectToSteam) // 是否登录 Steam 客户端
{
await MessageBox.ShowAsync(Strings.Idle_NeedLoginSteam, button: MessageBox.Button.OK);
return;
}

if (RunState)
{
await SteamConnectService.Current.RefreshGamesListAsync();
await ReadyToGoIdle();
}
else
{
StopIdle();
RunOrStopAutoNext(false);
}
RunLoaingState = false;
Toast.Show(ToastIcon.Success, Strings.Idle_OperationSuccess);
}
else
Toast.Show(ToastIcon.Warning, Strings.Idle_LoaingTips);
if (!await LoginSteam()) // 登录 Steam Web
return;

if (!RunLoaingState)
{
RunLoaingState = true;
RunState = !RunState;

if (RunState)
{
await SteamConnectService.Current.RefreshGamesListAsync();
await ReadyToGoIdle();
}
else
await MessageBox.ShowAsync(Strings.Idle_SteamNotRuning, button: MessageBox.Button.OK);
{
StopIdle();
RunOrStopAutoNext(false);
}
RunLoaingState = false;
Toast.Show(ToastIcon.Success, Strings.Idle_OperationSuccess);
}
else
await MessageBox.ShowAsync(Strings.Idle_NeedLoginSteam, button: MessageBox.Button.OK);
Toast.Show(ToastIcon.Warning, Strings.Idle_LoaingTips);
}

/// <summary>
Expand Down Expand Up @@ -117,11 +119,11 @@ private async Task<bool> LoginSteam()
{
if (!SteamLoginState.Success)
{
var vm = new IdleSteamLoginViewModel(ref SteamLoginState);
var result = await IWindowManager.Instance.ShowTaskDialogAsync(vm, Strings.Steam_Login,
pageContent: new IdleSteamLogin(), okButtonText: Strings.Confirm, isCancelButton: true, disableScroll: true);
var vm = new IdleSteamLoginPageViewModel(ref SteamLoginState);
await IWindowManager.Instance.ShowTaskDialogAsync(vm, Strings.Steam_Login,
pageContent: new IdleSteamLoginPage(), okButtonText: Strings.Confirm, isOkButton: false);

return result;
return SteamLoginState.Success;
}
return true;
}
Expand Down Expand Up @@ -425,4 +427,4 @@ private void IdleComplete()
}
#endregion

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using BD.SteamClient.Models;
using BD.SteamClient.Services;

namespace BD.WTTS.UI.ViewModels;

public sealed partial class IdleSteamLoginPageViewModel : WindowViewModel
{
readonly ISteamAccountService Account = Ioc.Get<ISteamAccountService>();

public SteamLoginState SteamLoginState { get; set; }

public IdleSteamLoginPageViewModel(ref SteamLoginState steamLoginState)
{
SteamLoginState = steamLoginState;
this.Login = ReactiveCommand.Create(SteamLogin);
}

private async void SteamLogin()
{
if (!IsLoading)
{
IsLoading = true;

if (SteamLoginState.SteamId == 0)
{
SteamLoginState.Username = UserNameText;
SteamLoginState.Password = PasswordText;
}
else
{
this.TwofactorCode ??= string.Empty;

if (SteamLoginState.Requires2FA)
{
SteamLoginState.TwofactorCode = this.TwofactorCode;
}
else if (SteamLoginState.RequiresEmailAuth)
{
SteamLoginState.EmailCode = this.TwofactorCode;
}
}

await Account.DoLoginV2Async(SteamLoginState);

Requires2FA = SteamLoginState.Requires2FA;
RequiresEmailAuth = SteamLoginState.RequiresEmailAuth;

if (SteamLoginState.Success)
{
if (RemenberLogin)
{

}
Toast.Show(ToastIcon.Success, Strings.Success_.Format(Strings.User_Login));
IsLoading = false;
Close?.Invoke();
}
else if (SteamLoginState.Message != null)
{
IsLoading = false;
Toast.Show(ToastIcon.Warning, SteamLoginState.Message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace BD.WTTS.UI.ViewModels;

public sealed partial class IdleSteamLoginViewModel
public sealed partial class IdleSteamLoginPageViewModel
{
/// <summary>
/// 用户名
Expand All @@ -20,12 +20,6 @@ public sealed partial class IdleSteamLoginViewModel
[Reactive]
public string? PasswordText { get; set; }

/// <summary>
/// 邮箱验证码
/// </summary>
[Reactive]
public string? EmailAuthText { get; set; }

/// <summary>
/// 2FA 验证码
/// </summary>
Expand All @@ -44,5 +38,14 @@ public sealed partial class IdleSteamLoginViewModel
[Reactive]
public bool RequiresEmailAuth { get; set; }

/// <summary>
/// 是否记住登录状态
/// </summary>
[Reactive]
public bool RemenberLogin { get; set; } = true;

[Reactive]
public bool IsLoading { get; set; }

public ICommand Login { get; set; }
}

This file was deleted.

Loading

0 comments on commit a6a45e5

Please sign in to comment.