moved connection state to status bar

This commit is contained in:
2026-04-29 04:05:16 +02:00
parent b6a4903847
commit 06d5113711
6 changed files with 48 additions and 39 deletions
+32 -13
View File
@@ -18,6 +18,13 @@ public partial class MainViewModel : ObservableObject, IDisposable
private const int TEAM_CHAMPIONS_MAX = 5;
private const int BENCH_CHAMPIONS_MAX = 10;
public enum ConnectionStatus
{
Disconnected,
Connecting,
Connected,
}
private bool _isDisposed;
private readonly Lock _syncRoot = new();
private readonly SemaphoreSlim _championUpdateSemaphore = new(1, 1);
@@ -36,12 +43,13 @@ public partial class MainViewModel : ObservableObject, IDisposable
[ObservableProperty]
public partial bool IsDisconnected { get; private set; } = false;
[ObservableProperty]
public partial string ConnectionStatus { get; private set; } = "Not connected.";
[ObservableProperty, NotifyPropertyChangedFor(nameof(ReconnectButtonVisibility))]
public partial ConnectionStatus Status { get; private set; } = ConnectionStatus.Disconnected;
public Visibility ReconnectButtonVisibility => Status == ConnectionStatus.Disconnected ? Visibility.Visible : Visibility.Collapsed;
[ObservableProperty]
public partial bool AutoAccept { get; set; } = true;
private Dictionary<int, ChampionData> _allChampions = [];
private List<int> _needChampionIds = [];
private readonly APIClient _client = new();
@@ -51,9 +59,9 @@ public partial class MainViewModel : ObservableObject, IDisposable
public MainViewModel()
{
_lcuWebsocket.Connecting += (_, _) => UpdateConnectionStatus(false, "Connecting ...");
_lcuWebsocket.Connected += (_, _) => UpdateConnectionStatus(false, "Connected");
_lcuWebsocket.Disconnected += (_, _) => UpdateConnectionStatus(true, "Reconnect?");
_lcuWebsocket.Connecting += (_, _) => UpdateConnectionStatus(false, ConnectionStatus.Connecting);
_lcuWebsocket.Connected += (_, _) => UpdateConnectionStatus(false, ConnectionStatus.Connected);
_lcuWebsocket.Disconnected += (_, _) => UpdateConnectionStatus(true, ConnectionStatus.Disconnected);
_lcuWebsocket.LcuApiEvent += OnLcuApiEvent;
#if DEBUG
@@ -75,16 +83,27 @@ public partial class MainViewModel : ObservableObject, IDisposable
{
_allChampions = championDictionary;
}
await UpdateNeedChampionIdsAsync();
await FillChampionLists();
try
{
await UpdateNeedChampionIdsAsync();
}
catch (InvalidOperationException)
{
UpdateConnectionStatus(false, ConnectionStatus.Disconnected);
return;
}
finally
{
await FillChampionLists();
}
}
private void UpdateConnectionStatus(bool isConnected, string statusMessage)
private void UpdateConnectionStatus(bool isConnected, ConnectionStatus status)
{
Dispatcher.Invoke(() =>
{
IsDisconnected = isConnected;
ConnectionStatus = statusMessage;
Status = status;
});
}
@@ -191,7 +210,7 @@ public partial class MainViewModel : ObservableObject, IDisposable
}
}
[RelayCommand(AllowConcurrentExecutions = false, CanExecute = nameof(IsDisconnected))]
[RelayCommand(AllowConcurrentExecutions = false)]
private async Task Connect()
{
if (_lcuWebsocketTask is null || _lcuWebsocketTask.IsCompleted)
@@ -219,7 +238,7 @@ public partial class MainViewModel : ObservableObject, IDisposable
await _aramBalanceService.ReloadAsync(force: true);
MessageBox.Show("Reloaded ARAM balance data.", "Info", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
[RelayCommand]
private async Task Quit()
{