Refactor new StatusBarViewModel
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
x:Class="v2rayN.Desktop.App"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:v2rayN.Desktop.ViewModels"
|
||||
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
|
||||
x:DataType="local:AppViewModel"
|
||||
xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
|
||||
x:DataType="vms:StatusBarViewModel"
|
||||
RequestedThemeVariant="Default">
|
||||
<Application.Styles>
|
||||
<StyleInclude Source="Styles/GlobalStyles.axaml" />
|
||||
@@ -37,13 +37,13 @@
|
||||
<NativeMenuItem Command="{Binding SystemProxySetCmd}" Header="{x:Static resx:ResUI.menuSystemProxySet}" />
|
||||
<NativeMenuItem Command="{Binding SystemProxyNothingCmd}" Header="{x:Static resx:ResUI.menuSystemProxyNothing}" />
|
||||
<NativeMenuItemSeparator />
|
||||
<NativeMenuItem Command="{Binding AddServerViaClipboardCmd}" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
|
||||
<NativeMenuItem Click="MenuAddServerViaClipboardClick" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
|
||||
<NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" />
|
||||
<NativeMenuItem Command="{Binding SubUpdateCmd}" Header="{x:Static resx:ResUI.menuSubUpdate}" />
|
||||
<NativeMenuItem Command="{Binding SubUpdateViaProxyCmd}" Header="{x:Static resx:ResUI.menuSubUpdateViaProxy}" />
|
||||
<NativeMenuItemSeparator />
|
||||
<NativeMenuItem Click="TrayIcon_Clicked" Header="{x:Static resx:ResUI.menuShowOrHideMainWindow}" />
|
||||
<NativeMenuItem Command="{Binding ExitCmd}" Header="{x:Static resx:ResUI.menuExit}" />
|
||||
<NativeMenuItem Click="MenuExit_Click" Header="{x:Static resx:ResUI.menuExit}" />
|
||||
</NativeMenu>
|
||||
</TrayIcon.Menu>
|
||||
</TrayIcon>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using v2rayN.Desktop.ViewModels;
|
||||
using Splat;
|
||||
using v2rayN.Desktop.Common;
|
||||
using v2rayN.Desktop.Views;
|
||||
|
||||
namespace v2rayN.Desktop;
|
||||
@@ -22,7 +23,9 @@ public partial class App : Application
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
|
||||
|
||||
this.DataContext = new AppViewModel();
|
||||
var ViewModel = new StatusBarViewModel(null);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||
this.DataContext = ViewModel;
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
@@ -85,4 +88,27 @@ public partial class App : Application
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuAddServerViaClipboardClick(object? sender, EventArgs e)
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
if (desktop.MainWindow != null)
|
||||
{
|
||||
var clipboardData = AvaUtils.GetClipboardData(desktop.MainWindow).Result;
|
||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||
if (service != null) _ = service.AddServerViaClipboardAsync(clipboardData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuExit_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.MyAppExitAsync(false);
|
||||
|
||||
desktop.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace v2rayN.Desktop.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||
var service = Locator.Current.GetService<StatusBarViewModel>();
|
||||
if (service != null) await service.SetListenerType(type);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
|
||||
xmlns:view="using:v2rayN.Desktop.Views"
|
||||
xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
|
||||
Title="v2rayN"
|
||||
Width="900"
|
||||
@@ -118,72 +119,7 @@
|
||||
</Menu>
|
||||
</DockPanel>
|
||||
|
||||
<StackPanel Height="50" DockPanel.Dock="Bottom">
|
||||
<DockPanel>
|
||||
<StackPanel
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Right">
|
||||
<TextBlock x:Name="txtSpeedProxyDisplay" />
|
||||
<Border Margin="2" />
|
||||
<TextBlock x:Name="txtSpeedDirectDisplay" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Width="240"
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left">
|
||||
<TextBlock x:Name="txtInboundDisplay" />
|
||||
<Border Margin="2" />
|
||||
<TextBlock x:Name="txtInboundLanDisplay" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
x:Name="spEnableTun"
|
||||
Width="100"
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left">
|
||||
<TextBlock Text="{x:Static resx:ResUI.TbEnableTunAs}" />
|
||||
<ToggleSwitch
|
||||
x:Name="togEnableTun"
|
||||
HorizontalAlignment="Left"
|
||||
Classes="Margin8"
|
||||
Theme="{StaticResource SimpleToggleSwitch}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left"
|
||||
Orientation="Horizontal">
|
||||
<ComboBox
|
||||
x:Name="cmbSystemProxy"
|
||||
Width="120"
|
||||
Margin="8,0"
|
||||
ToolTip.Tip="{x:Static resx:ResUI.menuSystemproxy}">
|
||||
<ComboBoxItem Content="{x:Static resx:ResUI.menuSystemProxyClear}" />
|
||||
<ComboBoxItem Content="{x:Static resx:ResUI.menuSystemProxySet}" />
|
||||
<ComboBoxItem Content="{x:Static resx:ResUI.menuSystemProxyNothing}" />
|
||||
</ComboBox>
|
||||
|
||||
<ComboBox
|
||||
x:Name="cmbRoutings2"
|
||||
Width="150"
|
||||
Margin="8,0"
|
||||
DisplayMemberBinding="{Binding remarks}"
|
||||
ItemsSource="{Binding RoutingItems}"
|
||||
ToolTip.Tip="{x:Static resx:ResUI.menuRouting}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Margin="8,0" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="txtRunningServerDisplay" Tapped="TxtRunningServerDisplay_Tapped" />
|
||||
<Border Margin="2" />
|
||||
<TextBlock x:Name="txtRunningInfoDisplay" Tapped="TxtRunningServerDisplay_Tapped" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<view:StatusBarView DockPanel.Dock="Bottom" />
|
||||
|
||||
<Grid>
|
||||
<Grid x:Name="gridMain" IsVisible="False">
|
||||
|
||||
@@ -12,7 +12,6 @@ using Splat;
|
||||
using System.ComponentModel;
|
||||
using System.Reactive.Disposables;
|
||||
using v2rayN.Desktop.Common;
|
||||
using v2rayN.Desktop.Handler;
|
||||
|
||||
namespace v2rayN.Desktop.Views
|
||||
{
|
||||
@@ -40,9 +39,8 @@ namespace v2rayN.Desktop.Views
|
||||
menuCheckUpdate.Click += MenuCheckUpdate_Click;
|
||||
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
|
||||
|
||||
var IsAdministrator = Utils.IsAdministrator();
|
||||
MessageBus.Current.Listen<string>(EMsgCommand.SendSnackMsg.ToString()).Subscribe(x => DelegateSnackMsg(x));
|
||||
ViewModel = new MainWindowViewModel(IsAdministrator, UpdateViewHandler);
|
||||
ViewModel = new MainWindowViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(MainWindowViewModel));
|
||||
|
||||
//WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null);
|
||||
@@ -82,19 +80,6 @@ namespace v2rayN.Desktop.Views
|
||||
this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables);
|
||||
|
||||
//status bar
|
||||
this.OneWayBind(ViewModel, vm => vm.InboundDisplay, v => v.txtInboundDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.InboundLanDisplay, v => v.txtInboundLanDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.RunningServerDisplay, v => v.txtRunningServerDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.RunningInfoDisplay, v => v.txtRunningInfoDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.SpeedProxyDisplay, v => v.txtSpeedProxyDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.SpeedDirectDisplay, v => v.txtSpeedDirectDisplay.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.EnableTun, v => v.togEnableTun.IsChecked).DisposeWith(disposables);
|
||||
|
||||
this.Bind(ViewModel, vm => vm.SystemProxySelected, v => v.cmbSystemProxy.SelectedIndex).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.RoutingItems, v => v.cmbRoutings2.ItemsSource).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.SelectedRouting, v => v.cmbRoutings2.SelectedItem).DisposeWith(disposables);
|
||||
|
||||
if (_config.uiItem.mainGirdOrientation == EGirdOrientation.Horizontal)
|
||||
{
|
||||
gridMain.IsVisible = true;
|
||||
@@ -118,7 +103,7 @@ namespace v2rayN.Desktop.Views
|
||||
}
|
||||
});
|
||||
|
||||
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||
this.Title = $"{Utils.GetVersion()} - {(Utils.IsAdministrator() ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||
if (Utils.IsWindows())
|
||||
{
|
||||
menuGlobalHotkeySetting.IsVisible = false;
|
||||
@@ -128,10 +113,6 @@ namespace v2rayN.Desktop.Views
|
||||
menuRebootAsAdmin.IsVisible = false;
|
||||
menuSettingsSetUWP.IsVisible = false;
|
||||
menuGlobalHotkeySetting.IsVisible = false;
|
||||
if (_config.tunModeItem.enableTun)
|
||||
{
|
||||
ViewModel.EnableTun = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_config.uiItem.mainGirdOrientation == EGirdOrientation.Horizontal)
|
||||
@@ -215,33 +196,12 @@ namespace v2rayN.Desktop.Views
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherServerAvailability:
|
||||
if (obj is null) return false;
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
ViewModel?.TestServerAvailabilityResult((string)obj),
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherReload:
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
ViewModel?.ReloadResult(),
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherRefreshServersBiz:
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
ViewModel?.RefreshServersBiz(),
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherRefreshIcon:
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
this.Icon = AvaUtils.GetAppIcon(_config.systemProxyItem.sysProxyType);
|
||||
},
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.Shutdown:
|
||||
StorageUI();
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
@@ -251,12 +211,7 @@ namespace v2rayN.Desktop.Views
|
||||
break;
|
||||
|
||||
case EViewAction.ScanScreenTask:
|
||||
ScanScreenTaskAsync().ContinueWith(_ => { });
|
||||
break;
|
||||
|
||||
case EViewAction.UpdateSysProxy:
|
||||
if (obj is null) return false;
|
||||
await SysProxyHandler.UpdateSysProxy(_config, (bool)obj);
|
||||
await ScanScreenTaskAsync();
|
||||
break;
|
||||
|
||||
case EViewAction.AddServerViaClipboard:
|
||||
@@ -282,21 +237,21 @@ namespace v2rayN.Desktop.Views
|
||||
ShowHideWindow(null);
|
||||
break;
|
||||
|
||||
case EGlobalHotkey.SystemProxyClear:
|
||||
ViewModel?.SetListenerType(ESysProxyType.ForcedClear);
|
||||
break;
|
||||
//case EGlobalHotkey.SystemProxyClear:
|
||||
// ViewModel?.SetListenerType(ESysProxyType.ForcedClear);
|
||||
// break;
|
||||
|
||||
case EGlobalHotkey.SystemProxySet:
|
||||
ViewModel?.SetListenerType(ESysProxyType.ForcedChange);
|
||||
break;
|
||||
//case EGlobalHotkey.SystemProxySet:
|
||||
// ViewModel?.SetListenerType(ESysProxyType.ForcedChange);
|
||||
// break;
|
||||
|
||||
case EGlobalHotkey.SystemProxyUnchanged:
|
||||
ViewModel?.SetListenerType(ESysProxyType.Unchanged);
|
||||
break;
|
||||
//case EGlobalHotkey.SystemProxyUnchanged:
|
||||
// ViewModel?.SetListenerType(ESysProxyType.Unchanged);
|
||||
// break;
|
||||
|
||||
case EGlobalHotkey.SystemProxyPac:
|
||||
ViewModel?.SetListenerType(ESysProxyType.Pac);
|
||||
break;
|
||||
//case EGlobalHotkey.SystemProxyPac:
|
||||
// ViewModel?.SetListenerType(ESysProxyType.Pac);
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,11 +297,6 @@ namespace v2rayN.Desktop.Views
|
||||
Utils.ProcessStart($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}");
|
||||
}
|
||||
|
||||
private void TxtRunningServerDisplay_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)
|
||||
{
|
||||
ViewModel?.TestServerAvailability();
|
||||
}
|
||||
|
||||
private void menuSettingsSetUWP_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Utils.ProcessStart(Utils.GetBinPath("EnableLoopback.exe"));
|
||||
|
||||
81
v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml
Normal file
81
v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml
Normal file
@@ -0,0 +1,81 @@
|
||||
<UserControl
|
||||
x:Class="v2rayN.Desktop.Views.StatusBarView"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
|
||||
xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:DataType="vms:StatusBarViewModel"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<StackPanel Height="50">
|
||||
<DockPanel>
|
||||
<StackPanel
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Right">
|
||||
<TextBlock x:Name="txtSpeedProxyDisplay" />
|
||||
<Border Margin="2" />
|
||||
<TextBlock x:Name="txtSpeedDirectDisplay" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Width="240"
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left">
|
||||
<TextBlock x:Name="txtInboundDisplay" />
|
||||
<Border Margin="2" />
|
||||
<TextBlock x:Name="txtInboundLanDisplay" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
x:Name="spEnableTun"
|
||||
Width="100"
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left">
|
||||
<TextBlock Text="{x:Static resx:ResUI.TbEnableTunAs}" />
|
||||
<ToggleSwitch
|
||||
x:Name="togEnableTun"
|
||||
HorizontalAlignment="Left"
|
||||
Classes="Margin8"
|
||||
Theme="{StaticResource SimpleToggleSwitch}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Left"
|
||||
Orientation="Horizontal">
|
||||
<ComboBox
|
||||
x:Name="cmbSystemProxy"
|
||||
Width="120"
|
||||
Margin="8,0"
|
||||
ToolTip.Tip="{x:Static resx:ResUI.menuSystemproxy}">
|
||||
<ComboBoxItem Content="{x:Static resx:ResUI.menuSystemProxyClear}" />
|
||||
<ComboBoxItem Content="{x:Static resx:ResUI.menuSystemProxySet}" />
|
||||
<ComboBoxItem Content="{x:Static resx:ResUI.menuSystemProxyNothing}" />
|
||||
</ComboBox>
|
||||
|
||||
<ComboBox
|
||||
x:Name="cmbRoutings2"
|
||||
Width="150"
|
||||
Margin="8,0"
|
||||
DisplayMemberBinding="{Binding remarks}"
|
||||
ItemsSource="{Binding RoutingItems}"
|
||||
ToolTip.Tip="{x:Static resx:ResUI.menuRouting}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Margin="8,0" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="txtRunningServerDisplay" />
|
||||
<Border Margin="2" />
|
||||
<TextBlock x:Name="txtRunningInfoDisplay" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
136
v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs
Normal file
136
v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using System.Reactive.Disposables;
|
||||
using v2rayN.Desktop.Common;
|
||||
using v2rayN.Desktop.Handler;
|
||||
|
||||
namespace v2rayN.Desktop.Views
|
||||
{
|
||||
public partial class StatusBarView : ReactiveUserControl<StatusBarViewModel>
|
||||
{
|
||||
private static Config _config;
|
||||
|
||||
public StatusBarView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_config = AppHandler.Instance.Config;
|
||||
//ViewModel = new StatusBarViewModel(UpdateViewHandler);
|
||||
//Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||
ViewModel = Locator.Current.GetService<StatusBarViewModel>();
|
||||
ViewModel?.Init(UpdateViewHandler);
|
||||
|
||||
txtRunningServerDisplay.Tapped += TxtRunningServerDisplay_Tapped;
|
||||
txtRunningInfoDisplay.Tapped += TxtRunningServerDisplay_Tapped;
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
//status bar
|
||||
this.OneWayBind(ViewModel, vm => vm.InboundDisplay, v => v.txtInboundDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.InboundLanDisplay, v => v.txtInboundLanDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.RunningServerDisplay, v => v.txtRunningServerDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.RunningInfoDisplay, v => v.txtRunningInfoDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.SpeedProxyDisplay, v => v.txtSpeedProxyDisplay.Text).DisposeWith(disposables);
|
||||
this.OneWayBind(ViewModel, vm => vm.SpeedDirectDisplay, v => v.txtSpeedDirectDisplay.Text).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.EnableTun, v => v.togEnableTun.IsChecked).DisposeWith(disposables);
|
||||
|
||||
this.Bind(ViewModel, vm => vm.SystemProxySelected, v => v.cmbSystemProxy.SelectedIndex).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.RoutingItems, v => v.cmbRoutings2.ItemsSource).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.SelectedRouting, v => v.cmbRoutings2.SelectedItem).DisposeWith(disposables);
|
||||
|
||||
////system proxy
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlSystemProxyClear, v => v.menuSystemProxyClear2.Visibility, conversionHint: BooleanToVisibilityHint.UseHidden, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlSystemProxySet, v => v.menuSystemProxySet2.Visibility, conversionHint: BooleanToVisibilityHint.UseHidden, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlSystemProxyNothing, v => v.menuSystemProxyNothing2.Visibility, conversionHint: BooleanToVisibilityHint.UseHidden, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlSystemProxyPac, v => v.menuSystemProxyPac2.Visibility, conversionHint: BooleanToVisibilityHint.UseHidden, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
|
||||
//this.BindCommand(ViewModel, vm => vm.SystemProxyClearCmd, v => v.menuSystemProxyClear).DisposeWith(disposables);
|
||||
//this.BindCommand(ViewModel, vm => vm.SystemProxySetCmd, v => v.menuSystemProxySet).DisposeWith(disposables);
|
||||
//this.BindCommand(ViewModel, vm => vm.SystemProxyPacCmd, v => v.menuSystemProxyPac).DisposeWith(disposables);
|
||||
//this.BindCommand(ViewModel, vm => vm.SystemProxyNothingCmd, v => v.menuSystemProxyNothing).DisposeWith(disposables);
|
||||
|
||||
////routings and servers
|
||||
//this.OneWayBind(ViewModel, vm => vm.RoutingItems, v => v.cmbRoutings.ItemsSource).DisposeWith(disposables);
|
||||
//this.Bind(ViewModel, vm => vm.SelectedRouting, v => v.cmbRoutings.SelectedItem).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlRouting, v => v.menuRoutings.Visibility).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlRouting, v => v.sepRoutings.Visibility).DisposeWith(disposables);
|
||||
|
||||
//this.OneWayBind(ViewModel, vm => vm.Servers, v => v.cmbServers.ItemsSource).DisposeWith(disposables);
|
||||
//this.Bind(ViewModel, vm => vm.SelectedServer, v => v.cmbServers.SelectedItem).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlServers, v => v.cmbServers.Visibility).DisposeWith(disposables);
|
||||
|
||||
////tray menu
|
||||
//this.BindCommand(ViewModel, vm => vm.AddServerViaClipboardCmd, v => v.menuAddServerViaClipboard2).DisposeWith(disposables);
|
||||
//this.BindCommand(ViewModel, vm => vm.AddServerViaScanCmd, v => v.menuAddServerViaScan2).DisposeWith(disposables);
|
||||
//this.BindCommand(ViewModel, vm => vm.SubUpdateCmd, v => v.menuSubUpdate2).DisposeWith(disposables);
|
||||
//this.BindCommand(ViewModel, vm => vm.SubUpdateViaProxyCmd, v => v.menuSubUpdateViaProxy2).DisposeWith(disposables);
|
||||
|
||||
//this.OneWayBind(ViewModel, vm => vm.RunningServerToolTipText, v => v.tbNotify.ToolTipText).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.NotifyLeftClickCmd, v => v.tbNotify.LeftClickCommand).DisposeWith(disposables);
|
||||
|
||||
////status bar
|
||||
//this.OneWayBind(ViewModel, vm => vm.InboundDisplay, v => v.txtInboundDisplay.Text).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.InboundLanDisplay, v => v.txtInboundLanDisplay.Text).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.RunningServerDisplay, v => v.txtRunningServerDisplay.Text).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.RunningInfoDisplay, v => v.txtRunningInfoDisplay.Text).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.SpeedProxyDisplay, v => v.txtSpeedProxyDisplay.Text).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.SpeedDirectDisplay, v => v.txtSpeedDirectDisplay.Text).DisposeWith(disposables);
|
||||
//this.Bind(ViewModel, vm => vm.EnableTun, v => v.togEnableTun.IsChecked).DisposeWith(disposables);
|
||||
|
||||
//this.Bind(ViewModel, vm => vm.SystemProxySelected, v => v.cmbSystemProxy.SelectedIndex).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.RoutingItems, v => v.cmbRoutings2.ItemsSource).DisposeWith(disposables);
|
||||
//this.Bind(ViewModel, vm => vm.SelectedRouting, v => v.cmbRoutings2.SelectedItem).DisposeWith(disposables);
|
||||
//this.OneWayBind(ViewModel, vm => vm.BlRouting, v => v.cmbRoutings2.Visibility).DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case EViewAction.UpdateSysProxy:
|
||||
if (obj is null) return false;
|
||||
await SysProxyHandler.UpdateSysProxy(_config, (bool)obj);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherServerAvailability:
|
||||
if (obj is null) return false;
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
ViewModel?.TestServerAvailabilityResult((string)obj),
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherRefreshServersBiz:
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
ViewModel?.RefreshServersBiz(),
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherRefreshIcon:
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
RefreshIcon();
|
||||
},
|
||||
DispatcherPriority.Default);
|
||||
break;
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private void RefreshIcon()
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
desktop.MainWindow.Icon = AvaUtils.GetAppIcon(_config.systemProxyItem.sysProxyType);
|
||||
}
|
||||
}
|
||||
|
||||
private void TxtRunningServerDisplay_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)
|
||||
{
|
||||
ViewModel?.TestServerAvailability();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user