Skip to content

Commit

Permalink
Added Cancellation to "Login Loop" (#207)
Browse files Browse the repository at this point in the history
* Added Cancellation to "Login Loop"

* Sonar angry
  • Loading branch information
Foxlider authored Oct 12, 2024
1 parent fd5eff7 commit cf1c353
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions FASTER/ViewModel/SteamUpdaterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace FASTER.ViewModel
{
public sealed class SteamUpdaterViewModel : INotifyPropertyChanged
public sealed class SteamUpdaterViewModel : INotifyPropertyChanged, IDisposable
{
public SteamUpdaterViewModel()
{
Expand Down Expand Up @@ -510,6 +510,8 @@ public async Task<int> RunModsUpdater(ObservableCollection<ArmaMod> mods)

internal async Task<bool> SteamLogin()
{
if (tokenSource.IsCancellationRequested)
tokenSource = new CancellationTokenSource();
IsLoggingIn = true;
var path = Path.Combine(Path.GetDirectoryName(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath) ?? string.Empty, "sentries");

Expand All @@ -530,7 +532,7 @@ internal async Task<bool> SteamLogin()
Parameters.Output += $"\nConnecting to Steam as {(_steamCredentials.IsAnonymous ? "anonymous" : _steamCredentials.Username)}";
SteamClient.MaximumLogonAttempts = 5;
try
{ await SteamClient.ConnectAsync(); }
{ await SteamClient.ConnectAsync(tokenSource.Token); }
catch (SteamClientAlreadyRunningException)
{
Parameters.Output += $"\nClient already logged in.";
Expand Down Expand Up @@ -746,6 +748,11 @@ private void RaisePropertyChanged(string property)
if (PropertyChanged == null) return;
PropertyChanged(this, new PropertyChangedEventArgs(property));
}

public void Dispose()
{
tokenSource.Dispose();
}
}

public static class UpdateState
Expand Down

0 comments on commit cf1c353

Please sign in to comment.