Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable and Disable the Login and Play buttons on Character Summary view dependent on EFT's running state. #285

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions SIT.Manager/ViewModels/Play/CharacterSummaryViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
Expand Down Expand Up @@ -43,6 +44,9 @@
[ObservableProperty]
private bool _requireLogin = true;

[ObservableProperty]
public bool _canLaunch = true;

public IAsyncRelayCommand PlayCommand { get; }

public IAsyncRelayCommand LogoutCommand { get; }
Expand Down Expand Up @@ -90,6 +94,11 @@
Task.Run(SetSideImage);

PlayCommand = new AsyncRelayCommand(Play);

// In an ideal world we would use OnActivated and OnDeactivated - which are implemented from IActivatableViewModel in the Avalonia.ReactiveUI package.
// However, this would also require changes in the CharacterSummaryView class - for not this implementation, while crude, does suffice.
// It may be worth implementing Avalonia.ReactiveUI.IActivatableViewModel at a later date for all pages as part of a larger refactor.
_tarkovClientService.RunningStateChanged += TarkovClient_RunningStateChanged;
Comment on lines +98 to +101
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnActivated & OnDeactivated do exist, they are just there as overrides

LogoutCommand = new AsyncRelayCommand(Logout);
}

Expand Down Expand Up @@ -165,7 +174,27 @@
}
}

private void TarkovClient_RunningStateChanged(object? sender, RunningState runningState)
{
Dispatcher.UIThread.Invoke(() =>
{
switch (runningState)
{
case RunningState.Starting:
case RunningState.Running:
CanLaunch = false;

break;
case RunningState.NotRunning:
case RunningState.StoppedUnexpectedly:
CanLaunch = true;

break;
}
});
}

private async Task Logout()

Check warning on line 197 in SIT.Manager/ViewModels/Play/CharacterSummaryViewModel.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 197 in SIT.Manager/ViewModels/Play/CharacterSummaryViewModel.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 197 in SIT.Manager/ViewModels/Play/CharacterSummaryViewModel.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 197 in SIT.Manager/ViewModels/Play/CharacterSummaryViewModel.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (character != null)
{
Expand Down
4 changes: 2 additions & 2 deletions SIT.Manager/Views/Play/CharacterSummaryView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
</StackPanel>

<Button Grid.Column="2"
Command="{Binding PlayCommand}">
<Panel>
Command="{Binding PlayCommand}" IsEnabled="{Binding CanLaunch}">
<Panel>
<TextBlock IsVisible="{Binding !RequireLogin}"
Text="{DynamicResource CharacterSummaryViewPlayButtonText}"/>
<TextBlock IsVisible="{Binding RequireLogin}"
Expand Down
Loading