This commit is contained in:
2dust 2025-10-07 20:20:06 +08:00
parent 4301415b4c
commit c53d9c118a
12 changed files with 31 additions and 66 deletions

View file

@ -0,0 +1,8 @@
namespace ServiceLib.Enums;
public enum ERuleType
{
ALL = 0,
Routing = 1,
DNS = 2,
}

View file

@ -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<string> IEProxyProtocols =
[
@ -473,12 +471,6 @@ public class Global
"tcp,udp"
];
public static readonly List<string> RuleTypes =
[
RoutingRuleType,
DNSRuleType
];
public static readonly List<string> destOverrideProtocols =
[
"http",

View file

@ -15,5 +15,5 @@ public class RulesItem
public List<string>? Process { get; set; }
public bool Enabled { get; set; } = true;
public string? Remarks { get; set; }
public List<string>? RuleTypes { get; set; }
public ERuleType? RuleType { get; set; }
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -21,7 +21,8 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject
[Reactive]
public string Process { get; set; }
public IList<string> 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

View file

@ -45,12 +45,12 @@
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
<ListBox
x:Name="clbRuleTypes"
<ComboBox
x:Name="cmbRuleType"
Width="300"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
SelectionMode="Multiple,Toggle"
Theme="{DynamicResource CardCheckGroupListBox}" />
MaxDropDownHeight="1000" />
</StackPanel>
<TextBlock

View file

@ -28,16 +28,7 @@ public partial class RoutingRuleDetailsWindow : WindowBase<RoutingRuleDetailsVie
clbProtocol.ItemsSource = Global.RuleProtocols;
clbInboundTag.ItemsSource = Global.InboundTags;
cmbNetwork.ItemsSource = Global.RuleNetworks;
clbRuleTypes.SelectionChanged += ClbRuleTypes_SelectionChanged;
clbRuleTypes.ItemsSource = Global.RuleTypes;
if (ViewModel.Types != null)
{
foreach (var it in ViewModel.Types)
{
clbRuleTypes.SelectedItems.Add(it);
}
}
cmbRuleType.ItemsSource = Utils.GetEnumNames<ERuleType>();
if (!rulesItem.Id.IsNullOrEmpty())
{
@ -62,6 +53,7 @@ public partial class RoutingRuleDetailsWindow : WindowBase<RoutingRuleDetailsVie
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.SelectedValue).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
});
@ -118,12 +110,4 @@ public partial class RoutingRuleDetailsWindow : WindowBase<RoutingRuleDetailsVie
}
}
}
private void ClbRuleTypes_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (ViewModel != null)
{
ViewModel.Types = clbRuleTypes.SelectedItems.Cast<string>().ToList();
}
}
}

View file

@ -60,12 +60,12 @@
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
<ListBox
x:Name="clbRuleTypes"
<ComboBox
x:Name="cmbRuleType"
Width="200"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
FontSize="{DynamicResource StdFontSize}"
Style="{StaticResource MaterialDesignFilterChipPrimaryListBox}" />
MaxDropDownHeight="1000"
Style="{StaticResource DefComboBox}" />
</StackPanel>
<TextBlock

View file

@ -21,16 +21,7 @@ public partial class RoutingRuleDetailsWindow
clbProtocol.ItemsSource = Global.RuleProtocols;
clbInboundTag.ItemsSource = Global.InboundTags;
cmbNetwork.ItemsSource = Global.RuleNetworks;
clbRuleTypes.SelectionChanged += ClbRuleTypes_SelectionChanged;
clbRuleTypes.ItemsSource = Global.RuleTypes;
if (ViewModel.Types != null)
{
foreach (var it in ViewModel.Types)
{
clbRuleTypes.SelectedItems.Add(it);
}
}
cmbRuleType.ItemsSource = Utils.GetEnumNames<ERuleType>();
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<string>().ToList();
}
}
}