From fff5c293c817232fbf1a302caf54ad5cfde79f8d Mon Sep 17 00:00:00 2001 From: RMBGAME Date: Sun, 18 Dec 2022 21:03:21 +0800 Subject: [PATCH] task command --- .../UI/Views/Pages/SteamAccountPage.axaml | 10 +++--- .../Pages/SteamAccountPageViewModel.cs | 31 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml index a5690be8816..3c6d2115e70 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml @@ -94,13 +94,13 @@ - + @@ -343,7 +343,7 @@ Mode=OneWay, Source={x:Static resx:R.Current}}" Classes="flatbutton" - Command="{ReflectionBinding #u.DataContext.OfflineModeButton_Click}" + Command="{ReflectionBinding #u.DataContext.OfflineModeButton_ClickCommand}" CommandParameter="{Binding}" Cursor="Hand"> @@ -359,7 +359,7 @@ MaxWidth="250" HorizontalAlignment="Stretch" Classes="flatbutton" - Command="{ReflectionBinding #u.DataContext.SteamId_Click}" + Command="{ReflectionBinding #u.DataContext.SteamId_ClickCommand}" CommandParameter="{Binding}" Cursor="Hand"> diff --git a/src/ST.Client/UI/ViewModels/Pages/SteamAccountPageViewModel.cs b/src/ST.Client/UI/ViewModels/Pages/SteamAccountPageViewModel.cs index 9bd61ecbbe2..eb5216aa4e9 100644 --- a/src/ST.Client/UI/ViewModels/Pages/SteamAccountPageViewModel.cs +++ b/src/ST.Client/UI/ViewModels/Pages/SteamAccountPageViewModel.cs @@ -29,9 +29,12 @@ public SteamAccountPageViewModel() { this.WhenAnyValue(x => x.SteamUsers) .Subscribe(s => this.RaisePropertyChanged(nameof(IsUserEmpty))); - LoginAccountCommand = ReactiveCommand.Create(LoginNewSteamAccount); + LoginAccountCommand = ReactiveCommand.CreateFromTask(LoginNewSteamAccount); RefreshCommand = ReactiveCommand.Create(SteamConnectService.Current.RefreshSteamUsers); + SteamId_ClickCommand = ReactiveCommand.CreateFromTask(SteamId_Click); + OfflineModeButton_ClickCommand = ReactiveCommand.CreateFromTask(OfflineModeButton_Click); + ShareManageCommand = ReactiveCommand.Create(OpenShareManageWindow); OpenBrowserCommand = ReactiveCommand.CreateFromTask(x => Browser2.OpenAsync(x)); @@ -61,6 +64,10 @@ public SteamAccountPageViewModel() public ReactiveCommand LoginAccountCommand { get; } + public ReactiveCommand SteamId_ClickCommand { get; } + + public ReactiveCommand OfflineModeButton_ClickCommand { get; } + public ReactiveCommand RefreshCommand { get; } public ReactiveCommand ShareManageCommand { get; } @@ -99,9 +106,9 @@ public override void Initialize() menus.Add(new MenuItemCustomName(title, AppResources.UserChange_BtnTootlip) { - Command = ReactiveCommand.Create(() => + Command = ReactiveCommand.CreateFromTask(async () => { - SteamId_Click(user); + await ReStartSteamByUser(user); INotificationService.Instance.Notify(string.Format(AppResources.UserChange_ChangeUserTip, title), NotificationType.Message); }), @@ -144,10 +151,7 @@ private async Task ReStartSteamByUser(SteamUser? user = null) steamService.SetCurrentUser(string.Empty); } - await Task.Run(() => - { - steamService.StartSteamWithParameter(); - }); + await Task.Run(steamService.StartSteamWithParameter); } public async void DeleteUserButton_Click(SteamUser user) @@ -178,15 +182,14 @@ public void OpenUserDataFolder(SteamUser user) IPlatformService.Instance.OpenFolder(Path.Combine(ISteamService.Instance.SteamDirPath, user.UserdataPath)); } - public void LoginNewSteamAccount() + public async Task LoginNewSteamAccount() { - var result = MessageBox.ShowAsync(AppResources.UserChange_LoginNewAccountTip, button: MessageBox.Button.OKCancel).ContinueWith(s => + var result = await MessageBox.ShowAsync(AppResources.UserChange_LoginNewAccountTip, button: MessageBox.Button.OKCancel); + + if (result == MessageBox.Result.OK) { - if (s.Result == MessageBox.Result.OK) - { - ReStartSteamByUser(); - } - }); + await ReStartSteamByUser(); + } } public async void EditRemarkAsync(SteamUser user)