diff --git a/ARAMUtility/ARAMUtility.csproj b/ARAMUtility/ARAMUtility.csproj
index 1e0554d..d78c59f 100644
--- a/ARAMUtility/ARAMUtility.csproj
+++ b/ARAMUtility/ARAMUtility.csproj
@@ -15,7 +15,7 @@
-
+
diff --git a/ARAMUtility/View/MainWindow.xaml b/ARAMUtility/View/MainWindow.xaml
index 2b2bfb5..e1d7d6d 100644
--- a/ARAMUtility/View/MainWindow.xaml
+++ b/ARAMUtility/View/MainWindow.xaml
@@ -7,7 +7,7 @@
xmlns:vm="clr-namespace:ARAMUtility.ViewModel"
mc:Ignorable="d"
Title="{Binding Title}"
- Height="480"
+ Height="500"
Width="700"
Background="#0a1a2a"
Topmost="True"
@@ -67,27 +67,11 @@
-
-
+
+
+
+
diff --git a/ARAMUtility/View/MainWindow.xaml.cs b/ARAMUtility/View/MainWindow.xaml.cs
index 4cda70c..5d7580f 100644
--- a/ARAMUtility/View/MainWindow.xaml.cs
+++ b/ARAMUtility/View/MainWindow.xaml.cs
@@ -11,6 +11,10 @@ public partial class MainWindow : Window
{
InitializeComponent();
+#if DEBUG
+ Topmost = false;
+#endif
+
if (DataContext is MainViewModel viewModel)
{
Loaded += viewModel.OnInit;
diff --git a/ARAMUtility/ViewModel/MainViewModel.cs b/ARAMUtility/ViewModel/MainViewModel.cs
index 314593e..b376f05 100644
--- a/ARAMUtility/ViewModel/MainViewModel.cs
+++ b/ARAMUtility/ViewModel/MainViewModel.cs
@@ -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 _allChampions = [];
private List _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()
{
diff --git a/LeagueAPI/LcuWebsocket.cs b/LeagueAPI/LcuWebsocket.cs
index 5e443d8..3eeb612 100644
--- a/LeagueAPI/LcuWebsocket.cs
+++ b/LeagueAPI/LcuWebsocket.cs
@@ -51,10 +51,13 @@ public class LcuWebsocket : IDisposable
}
catch
{
+ await Task.Delay(TimeSpan.FromMilliseconds(500));
+ Disconnected?.Invoke(this, EventArgs.Empty);
return;
}
if (!ProcessFinder.IsPortOpen(ProcessInfo))
{
+ Disconnected?.Invoke(this, EventArgs.Empty);
throw new InvalidOperationException("Failed to connect to LCUx process port.");
}
@@ -67,8 +70,6 @@ public class LcuWebsocket : IDisposable
{
await _socket.ConnectAsync(uri, CancellationToken.None);
- Connected?.Invoke(this, EventArgs.Empty);
-
foreach (string eventName in SUBSCRIBE_EVENTS)
{
string message = $"[{OPCODE_SUBSCRIBE}, \"{eventName}\"]";
@@ -77,6 +78,8 @@ public class LcuWebsocket : IDisposable
await _socket.SendAsync(memory, WebSocketMessageType.Text, true, CancellationToken.None);
}
+ Connected?.Invoke(this, EventArgs.Empty);
+
while (_socket.State is WebSocketState.Open)
{
try
diff --git a/LeagueAPI/LeagueAPI.csproj b/LeagueAPI/LeagueAPI.csproj
index 5303e13..02cb419 100644
--- a/LeagueAPI/LeagueAPI.csproj
+++ b/LeagueAPI/LeagueAPI.csproj
@@ -7,8 +7,7 @@
-
-
+