2025-01-30 09:10:05 +00:00
|
|
|
using System.Reactive.Disposables;
|
|
|
|
using Avalonia.Controls;
|
2024-08-29 07:48:51 +00:00
|
|
|
using Avalonia.Input;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.ReactiveUI;
|
|
|
|
using MsBox.Avalonia.Enums;
|
|
|
|
using ReactiveUI;
|
|
|
|
using v2rayN.Desktop.Common;
|
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
namespace v2rayN.Desktop.Views;
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
public partial class RoutingSettingWindow : ReactiveWindow<RoutingSettingViewModel>
|
|
|
|
{
|
|
|
|
private bool _manualClose = false;
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
public RoutingSettingWindow()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
this.Closing += RoutingSettingWindow_Closing;
|
|
|
|
btnCancel.Click += (s, e) => this.Close();
|
|
|
|
this.KeyDown += RoutingSettingWindow_KeyDown;
|
|
|
|
lstRoutings.SelectionChanged += lstRoutings_SelectionChanged;
|
|
|
|
lstRoutings.DoubleTapped += LstRoutings_DoubleTapped;
|
|
|
|
menuRoutingAdvancedSelectAll.Click += menuRoutingAdvancedSelectAll_Click;
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
ViewModel = new RoutingSettingViewModel(UpdateViewHandler);
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
Global.DomainStrategies.ForEach(it =>
|
|
|
|
{
|
|
|
|
cmbdomainStrategy.Items.Add(it);
|
|
|
|
});
|
|
|
|
Global.DomainMatchers.ForEach(it =>
|
|
|
|
{
|
|
|
|
cmbdomainMatcher.Items.Add(it);
|
|
|
|
});
|
|
|
|
Global.DomainStrategies4Singbox.ForEach(it =>
|
|
|
|
{
|
|
|
|
cmbdomainStrategy4Singbox.Items.Add(it);
|
|
|
|
});
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
this.WhenActivated(disposables =>
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
this.OneWayBind(ViewModel, vm => vm.RoutingItems, v => v.lstRoutings.ItemsSource).DisposeWith(disposables);
|
|
|
|
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstRoutings.SelectedItem).DisposeWith(disposables);
|
|
|
|
|
|
|
|
this.Bind(ViewModel, vm => vm.DomainStrategy, v => v.cmbdomainStrategy.SelectedValue).DisposeWith(disposables);
|
|
|
|
this.Bind(ViewModel, vm => vm.DomainMatcher, v => v.cmbdomainMatcher.SelectedValue).DisposeWith(disposables);
|
|
|
|
this.Bind(ViewModel, vm => vm.DomainStrategy4Singbox, v => v.cmbdomainStrategy4Singbox.SelectedValue).DisposeWith(disposables);
|
|
|
|
|
|
|
|
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedAddCmd, v => v.menuRoutingAdvancedAdd).DisposeWith(disposables);
|
|
|
|
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedAddCmd, v => v.menuRoutingAdvancedAdd2).DisposeWith(disposables);
|
|
|
|
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedRemoveCmd, v => v.menuRoutingAdvancedRemove).DisposeWith(disposables);
|
|
|
|
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedSetDefaultCmd, v => v.menuRoutingAdvancedSetDefault).DisposeWith(disposables);
|
|
|
|
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedImportRulesCmd, v => v.menuRoutingAdvancedImportRules).DisposeWith(disposables);
|
|
|
|
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedImportRulesCmd, v => v.menuRoutingAdvancedImportRules2).DisposeWith(disposables);
|
|
|
|
|
|
|
|
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
|
|
|
});
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
|
|
|
{
|
|
|
|
switch (action)
|
2024-10-15 07:17:05 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
case EViewAction.CloseWindow:
|
|
|
|
this.Close(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EViewAction.ShowYesNo:
|
|
|
|
if (await UI.ShowYesNo(this, ResUI.RemoveRules) == ButtonResult.No)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
return false;
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
break;
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
case EViewAction.RoutingRuleSettingWindow:
|
|
|
|
if (obj is null)
|
|
|
|
return false;
|
|
|
|
return await new RoutingRuleSettingWindow((RoutingItem)obj).ShowDialog<bool>(this);
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
return await Task.FromResult(true);
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void RoutingSettingWindow_KeyDown(object? sender, KeyEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.KeyModifiers is KeyModifiers.Control or KeyModifiers.Meta)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
if (e.Key == Key.A)
|
2025-02-26 09:01:57 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
lstRoutings.SelectAll();
|
2025-02-26 09:01:57 +00:00
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
else if (e.Key is Key.Enter or Key.Return)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
ViewModel?.RoutingAdvancedSetDefault();
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
else if (e.Key == Key.Delete)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
ViewModel?.RoutingAdvancedRemoveAsync();
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void menuRoutingAdvancedSelectAll_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
lstRoutings.SelectAll();
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void lstRoutings_SelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (ViewModel != null)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
ViewModel.SelectedSources = lstRoutings.SelectedItems.Cast<RoutingItemModel>().ToList();
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void LstRoutings_DoubleTapped(object? sender, TappedEventArgs e)
|
|
|
|
{
|
|
|
|
ViewModel?.RoutingAdvancedEditAsync(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void linkdomainStrategy_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
ProcUtils.ProcessStart("https://xtls.github.io/config/routing.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void linkdomainStrategy4Singbox_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
ProcUtils.ProcessStart("https://sing-box.sagernet.org/zh/configuration/shared/listen/#domain_strategy");
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void btnCancel_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
_manualClose = true;
|
|
|
|
this.Close(ViewModel?.IsModified);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RoutingSettingWindow_Closing(object? sender, WindowClosingEventArgs e)
|
|
|
|
{
|
|
|
|
if (ViewModel?.IsModified == true)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
if (!_manualClose)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
btnCancel_Click(null, null);
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-01-30 09:10:05 +00:00
|
|
|
}
|