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
+1 -1
View File
@@ -15,7 +15,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+5 -21
View File
@@ -7,7 +7,7 @@
xmlns:vm="clr-namespace:ARAMUtility.ViewModel" xmlns:vm="clr-namespace:ARAMUtility.ViewModel"
mc:Ignorable="d" mc:Ignorable="d"
Title="{Binding Title}" Title="{Binding Title}"
Height="480" Height="500"
Width="700" Width="700"
Background="#0a1a2a" Background="#0a1a2a"
Topmost="True" Topmost="True"
@@ -67,27 +67,11 @@
<Separator /> <Separator />
<MenuItem Header="Quit" Command="{Binding QuitCommand}" /> <MenuItem Header="Quit" Command="{Binding QuitCommand}" />
</MenuItem> </MenuItem>
<MenuItem Header="{Binding ConnectionStatus}" Command="{Binding ConnectCommand}" /> <MenuItem Header="Reconnect" Command="{Binding ConnectCommand}" Visibility="{Binding ReconnectButtonVisibility, Mode=OneWay}" />
<MenuItem Header="Update ARAM">
<StackPanel Orientation="Vertical">
<ComboBox ItemsSource="{Binding .}"
SelectedIndex="0"
SelectedItem="{Binding .}"
/>
<ItemsControl ItemsSource="{Binding .}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding .}" />
<TextBox Text="{Binding .}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Content="Save" />
</StackPanel>
</MenuItem>
</Menu> </Menu>
<StatusBar DockPanel.Dock="Bottom">
<StatusBarItem Content="{Binding Status}" />
</StatusBar>
<Viewbox Stretch="Uniform" StretchDirection="DownOnly"> <Viewbox Stretch="Uniform" StretchDirection="DownOnly">
<Grid Margin="10"> <Grid Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
+4
View File
@@ -11,6 +11,10 @@ public partial class MainWindow : Window
{ {
InitializeComponent(); InitializeComponent();
#if DEBUG
Topmost = false;
#endif
if (DataContext is MainViewModel viewModel) if (DataContext is MainViewModel viewModel)
{ {
Loaded += viewModel.OnInit; Loaded += viewModel.OnInit;
+27 -8
View File
@@ -18,6 +18,13 @@ public partial class MainViewModel : ObservableObject, IDisposable
private const int TEAM_CHAMPIONS_MAX = 5; private const int TEAM_CHAMPIONS_MAX = 5;
private const int BENCH_CHAMPIONS_MAX = 10; private const int BENCH_CHAMPIONS_MAX = 10;
public enum ConnectionStatus
{
Disconnected,
Connecting,
Connected,
}
private bool _isDisposed; private bool _isDisposed;
private readonly Lock _syncRoot = new(); private readonly Lock _syncRoot = new();
private readonly SemaphoreSlim _championUpdateSemaphore = new(1, 1); private readonly SemaphoreSlim _championUpdateSemaphore = new(1, 1);
@@ -36,8 +43,9 @@ public partial class MainViewModel : ObservableObject, IDisposable
[ObservableProperty] [ObservableProperty]
public partial bool IsDisconnected { get; private set; } = false; public partial bool IsDisconnected { get; private set; } = false;
[ObservableProperty] [ObservableProperty, NotifyPropertyChangedFor(nameof(ReconnectButtonVisibility))]
public partial string ConnectionStatus { get; private set; } = "Not connected."; public partial ConnectionStatus Status { get; private set; } = ConnectionStatus.Disconnected;
public Visibility ReconnectButtonVisibility => Status == ConnectionStatus.Disconnected ? Visibility.Visible : Visibility.Collapsed;
[ObservableProperty] [ObservableProperty]
public partial bool AutoAccept { get; set; } = true; public partial bool AutoAccept { get; set; } = true;
@@ -51,9 +59,9 @@ public partial class MainViewModel : ObservableObject, IDisposable
public MainViewModel() public MainViewModel()
{ {
_lcuWebsocket.Connecting += (_, _) => UpdateConnectionStatus(false, "Connecting ..."); _lcuWebsocket.Connecting += (_, _) => UpdateConnectionStatus(false, ConnectionStatus.Connecting);
_lcuWebsocket.Connected += (_, _) => UpdateConnectionStatus(false, "Connected"); _lcuWebsocket.Connected += (_, _) => UpdateConnectionStatus(false, ConnectionStatus.Connected);
_lcuWebsocket.Disconnected += (_, _) => UpdateConnectionStatus(true, "Reconnect?"); _lcuWebsocket.Disconnected += (_, _) => UpdateConnectionStatus(true, ConnectionStatus.Disconnected);
_lcuWebsocket.LcuApiEvent += OnLcuApiEvent; _lcuWebsocket.LcuApiEvent += OnLcuApiEvent;
#if DEBUG #if DEBUG
@@ -75,16 +83,27 @@ public partial class MainViewModel : ObservableObject, IDisposable
{ {
_allChampions = championDictionary; _allChampions = championDictionary;
} }
try
{
await UpdateNeedChampionIdsAsync(); await UpdateNeedChampionIdsAsync();
}
catch (InvalidOperationException)
{
UpdateConnectionStatus(false, ConnectionStatus.Disconnected);
return;
}
finally
{
await FillChampionLists(); await FillChampionLists();
} }
}
private void UpdateConnectionStatus(bool isConnected, string statusMessage) private void UpdateConnectionStatus(bool isConnected, ConnectionStatus status)
{ {
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
IsDisconnected = isConnected; 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() private async Task Connect()
{ {
if (_lcuWebsocketTask is null || _lcuWebsocketTask.IsCompleted) if (_lcuWebsocketTask is null || _lcuWebsocketTask.IsCompleted)
+5 -2
View File
@@ -51,10 +51,13 @@ public class LcuWebsocket : IDisposable
} }
catch catch
{ {
await Task.Delay(TimeSpan.FromMilliseconds(500));
Disconnected?.Invoke(this, EventArgs.Empty);
return; return;
} }
if (!ProcessFinder.IsPortOpen(ProcessInfo)) if (!ProcessFinder.IsPortOpen(ProcessInfo))
{ {
Disconnected?.Invoke(this, EventArgs.Empty);
throw new InvalidOperationException("Failed to connect to LCUx process port."); throw new InvalidOperationException("Failed to connect to LCUx process port.");
} }
@@ -67,8 +70,6 @@ public class LcuWebsocket : IDisposable
{ {
await _socket.ConnectAsync(uri, CancellationToken.None); await _socket.ConnectAsync(uri, CancellationToken.None);
Connected?.Invoke(this, EventArgs.Empty);
foreach (string eventName in SUBSCRIBE_EVENTS) foreach (string eventName in SUBSCRIBE_EVENTS)
{ {
string message = $"[{OPCODE_SUBSCRIBE}, \"{eventName}\"]"; string message = $"[{OPCODE_SUBSCRIBE}, \"{eventName}\"]";
@@ -77,6 +78,8 @@ public class LcuWebsocket : IDisposable
await _socket.SendAsync(memory, WebSocketMessageType.Text, true, CancellationToken.None); await _socket.SendAsync(memory, WebSocketMessageType.Text, true, CancellationToken.None);
} }
Connected?.Invoke(this, EventArgs.Empty);
while (_socket.State is WebSocketState.Open) while (_socket.State is WebSocketState.Open)
{ {
try try
+1 -2
View File
@@ -7,8 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CliWrap" Version="3.10.0" /> <PackageReference Include="CliWrap" Version="3.10.1" />
<PackageReference Include="MoonSharp" Version="2.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>