From ab6a6b879e29ac92e8808db4eca63708e4077684 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Sun, 2 Nov 2025 15:25:41 +0800
Subject: [PATCH] Code clean
---
v2rayN/Directory.Build.props | 2 +-
v2rayN/ServiceLib/Common/Utils.cs | 31 ++++++++++++++
v2rayN/ServiceLib/Handler/ConfigHandler.cs | 24 +++++++++++
v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs | 5 +++
.../Manager/ActionPrecheckManager.cs | 15 +++++++
.../Manager/ProfileGroupItemManager.cs | 8 ++++
v2rayN/ServiceLib/Models/ProfileItem.cs | 19 +++++++++
.../CoreConfig/Singbox/SingboxDnsService.cs | 2 +
.../Singbox/SingboxOutboundService.cs | 3 ++
.../Singbox/SingboxRoutingService.cs | 4 ++
.../Singbox/SingboxRulesetService.cs | 2 +
.../V2ray/CoreConfigV2rayService.cs | 2 +
.../CoreConfig/V2ray/V2rayBalancerService.cs | 2 +
.../CoreConfig/V2ray/V2rayDnsService.cs | 6 +++
.../CoreConfig/V2ray/V2rayOutboundService.cs | 3 ++
.../ServiceLib/Services/SpeedtestService.cs | 2 +-
.../ViewModels/CheckUpdateViewModel.cs | 3 ++
.../ViewModels/ClashConnectionsViewModel.cs | 1 +
.../ViewModels/ClashProxiesViewModel.cs | 3 ++
.../ViewModels/FullConfigTemplateViewModel.cs | 4 ++
.../ViewModels/MainWindowViewModel.cs | 30 +++++++-------
.../ViewModels/ProfilesViewModel.cs | 12 +++---
.../ViewModels/StatusBarViewModel.cs | 7 +++-
v2rayN/v2rayN.Desktop/Common/AvaUtils.cs | 3 ++
.../Converters/DelayColorConverter.cs | 2 +-
.../ViewModels/ThemeSettingViewModel.cs | 2 +
.../Views/AddGroupServerWindow.axaml.cs | 2 +
.../v2rayN.Desktop/Views/MainWindow.axaml.cs | 22 +++++++---
v2rayN/v2rayN.Desktop/Views/MsgView.axaml.cs | 2 +
.../Views/ProfilesView.axaml.cs | 28 ++++++++++++-
.../Views/RoutingRuleSettingWindow.axaml.cs | 3 ++
.../Views/RoutingSettingWindow.axaml.cs | 3 ++
.../Views/StatusBarView.axaml.cs | 3 ++
.../Views/SubSettingWindow.axaml.cs | 6 +++
v2rayN/v2rayN/Common/WindowsUtils.cs | 2 +-
.../v2rayN/Converters/DelayColorConverter.cs | 14 +++----
.../ViewModels/ThemeSettingViewModel.cs | 2 +
.../v2rayN/Views/AddGroupServerWindow.xaml.cs | 3 ++
v2rayN/v2rayN/Views/MainWindow.xaml.cs | 26 ++++++++----
v2rayN/v2rayN/Views/MsgView.xaml.cs | 3 ++
v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 41 +++++++++++++++++--
.../Views/RoutingRuleSettingWindow.xaml.cs | 9 ++++
.../v2rayN/Views/RoutingSettingWindow.xaml.cs | 3 ++
v2rayN/v2rayN/Views/StatusBarView.xaml.cs | 3 ++
v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 6 +++
45 files changed, 326 insertions(+), 52 deletions(-)
diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props
index d97ccb93..069c74df 100644
--- a/v2rayN/Directory.Build.props
+++ b/v2rayN/Directory.Build.props
@@ -8,7 +8,7 @@
net8.0
true
true
- CA1031;CS1591;NU1507;CA1416;IDE0058
+ CA1031;CS1591;NU1507;CA1416;IDE0058;IDE0053;IDE0200
annotations
enable
2dust
diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs
index 2075342a..aedd3334 100644
--- a/v2rayN/ServiceLib/Common/Utils.cs
+++ b/v2rayN/ServiceLib/Common/Utils.cs
@@ -306,7 +306,10 @@ public class Utils
public static bool IsBase64String(string? plainText)
{
if (plainText.IsNullOrEmpty())
+ {
return false;
+ }
+
var buffer = new Span(new byte[plainText.Length]);
return Convert.TryFromBase64String(plainText, buffer, out var _);
}
@@ -520,40 +523,62 @@ public class Utils
{
// Loopback address check (127.0.0.1 for IPv4, ::1 for IPv6)
if (IPAddress.IsLoopback(address))
+ {
return true;
+ }
var ipBytes = address.GetAddressBytes();
if (address.AddressFamily == AddressFamily.InterNetwork)
{
// IPv4 private address check
if (ipBytes[0] == 10)
+ {
return true;
+ }
+
if (ipBytes[0] == 172 && ipBytes[1] >= 16 && ipBytes[1] <= 31)
+ {
return true;
+ }
+
if (ipBytes[0] == 192 && ipBytes[1] == 168)
+ {
return true;
+ }
}
else if (address.AddressFamily == AddressFamily.InterNetworkV6)
{
// IPv6 private address check
// Link-local address fe80::/10
if (ipBytes[0] == 0xfe && (ipBytes[1] & 0xc0) == 0x80)
+ {
return true;
+ }
// Unique local address fc00::/7 (typically fd00::/8)
if ((ipBytes[0] & 0xfe) == 0xfc)
+ {
return true;
+ }
// Private portion in IPv4-mapped addresses ::ffff:0:0/96
if (address.IsIPv4MappedToIPv6)
{
var ipv4Bytes = ipBytes.Skip(12).ToArray();
if (ipv4Bytes[0] == 10)
+ {
return true;
+ }
+
if (ipv4Bytes[0] == 172 && ipv4Bytes[1] >= 16 && ipv4Bytes[1] <= 31)
+ {
return true;
+ }
+
if (ipv4Bytes[0] == 192 && ipv4Bytes[1] == 168)
+ {
return true;
+ }
}
}
}
@@ -708,10 +733,16 @@ public class Utils
foreach (var host in hostsList)
{
if (host.StartsWith("#"))
+ {
continue;
+ }
+
var hostItem = host.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (hostItem.Length < 2)
+ {
continue;
+ }
+
systemHosts.Add(hostItem[1], hostItem[0]);
}
}
diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
index 72addec4..08937c5e 100644
--- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs
+++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
@@ -1651,7 +1651,9 @@ public static class ConfigHandler
var uri = Utils.TryUri(url);
if (uri == null)
+ {
return -1;
+ }
//Do not allow http protocol
if (url.StartsWith(Global.HttpProtocol) && !Utils.IsPrivateNetwork(uri.IdnHost))
{
@@ -2018,11 +2020,15 @@ public static class ConfigHandler
var downloadHandle = new DownloadService();
var templateContent = await downloadHandle.TryDownloadString(config.ConstItem.RouteRulesTemplateSourceUrl, true, "");
if (templateContent.IsNullOrEmpty())
+ {
return await InitBuiltinRouting(config, blImportAdvancedRules); // fallback
+ }
var template = JsonUtils.Deserialize(templateContent);
if (template == null)
+ {
return await InitBuiltinRouting(config, blImportAdvancedRules); // fallback
+ }
var items = await AppManager.Instance.RoutingItems();
var maxSort = items.Count;
@@ -2035,14 +2041,18 @@ public static class ConfigHandler
var item = template.RoutingItems[i];
if (item.Url.IsNullOrEmpty() && item.RuleSet.IsNullOrEmpty())
+ {
continue;
+ }
var ruleSetsString = !item.RuleSet.IsNullOrEmpty()
? item.RuleSet
: await downloadHandle.TryDownloadString(item.Url, true, "");
if (ruleSetsString.IsNullOrEmpty())
+ {
continue;
+ }
item.Remarks = $"{template.Version}-{item.Remarks}";
item.Enabled = true;
@@ -2238,17 +2248,25 @@ public static class ConfigHandler
var downloadHandle = new DownloadService();
var templateContent = await downloadHandle.TryDownloadString(url, true, "");
if (templateContent.IsNullOrEmpty())
+ {
return currentItem;
+ }
var template = JsonUtils.Deserialize(templateContent);
if (template == null)
+ {
return currentItem;
+ }
if (!template.NormalDNS.IsNullOrEmpty())
+ {
template.NormalDNS = await downloadHandle.TryDownloadString(template.NormalDNS, true, "");
+ }
if (!template.TunDNS.IsNullOrEmpty())
+ {
template.TunDNS = await downloadHandle.TryDownloadString(template.TunDNS, true, "");
+ }
template.Id = currentItem.Id;
template.Enabled = currentItem.Enabled;
@@ -2282,10 +2300,16 @@ public static class ConfigHandler
var downloadHandle = new DownloadService();
var templateContent = await downloadHandle.TryDownloadString(url, true, "");
if (templateContent.IsNullOrEmpty())
+ {
return null;
+ }
+
var template = JsonUtils.Deserialize(templateContent);
if (template == null)
+ {
return null;
+ }
+
return template;
}
diff --git a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs
index 5376780f..ae670662 100644
--- a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs
+++ b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs
@@ -12,7 +12,9 @@ public class Hysteria2Fmt : BaseFmt
var url = Utils.TryUri(str);
if (url == null)
+ {
return null;
+ }
item.Address = url.IdnHost;
item.Port = url.Port;
@@ -32,7 +34,10 @@ public class Hysteria2Fmt : BaseFmt
public static string? ToUri(ProfileItem? item)
{
if (item == null)
+ {
return null;
+ }
+
var url = string.Empty;
var remark = string.Empty;
diff --git a/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs b/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs
index f4f998b3..75e3e00e 100644
--- a/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs
+++ b/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs
@@ -81,21 +81,36 @@ public class ActionPrecheckManager(Config config)
{
case EConfigType.VMess:
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
+ {
errors.Add(string.Format(ResUI.InvalidProperty, "Id"));
+ }
+
break;
case EConfigType.VLESS:
if (item.Id.IsNullOrEmpty() || (!Utils.IsGuidByParse(item.Id) && item.Id.Length > 30))
+ {
errors.Add(string.Format(ResUI.InvalidProperty, "Id"));
+ }
+
if (!Global.Flows.Contains(item.Flow))
+ {
errors.Add(string.Format(ResUI.InvalidProperty, "Flow"));
+ }
+
break;
case EConfigType.Shadowsocks:
if (item.Id.IsNullOrEmpty())
+ {
errors.Add(string.Format(ResUI.InvalidProperty, "Id"));
+ }
+
if (string.IsNullOrEmpty(item.Security) || !Global.SsSecuritiesInSingbox.Contains(item.Security))
+ {
errors.Add(string.Format(ResUI.InvalidProperty, "Security"));
+ }
+
break;
}
diff --git a/v2rayN/ServiceLib/Manager/ProfileGroupItemManager.cs b/v2rayN/ServiceLib/Manager/ProfileGroupItemManager.cs
index 6cd260d3..499ad3de 100644
--- a/v2rayN/ServiceLib/Manager/ProfileGroupItemManager.cs
+++ b/v2rayN/ServiceLib/Manager/ProfileGroupItemManager.cs
@@ -173,13 +173,19 @@ public class ProfileGroupItemManager
public static bool HasCycle(string? indexId, HashSet visited, HashSet stack)
{
if (indexId.IsNullOrEmpty())
+ {
return false;
+ }
if (stack.Contains(indexId))
+ {
return true;
+ }
if (visited.Contains(indexId))
+ {
return false;
+ }
visited.Add(indexId);
stack.Add(indexId);
@@ -289,7 +295,9 @@ public class ProfileGroupItemManager
{
var childNode = await AppManager.Instance.GetProfileItem(childId);
if (childNode == null)
+ {
continue;
+ }
if (!childNode.IsComplex())
{
diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/ProfileItem.cs
index b832a5e7..00ed38da 100644
--- a/v2rayN/ServiceLib/Models/ProfileItem.cs
+++ b/v2rayN/ServiceLib/Models/ProfileItem.cs
@@ -69,30 +69,49 @@ public class ProfileItem : ReactiveObject
public bool IsValid()
{
if (IsComplex())
+ {
return true;
+ }
if (Address.IsNullOrEmpty() || Port is <= 0 or >= 65536)
+ {
return false;
+ }
switch (ConfigType)
{
case EConfigType.VMess:
if (Id.IsNullOrEmpty() || !Utils.IsGuidByParse(Id))
+ {
return false;
+ }
+
break;
case EConfigType.VLESS:
if (Id.IsNullOrEmpty() || (!Utils.IsGuidByParse(Id) && Id.Length > 30))
+ {
return false;
+ }
+
if (!Global.Flows.Contains(Flow))
+ {
return false;
+ }
+
break;
case EConfigType.Shadowsocks:
if (Id.IsNullOrEmpty())
+ {
return false;
+ }
+
if (string.IsNullOrEmpty(Security) || !Global.SsSecuritiesInSingbox.Contains(Security))
+ {
return false;
+ }
+
break;
}
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs
index c5ba5b0c..f6190ea9 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs
@@ -202,7 +202,9 @@ public partial class CoreConfigSingboxService
var routing = await ConfigHandler.GetDefaultRouting(_config);
if (routing == null)
+ {
return 0;
+ }
var rules = JsonUtils.Deserialize>(routing.RuleSet) ?? [];
var expectedIPCidr = new List();
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs
index 1f1e68a0..e9d35a89 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs
@@ -679,7 +679,10 @@ public partial class CoreConfigSingboxService
{
var node = nodes[i];
if (node == null)
+ {
continue;
+ }
+
if (node.ConfigType.IsGroupType())
{
var (childProfiles, profileGroupItem) = await ProfileGroupItemManager.GetChildProfileItems(node.IndexId);
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs
index 9cd02204..33fde24e 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs
@@ -250,7 +250,9 @@ public partial class CoreConfigSingboxService
foreach (var it in item.Domain)
{
if (ParseV2Domain(it, rule1))
+ {
countDomain++;
+ }
}
if (countDomain > 0)
{
@@ -265,7 +267,9 @@ public partial class CoreConfigSingboxService
foreach (var it in item.Ip)
{
if (ParseV2Address(it, rule2))
+ {
countIp++;
+ }
}
if (countIp > 0)
{
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRulesetService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRulesetService.cs
index ef611c91..7d26ca2f 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRulesetService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRulesetService.cs
@@ -7,7 +7,9 @@ public partial class CoreConfigSingboxService
static void AddRuleSets(List ruleSets, List? rule_set)
{
if (rule_set != null)
+ {
ruleSets.AddRange(rule_set);
+ }
}
var geosite = "geosite";
var geoip = "geoip";
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs
index 6deff64d..d753fb3c 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs
@@ -137,7 +137,9 @@ public partial class CoreConfigV2rayService(Config config)
foreach (var rule in rules)
{
if (rule.outboundTag == null)
+ {
continue;
+ }
if (balancerTagSet.Contains(rule.outboundTag))
{
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs
index 660cc700..35a220c6 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs
@@ -11,7 +11,9 @@ public partial class CoreConfigV2rayService
// Case 1: exact match already exists -> nothing to do
if (subjectSelectors.Any(baseTagName.StartsWith))
+ {
return await Task.FromResult(0);
+ }
// Case 2: prefix match exists -> reuse it and move to the first position
var matched = subjectSelectors.FirstOrDefault(s => s.StartsWith(baseTagName));
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs
index 2218d013..c24b1eb2 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs
@@ -189,7 +189,10 @@ public partial class CoreConfigV2rayService
foreach (var domain in item.Domain)
{
if (domain.StartsWith('#'))
+ {
continue;
+ }
+
var normalizedDomain = domain.Replace(Global.RoutingRuleComma, ",");
if (item.OutboundTag == Global.DirectTag)
@@ -368,7 +371,10 @@ public partial class CoreConfigV2rayService
foreach (var host in systemHosts)
{
if (normalHost1[host.Key] != null)
+ {
continue;
+ }
+
normalHost1[host.Key] = host.Value;
}
}
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs
index 46169c37..3f1f7c5f 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs
@@ -803,7 +803,10 @@ public partial class CoreConfigV2rayService
{
var node = nodes[i];
if (node == null)
+ {
continue;
+ }
+
if (node.ConfigType.IsGroupType())
{
var (childProfiles, _) = await ProfileGroupItemManager.GetChildProfileItems(node.IndexId);
diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs
index bb4e9386..3cb5c2b6 100644
--- a/v2rayN/ServiceLib/Services/SpeedtestService.cs
+++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs
@@ -21,7 +21,7 @@ public class SpeedtestService(Config config, Func updateF
{
if (_lstExitLoop.Count > 0)
{
- UpdateFunc("", ResUI.SpeedtestingStop);
+ _ = UpdateFunc("", ResUI.SpeedtestingStop);
_lstExitLoop.Clear();
}
diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs
index 5267979b..f2b39361 100644
--- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs
@@ -209,6 +209,7 @@ public class CheckUpdateViewModel : MyReactiveObject
_ = UpdateFinishedResult(blReload);
return Disposable.Empty;
});
+ await Task.CompletedTask;
}
public async Task UpdateFinishedResult(bool blReload)
@@ -321,6 +322,7 @@ public class CheckUpdateViewModel : MyReactiveObject
_ = UpdateViewResult(model);
return Disposable.Empty;
});
+ await Task.CompletedTask;
}
public async Task UpdateViewResult(CheckUpdateModel model)
@@ -331,5 +333,6 @@ public class CheckUpdateViewModel : MyReactiveObject
return;
}
found.Remarks = model.Remarks;
+ await Task.CompletedTask;
}
}
diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs
index dbcc9a79..dba8190f 100644
--- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs
@@ -96,6 +96,7 @@ public class ClashConnectionsViewModel : MyReactiveObject
}
ConnectionItems.AddRange(lstModel);
+ await Task.CompletedTask;
}
public async Task ClashConnectionClose(bool all)
diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs
index 3f636456..d49193ad 100644
--- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs
@@ -245,6 +245,7 @@ public class ClashProxiesViewModel : MyReactiveObject
{
SelectedGroup = new();
}
+ await Task.CompletedTask;
}
private void RefreshProxyDetails(bool c)
@@ -391,6 +392,7 @@ public class ClashProxiesViewModel : MyReactiveObject
_ = ProxiesDelayTestResult(model);
return Disposable.Empty;
});
+ await Task.CompletedTask;
});
await Task.CompletedTask;
}
@@ -419,6 +421,7 @@ public class ClashProxiesViewModel : MyReactiveObject
detail.Delay = _delayTimeout;
detail.DelayName = string.Empty;
}
+ await Task.CompletedTask;
}
#endregion proxy function
diff --git a/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs
index a3907fc5..3a50b52e 100644
--- a/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs
@@ -66,10 +66,14 @@ public class FullConfigTemplateViewModel : MyReactiveObject
private async Task SaveSettingAsync()
{
if (!await SaveXrayConfigAsync())
+ {
return;
+ }
if (!await SaveSingboxConfigAsync())
+ {
return;
+ }
NoticeManager.Instance.Enqueue(ResUI.OperationSuccess);
_ = _updateView?.Invoke(EViewAction.CloseWindow, null);
diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
index 0b721184..d26213fb 100644
--- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
@@ -78,55 +78,55 @@ public class MainWindowViewModel : MyReactiveObject
//servers
AddVmessServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.VMess);
+ await AddServerAsync(EConfigType.VMess);
});
AddVlessServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.VLESS);
+ await AddServerAsync(EConfigType.VLESS);
});
AddShadowsocksServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.Shadowsocks);
+ await AddServerAsync(EConfigType.Shadowsocks);
});
AddSocksServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.SOCKS);
+ await AddServerAsync(EConfigType.SOCKS);
});
AddHttpServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.HTTP);
+ await AddServerAsync(EConfigType.HTTP);
});
AddTrojanServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.Trojan);
+ await AddServerAsync(EConfigType.Trojan);
});
AddHysteria2ServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.Hysteria2);
+ await AddServerAsync(EConfigType.Hysteria2);
});
AddTuicServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.TUIC);
+ await AddServerAsync(EConfigType.TUIC);
});
AddWireguardServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.WireGuard);
+ await AddServerAsync(EConfigType.WireGuard);
});
AddAnytlsServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.Anytls);
+ await AddServerAsync(EConfigType.Anytls);
});
AddCustomServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.Custom);
+ await AddServerAsync(EConfigType.Custom);
});
AddPolicyGroupServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.PolicyGroup);
+ await AddServerAsync(EConfigType.PolicyGroup);
});
AddProxyChainServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await AddServerAsync(true, EConfigType.ProxyChain);
+ await AddServerAsync(EConfigType.ProxyChain);
});
AddServerViaClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
@@ -283,6 +283,7 @@ public class MainWindowViewModel : MyReactiveObject
{
NoticeManager.Instance.Enqueue(msg);
}
+ await Task.CompletedTask;
}
private async Task UpdateTaskHandler(bool success, string msg)
@@ -310,6 +311,7 @@ public class MainWindowViewModel : MyReactiveObject
return;
}
AppEvents.DispatcherStatisticsRequested.Publish(update);
+ await Task.CompletedTask;
}
#endregion Actions
@@ -332,7 +334,7 @@ public class MainWindowViewModel : MyReactiveObject
#region Add Servers
- public async Task AddServerAsync(bool blNew, EConfigType eConfigType)
+ public async Task AddServerAsync(EConfigType eConfigType)
{
ProfileItem item = new()
{
diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
index 12f4804b..a6bb2567 100644
--- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
@@ -110,7 +110,7 @@ public class ProfilesViewModel : MyReactiveObject
//servers delete
EditServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
- await EditServerAsync(EConfigType.Custom);
+ await EditServerAsync();
}, canEditRemove);
RemoveServerCmd = ReactiveCommand.CreateFromTask(async () =>
{
@@ -300,14 +300,14 @@ public class ProfilesViewModel : MyReactiveObject
if (result.Delay.IsNotEmpty())
{
- int.TryParse(result.Delay, out var temp);
- item.Delay = temp;
+ item.Delay = result.Delay.ToInt();
item.DelayVal = result.Delay ?? string.Empty;
}
if (result.Speed.IsNotEmpty())
{
item.SpeedVal = result.Speed ?? string.Empty;
}
+ await Task.CompletedTask;
}
public async Task UpdateStatistics(ServerSpeedItem update)
@@ -333,6 +333,7 @@ public class ProfilesViewModel : MyReactiveObject
catch
{
}
+ await Task.CompletedTask;
}
#endregion Actions
@@ -487,7 +488,7 @@ public class ProfilesViewModel : MyReactiveObject
return lstSelected;
}
- public async Task EditServerAsync(EConfigType eConfigType)
+ public async Task EditServerAsync()
{
if (string.IsNullOrEmpty(SelectedProfile?.IndexId))
{
@@ -499,7 +500,7 @@ public class ProfilesViewModel : MyReactiveObject
NoticeManager.Instance.Enqueue(ResUI.PleaseSelectServer);
return;
}
- eConfigType = item.ConfigType;
+ var eConfigType = item.ConfigType;
bool? ret = false;
if (eConfigType == EConfigType.Custom)
@@ -753,6 +754,7 @@ public class ProfilesViewModel : MyReactiveObject
_ = SetSpeedTestResult(result);
return Disposable.Empty;
});
+ await Task.CompletedTask;
});
_speedtestService?.RunLoop(actionType, lstSelected);
}
diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
index 42cdafa8..b7c2a1e7 100644
--- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
@@ -120,7 +120,7 @@ public class StatusBarViewModel : MyReactiveObject
this.WhenAnyValue(
x => x.SelectedServer,
y => y != null && !y.Text.IsNullOrEmpty())
- .Subscribe(c => ServerSelectedChanged(c));
+ .Subscribe(ServerSelectedChanged);
SystemProxySelected = (int)_config.SystemProxyItem.SysProxyType;
this.WhenAnyValue(
@@ -367,11 +367,13 @@ public class StatusBarViewModel : MyReactiveObject
_ = TestServerAvailabilityResult(msg);
return Disposable.Empty;
});
+ await Task.CompletedTask;
}
public async Task TestServerAvailabilityResult(string msg)
{
RunningInfoDisplay = msg;
+ await Task.CompletedTask;
}
#region System proxy and Routings
@@ -384,7 +386,7 @@ public class StatusBarViewModel : MyReactiveObject
}
_config.SystemProxyItem.SysProxyType = type;
await ChangeSystemProxyAsync(type, true);
- NoticeManager.Instance.SendMessageEx($"{ResUI.TipChangeSystemProxy} - {_config.SystemProxyItem.SysProxyType.ToString()}");
+ NoticeManager.Instance.SendMessageEx($"{ResUI.TipChangeSystemProxy} - {_config.SystemProxyItem.SysProxyType}");
SystemProxySelected = (int)_config.SystemProxyItem.SysProxyType;
await ConfigHandler.SaveConfig(_config);
@@ -561,6 +563,7 @@ public class StatusBarViewModel : MyReactiveObject
catch
{
}
+ await Task.CompletedTask;
}
#endregion UI
diff --git a/v2rayN/v2rayN.Desktop/Common/AvaUtils.cs b/v2rayN/v2rayN.Desktop/Common/AvaUtils.cs
index 1ef294f6..cca01643 100644
--- a/v2rayN/v2rayN.Desktop/Common/AvaUtils.cs
+++ b/v2rayN/v2rayN.Desktop/Common/AvaUtils.cs
@@ -28,7 +28,10 @@ internal class AvaUtils
{
var clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
if (clipboard == null)
+ {
return;
+ }
+
await clipboard.SetTextAsync(strData);
}
catch
diff --git a/v2rayN/v2rayN.Desktop/Converters/DelayColorConverter.cs b/v2rayN/v2rayN.Desktop/Converters/DelayColorConverter.cs
index 82cd0cf1..7b339aea 100644
--- a/v2rayN/v2rayN.Desktop/Converters/DelayColorConverter.cs
+++ b/v2rayN/v2rayN.Desktop/Converters/DelayColorConverter.cs
@@ -6,7 +6,7 @@ public class DelayColorConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
- _ = int.TryParse(value?.ToString(), out var delay);
+ var delay = value.ToString().ToInt();
return delay switch
{
diff --git a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs
index 2bfa5eaf..c84a2887 100644
--- a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs
+++ b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs
@@ -95,7 +95,9 @@ public class ThemeSettingViewModel : MyReactiveObject
{
double size = CurrentFontSize;
if (size < Global.MinFontSize)
+ {
return;
+ }
Style style = new(x => Selectors.Or(
x.OfType