Code clean (#9482)

This commit is contained in:
DHR60
2026-06-06 03:20:06 +00:00
committed by GitHub
parent 4dc9c60b85
commit e6d08c2db1
58 changed files with 169 additions and 217 deletions
@@ -216,7 +216,7 @@ public class AddGroupServerViewModel : MyReactiveObject
NoticeManager.Instance.Enqueue(ResUI.PleaseAddAtLeastOneServer);
return;
}
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? ECoreType.Xray : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType);
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? ECoreType.Xray : Enum.Parse<ECoreType>(CoreType);
if (SelectedSource.CoreType is not (ECoreType.Xray or ECoreType.sing_box) ||
SelectedSource.ConfigType is not (EConfigType.ProxyChain or EConfigType.PolicyGroup))
{
@@ -50,7 +50,7 @@ public class AddServer2ViewModel : MyReactiveObject
NoticeManager.Instance.Enqueue(ResUI.FillServerAddressCustom);
return;
}
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType);
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : Enum.Parse<ECoreType>(CoreType);
if (await ConfigHandler.EditCustomServer(_config, SelectedSource) == 0)
{
@@ -69,7 +69,7 @@ public class ClashConnectionsViewModel : MyReactiveObject
var dtNow = DateTime.Now;
var lstModel = new List<ClashConnectionModel>();
foreach (var item in connections ?? new())
foreach (var item in connections ?? [])
{
var host = $"{(item.metadata.host.IsNullOrEmpty() ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}";
if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter))
@@ -85,7 +85,7 @@ public class ClashConnectionsViewModel : MyReactiveObject
Host = host,
Time = (dtNow - item.start).TotalSeconds < 0 ? 1 : (dtNow - item.start).TotalSeconds,
Elapsed = (dtNow - item.start).ToString(@"hh\:mm\:ss"),
Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}"
Chain = $"{item.rule} , {string.Join("->", item.chains ?? [])}"
};
lstModel.Add(model);
@@ -67,7 +67,7 @@ public class ClashProxiesViewModel : MyReactiveObject
this.WhenAnyValue(
x => x.SelectedGroup,
y => y != null && y.Name.IsNotEmpty())
.Subscribe(c => RefreshProxyDetails(c));
.Subscribe(RefreshProxyDetails);
this.WhenAnyValue(
x => x.RuleModeSelected,
@@ -77,7 +77,7 @@ public class ClashProxiesViewModel : MyReactiveObject
this.WhenAnyValue(
x => x.SortingSelected,
y => y >= 0)
.Subscribe(c => DoSortingSelected(c));
.Subscribe(DoSortingSelected);
this.WhenAnyValue(
x => x.AutoRefresh,
@@ -188,15 +188,14 @@ public class ClashProxiesViewModel : MyReactiveObject
ProxyGroups.Clear();
var proxyGroups = ClashApiManager.Instance.GetClashProxyGroups();
if (proxyGroups != null && proxyGroups.Count > 0)
if (proxyGroups is { Count: > 0 })
{
foreach (var it in proxyGroups)
{
if (it.name.IsNullOrEmpty() || !_proxies.ContainsKey(it.name))
if (it.name.IsNullOrEmpty() || !_proxies.TryGetValue(it.name, out var item))
{
continue;
}
var item = _proxies[it.name];
if (!Global.allowSelectType.Contains(item.type.ToLower()))
{
continue;
@@ -230,7 +229,7 @@ public class ClashProxiesViewModel : MyReactiveObject
});
}
if (ProxyGroups != null && ProxyGroups.Count > 0)
if (ProxyGroups is { Count: > 0 })
{
if (selectedName != null && ProxyGroups.Any(t => t.Name == selectedName))
{
@@ -56,7 +56,7 @@ public class DNSSettingViewModel : MyReactiveObject
});
this.WhenAnyValue(x => x.RayCustomDNSEnableCompatible, x => x.SBCustomDNSEnableCompatible)
.Select(x => !(x.Item1 && x.Item2))
.Select(x => x is not { Item1: true, Item2: true })
.ToPropertyEx(this, x => x.IsSimpleDNSEnabled);
_ = Init();
@@ -236,12 +236,9 @@ public class OptionSettingViewModel : MyReactiveObject
private async Task InitCoreType()
{
if (_config.CoreTypeItem == null)
{
_config.CoreTypeItem = new List<CoreTypeItem>();
}
_config.CoreTypeItem ??= [];
foreach (EConfigType it in Enum.GetValues(typeof(EConfigType)))
foreach (var it in Enum.GetValues<EConfigType>())
{
if (_config.CoreTypeItem.FindIndex(t => t.ConfigType == it) >= 0)
{
@@ -458,7 +455,7 @@ public class OptionSettingViewModel : MyReactiveObject
default:
continue;
}
item.CoreType = (ECoreType)Enum.Parse(typeof(ECoreType), type);
item.CoreType = Enum.Parse<ECoreType>(type);
}
await Task.CompletedTask;
}
@@ -5,13 +5,10 @@ public class ProfilesSelectViewModel : MyReactiveObject
#region private prop
private string _serverFilter = string.Empty;
private Dictionary<string, bool> _dicHeaderSort = new();
private readonly Dictionary<string, bool> _dicHeaderSort = new();
private string _subIndexId = string.Empty;
// ConfigType filter state: default include-mode with all types selected
private List<EConfigType> _filterConfigTypes = new();
private bool _filterExclude = false;
#endregion private prop
@@ -33,18 +30,11 @@ public class ProfilesSelectViewModel : MyReactiveObject
public string ServerFilter { get; set; }
// Include/Exclude filter for ConfigType
public List<EConfigType> FilterConfigTypes
{
get => _filterConfigTypes;
set => this.RaiseAndSetIfChanged(ref _filterConfigTypes, value);
}
[Reactive]
public List<EConfigType> FilterConfigTypes { get; set; }
[Reactive]
public bool FilterExclude
{
get => _filterExclude;
set => this.RaiseAndSetIfChanged(ref _filterExclude, value);
}
public bool FilterExclude { get; set; }
#endregion ObservableCollection
@@ -91,11 +81,11 @@ public class ProfilesSelectViewModel : MyReactiveObject
try
{
FilterExclude = false;
FilterConfigTypes = Enum.GetValues(typeof(EConfigType)).Cast<EConfigType>().ToList();
FilterConfigTypes = Enum.GetValues<EConfigType>().ToList();
}
catch
{
FilterConfigTypes = new();
FilterConfigTypes = [];
}
await RefreshSubscriptions();
@@ -165,14 +155,7 @@ public class ProfilesSelectViewModel : MyReactiveObject
if (lstModel.Count > 0)
{
var selected = lstModel.FirstOrDefault(t => t.IndexId == _config.IndexId);
if (selected != null)
{
SelectedProfile = selected;
}
else
{
SelectedProfile = lstModel.First();
}
SelectedProfile = selected ?? lstModel.First();
}
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
@@ -213,7 +196,7 @@ public class ProfilesSelectViewModel : MyReactiveObject
}).OrderBy(t => t.Sort).ToList();
// Apply ConfigType filter (include or exclude)
if (FilterConfigTypes != null && FilterConfigTypes.Count > 0)
if (FilterConfigTypes is { Count: > 0 })
{
if (FilterExclude)
{
@@ -321,7 +304,7 @@ public class ProfilesSelectViewModel : MyReactiveObject
// External setter for ConfigType filter
public void SetConfigTypeFilter(IEnumerable<EConfigType> types, bool exclude = false)
{
FilterConfigTypes = types?.Distinct().ToList() ?? new List<EConfigType>();
FilterConfigTypes = types?.Distinct().ToList() ?? [];
FilterExclude = exclude;
}
@@ -6,7 +6,7 @@ public class ProfilesViewModel : MyReactiveObject
private List<ProfileItem> _lstProfile;
private string _serverFilter = string.Empty;
private Dictionary<string, bool> _dicHeaderSort = new();
private readonly Dictionary<string, bool> _dicHeaderSort = new();
private SpeedtestService? _speedtestService;
private string? _pendingSelectIndexId;
@@ -190,7 +190,7 @@ public class ProfilesViewModel : MyReactiveObject
}, canEditRemove);
SortServerResultCmd = ReactiveCommand.CreateFromTask(async () =>
{
await SortServer(EServerColName.DelayVal.ToString());
await SortServer(nameof(EServerColName.DelayVal));
});
RemoveInvalidServerResultCmd = ReactiveCommand.CreateFromTask(async () =>
{
@@ -73,7 +73,7 @@ public class RoutingRuleDetailsViewModel : MyReactiveObject
}
SelectedSource.Protocol = ProtocolItems?.ToList();
SelectedSource.InboundTag = InboundTagItems?.ToList();
SelectedSource.RuleType = RuleType.IsNullOrEmpty() ? null : (ERuleType)Enum.Parse(typeof(ERuleType), RuleType);
SelectedSource.RuleType = RuleType.IsNullOrEmpty() ? null : Enum.Parse<ERuleType>(RuleType);
var hasRule = SelectedSource.Domain?.Count > 0
|| SelectedSource.Ip?.Count > 0
@@ -86,7 +86,7 @@ public class RoutingRuleSettingViewModel : MyReactiveObject
SelectedSource = new();
SelectedRouting = routingItem;
_rules = routingItem.Id.IsNullOrEmpty() ? new() : JsonUtils.Deserialize<List<RulesItem>>(SelectedRouting.RuleSet);
_rules = routingItem.Id.IsNullOrEmpty() ? [] : JsonUtils.Deserialize<List<RulesItem>>(SelectedRouting.RuleSet);
RefreshRulesItems();
}
@@ -313,9 +313,8 @@ public class StatusBarViewModel : MyReactiveObject
}
BlServers = true;
for (var k = 0; k < lstModel.Count; k++)
foreach (var it in lstModel)
{
var it = lstModel[k];
var name = it.GetSummary();
var item = new ComboItem() { ID = it.IndexId, Text = name };