mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-20 06:02:23 +00:00
50 lines
No EOL
2 KiB
C#
50 lines
No EOL
2 KiB
C#
using Avalonia.Interactivity;
|
|
using Avalonia.ReactiveUI;
|
|
using Avalonia.Threading;
|
|
using ReactiveUI;
|
|
using System.Reactive.Disposables;
|
|
|
|
namespace v2rayN.Desktop.Views
|
|
{
|
|
public partial class ClashConnectionsView : ReactiveUserControl<ClashConnectionsViewModel>
|
|
{
|
|
public ClashConnectionsView()
|
|
{
|
|
InitializeComponent();
|
|
ViewModel = new ClashConnectionsViewModel(UpdateViewHandler);
|
|
|
|
this.WhenActivated(disposables =>
|
|
{
|
|
this.OneWayBind(ViewModel, vm => vm.ConnectionItems, v => v.lstConnections.ItemsSource).DisposeWith(disposables);
|
|
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstConnections.SelectedItem).DisposeWith(disposables);
|
|
|
|
this.BindCommand(ViewModel, vm => vm.ConnectionCloseCmd, v => v.menuConnectionClose).DisposeWith(disposables);
|
|
this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.menuConnectionCloseAll).DisposeWith(disposables);
|
|
|
|
this.Bind(ViewModel, vm => vm.HostFilter, v => v.txtHostFilter.Text).DisposeWith(disposables);
|
|
this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.btnConnectionCloseAll).DisposeWith(disposables);
|
|
this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables);
|
|
});
|
|
}
|
|
|
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
|
{
|
|
switch (action)
|
|
{
|
|
case EViewAction.DispatcherRefreshConnections:
|
|
if (obj is null) return false;
|
|
Dispatcher.UIThread.Post(() =>
|
|
ViewModel?.RefreshConnections((List<ConnectionItem>?)obj),
|
|
DispatcherPriority.Default);
|
|
break;
|
|
}
|
|
|
|
return await Task.FromResult(true);
|
|
}
|
|
|
|
private void btnClose_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
ViewModel?.ClashConnectionClose(false);
|
|
}
|
|
}
|
|
} |