Skip to content

Commit

Permalink
task command
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Dec 18, 2022
1 parent e9136e7 commit fff5c29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@
<Border.ContextFlyout>
<MenuFlyout>
<MenuItem
Command="{ReflectionBinding #u.DataContext.SteamId_Click}"
Command="{ReflectionBinding #u.DataContext.SteamId_ClickCommand}"
CommandParameter="{Binding}"
Header="{ReflectionBinding Path=Res.UserChange_BtnText,
Mode=OneWay,
Source={x:Static resx:R.Current}}" />
<MenuItem
Command="{ReflectionBinding #u.DataContext.OfflineModeButton_Click}"
Command="{ReflectionBinding #u.DataContext.OfflineModeButton_ClickCommand}"
CommandParameter="{Binding}"
Header="{ReflectionBinding Path=Res.UserChange_OfflineBtn,
Mode=OneWay,
Expand Down Expand Up @@ -231,7 +231,7 @@
Source={x:Static resx:R.Current}}">
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="Tapped" SourceObject="{ReflectionBinding #nickname}">
<ia:InvokeCommandAction Command="{ReflectionBinding #u.DataContext.SteamId_Click}" CommandParameter="{Binding}" />
<ia:InvokeCommandAction Command="{ReflectionBinding #u.DataContext.SteamId_ClickCommand}" CommandParameter="{Binding}" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
</controls:ScrollingTextBlock>
Expand Down Expand Up @@ -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">
<controls:ScrollingTextBlock Text="{ReflectionBinding Path=Res.UserChange_OfflineBtn, Mode=OneWay, Source={x:Static resx:R.Current}}" />
Expand All @@ -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">
<controls:ScrollingTextBlock Text="{ReflectionBinding Path=Res.UserChange_BtnText, Mode=OneWay, Source={x:Static resx:R.Current}}" />
Expand Down
31 changes: 17 additions & 14 deletions src/ST.Client/UI/ViewModels/Pages/SteamAccountPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SteamUser>(SteamId_Click);
OfflineModeButton_ClickCommand = ReactiveCommand.CreateFromTask<SteamUser>(OfflineModeButton_Click);

ShareManageCommand = ReactiveCommand.Create(OpenShareManageWindow);
OpenBrowserCommand = ReactiveCommand.CreateFromTask<string>(x => Browser2.OpenAsync(x));

Expand Down Expand Up @@ -61,6 +64,10 @@ public SteamAccountPageViewModel()

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

public ReactiveCommand<SteamUser, Unit> SteamId_ClickCommand { get; }

public ReactiveCommand<SteamUser, Unit> OfflineModeButton_ClickCommand { get; }

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

public ReactiveCommand<Unit, Unit> ShareManageCommand { get; }
Expand Down Expand Up @@ -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);
}),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fff5c29

Please sign in to comment.