moved connection state to status bar
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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 @@
|
||||
<Separator />
|
||||
<MenuItem Header="Quit" Command="{Binding QuitCommand}" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="{Binding ConnectionStatus}" Command="{Binding ConnectCommand}" />
|
||||
<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>
|
||||
<MenuItem Header="Reconnect" Command="{Binding ConnectCommand}" Visibility="{Binding ReconnectButtonVisibility, Mode=OneWay}" />
|
||||
</Menu>
|
||||
<StatusBar DockPanel.Dock="Bottom">
|
||||
<StatusBarItem Content="{Binding Status}" />
|
||||
</StatusBar>
|
||||
<Viewbox Stretch="Uniform" StretchDirection="DownOnly">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -11,6 +11,10 @@ public partial class MainWindow : Window
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
#if DEBUG
|
||||
Topmost = false;
|
||||
#endif
|
||||
|
||||
if (DataContext is MainViewModel viewModel)
|
||||
{
|
||||
Loaded += viewModel.OnInit;
|
||||
|
||||
@@ -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,8 +43,9 @@ 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;
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliWrap" Version="3.10.0" />
|
||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||
<PackageReference Include="CliWrap" Version="3.10.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user