diff --git a/v2rayN/ServiceLib/Enums/ERuleType.cs b/v2rayN/ServiceLib/Enums/ERuleType.cs new file mode 100644 index 00000000..7455bf2a --- /dev/null +++ b/v2rayN/ServiceLib/Enums/ERuleType.cs @@ -0,0 +1,8 @@ +namespace ServiceLib.Enums; + +public enum ERuleType +{ + ALL = 0, + Routing = 1, + DNS = 2, +} diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 57c6bfa3..b45a6eb3 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -87,8 +87,6 @@ public class Global public const string SingboxFinalResolverTag = "final_resolver"; public const string SingboxHostsDNSTag = "hosts_dns"; public const string SingboxFakeDNSTag = "fake_dns"; - public const string RoutingRuleType = "Routing"; - public const string DNSRuleType = "DNS"; public static readonly List IEProxyProtocols = [ @@ -473,12 +471,6 @@ public class Global "tcp,udp" ]; - public static readonly List RuleTypes = - [ - RoutingRuleType, - DNSRuleType - ]; - public static readonly List destOverrideProtocols = [ "http", diff --git a/v2rayN/ServiceLib/Models/RulesItem.cs b/v2rayN/ServiceLib/Models/RulesItem.cs index 69b1b095..5a5cf529 100644 --- a/v2rayN/ServiceLib/Models/RulesItem.cs +++ b/v2rayN/ServiceLib/Models/RulesItem.cs @@ -15,5 +15,5 @@ public class RulesItem public List? Process { get; set; } public bool Enabled { get; set; } = true; public string? Remarks { get; set; } - public List? RuleTypes { get; set; } + public ERuleType? RuleType { get; set; } } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs index b8d6b6f7..d5ed77e7 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs @@ -253,7 +253,7 @@ public partial class CoreConfigSingboxService continue; } - if ((item.RuleTypes?.Count ?? 0) > 0 && !item.RuleTypes.Contains(Global.DNSRuleType)) + if (item.RuleType == ERuleType.Routing) { continue; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index b7c02255..09ace321 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -141,7 +141,7 @@ public partial class CoreConfigSingboxService continue; } - if ((item1.RuleTypes?.Count ?? 0) > 0 && !item1.RuleTypes.Contains(Global.RoutingRuleType)) + if (item1.RuleType == ERuleType.DNS) { continue; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs index 6268b740..59525135 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs @@ -142,7 +142,7 @@ public partial class CoreConfigV2rayService continue; } - if ((item.RuleTypes?.Count ?? 0) > 0 && !item.RuleTypes.Contains(Global.DNSRuleType)) + if (item.RuleType == ERuleType.Routing) { continue; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs index 1f204f36..7526812d 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs @@ -25,7 +25,7 @@ public partial class CoreConfigV2rayService continue; } - if ((item.RuleTypes?.Count ?? 0) > 0 && !item.RuleTypes.Contains(Global.RoutingRuleType)) + if (item.RuleType == ERuleType.DNS) { continue; } diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs index 2e227172..36b1babf 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs @@ -21,7 +21,8 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject [Reactive] public string Process { get; set; } - public IList Types { get; set; } + [Reactive] + public string? RuleType { get; set; } [Reactive] public bool AutoSort { get; set; } @@ -53,11 +54,7 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject Domain = Utils.List2String(SelectedSource.Domain, true); IP = Utils.List2String(SelectedSource.Ip, true); Process = Utils.List2String(SelectedSource.Process, true); - Types = SelectedSource.RuleTypes?.ToList(); - if (Types == null || Types.Count == 0) - { - Types = Global.RuleTypes; - } + RuleType = SelectedSource.RuleType?.ToString(); } private async Task SaveRulesAsync() @@ -80,7 +77,7 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject } SelectedSource.Protocol = ProtocolItems?.ToList(); SelectedSource.InboundTag = InboundTagItems?.ToList(); - SelectedSource.RuleTypes = Types?.ToList(); + SelectedSource.RuleType = RuleType.IsNullOrEmpty() ? null : (ERuleType)Enum.Parse(typeof(ERuleType), RuleType); var hasRule = SelectedSource.Domain?.Count > 0 || SelectedSource.Ip?.Count > 0 diff --git a/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml b/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml index ef2c4c09..4839490d 100644 --- a/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml @@ -45,12 +45,12 @@ Margin="{StaticResource Margin4}" HorizontalAlignment="Left" VerticalAlignment="Center" /> - + MaxDropDownHeight="1000" /> + (); if (!rulesItem.Id.IsNullOrEmpty()) { @@ -62,6 +53,7 @@ public partial class RoutingRuleDetailsWindow : WindowBase vm.IP, v => v.txtIP.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Process, v => v.txtProcess.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AutoSort, v => v.chkAutoSort.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.RuleType, v => v.cmbRuleType.SelectedValue).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); @@ -118,12 +110,4 @@ public partial class RoutingRuleDetailsWindow : WindowBase().ToList(); - } - } } diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml index 8b438ae0..af7f0a50 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml @@ -60,12 +60,12 @@ Margin="{StaticResource Margin4}" HorizontalAlignment="Left" VerticalAlignment="Center" /> - + MaxDropDownHeight="1000" + Style="{StaticResource DefComboBox}" /> (); if (!rulesItem.Id.IsNullOrEmpty()) { @@ -55,6 +46,7 @@ public partial class RoutingRuleDetailsWindow this.Bind(ViewModel, vm => vm.IP, v => v.txtIP.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Process, v => v.txtProcess.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.AutoSort, v => v.chkAutoSort.IsChecked).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.RuleType, v => v.cmbRuleType.Text).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); @@ -111,12 +103,4 @@ public partial class RoutingRuleDetailsWindow } } } - - private void ClbRuleTypes_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) - { - if (ViewModel != null) - { - ViewModel.Types = clbRuleTypes.SelectedItems.Cast().ToList(); - } - } }