diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props index 3bb4af7a..2e863e42 100644 --- a/v2rayN/Directory.Build.props +++ b/v2rayN/Directory.Build.props @@ -1,7 +1,7 @@ - 7.16.0 + 7.16.1 diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 5fb14023..1712b40c 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -998,7 +998,7 @@ public class Utils public static bool IsLinux() => OperatingSystem.IsLinux(); - public static bool IsOSX() => OperatingSystem.IsMacOS(); + public static bool IsMacOS() => OperatingSystem.IsMacOS(); public static bool IsNonWindows() => !OperatingSystem.IsWindows(); @@ -1020,7 +1020,7 @@ public class Utils { try { - if (IsWindows() || IsOSX()) + if (IsWindows() || IsMacOS()) { return false; } diff --git a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs index 82e94517..bc86cd7f 100644 --- a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs +++ b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs @@ -26,7 +26,7 @@ public static class AutoStartupHandler await SetTaskLinux(); } } - else if (Utils.IsOSX()) + else if (Utils.IsMacOS()) { await ClearTaskOSX(); diff --git a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs index adcd3114..c8d6a71a 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs @@ -45,7 +45,7 @@ public class Hysteria2Fmt : BaseFmt } var dicQuery = new Dictionary(); ToUriQueryLite(item, ref dicQuery); - + if (item.Path.IsNotEmpty()) { dicQuery.Add("obfs", "salamander"); diff --git a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs index 426945e0..21453591 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs @@ -33,7 +33,7 @@ public static class SysProxyHandler await ProxySettingLinux.SetProxy(Global.Loopback, port, exceptions); break; - case ESysProxyType.ForcedChange when Utils.IsOSX(): + case ESysProxyType.ForcedChange when Utils.IsMacOS(): await ProxySettingOSX.SetProxy(Global.Loopback, port, exceptions); break; @@ -45,7 +45,7 @@ public static class SysProxyHandler await ProxySettingLinux.UnsetProxy(); break; - case ESysProxyType.ForcedClear when Utils.IsOSX(): + case ESysProxyType.ForcedClear when Utils.IsMacOS(): await ProxySettingOSX.UnsetProxy(); break; diff --git a/v2rayN/ServiceLib/Helper/HttpClientHelper.cs b/v2rayN/ServiceLib/Helper/HttpClientHelper.cs index 0c9bd470..9bc38c01 100644 --- a/v2rayN/ServiceLib/Helper/HttpClientHelper.cs +++ b/v2rayN/ServiceLib/Helper/HttpClientHelper.cs @@ -48,7 +48,6 @@ public class HttpClientHelper } return await httpClient.GetStringAsync(url); } - public async Task PutAsync(string url, Dictionary headers) { @@ -72,6 +71,4 @@ public class HttpClientHelper { await httpClient.DeleteAsync(url); } - - } diff --git a/v2rayN/ServiceLib/Manager/CertPemManager.cs b/v2rayN/ServiceLib/Manager/CertPemManager.cs index 449592a7..9421aabf 100644 --- a/v2rayN/ServiceLib/Manager/CertPemManager.cs +++ b/v2rayN/ServiceLib/Manager/CertPemManager.cs @@ -202,7 +202,7 @@ public class CertPemManager /// /// Get certificate in PEM format from a server with CA pinning validation /// - public async Task<(string?, string?)> GetCertPemAsync(string target, string serverName, int timeout = 10) + public async Task<(string?, string?)> GetCertPemAsync(string target, string serverName, int timeout = 4) { try { @@ -216,7 +216,13 @@ public class CertPemManager using var ssl = new SslStream(client.GetStream(), false, ValidateServerCertificate); - await ssl.AuthenticateAsClientAsync(serverName); + var sslOptions = new SslClientAuthenticationOptions + { + TargetHost = serverName, + RemoteCertificateValidationCallback = ValidateServerCertificate + }; + + await ssl.AuthenticateAsClientAsync(sslOptions, cts.Token); var remote = ssl.RemoteCertificate; if (remote == null) @@ -242,7 +248,7 @@ public class CertPemManager /// /// Get certificate chain in PEM format from a server with CA pinning validation /// - public async Task<(List, string?)> GetCertChainPemAsync(string target, string serverName, int timeout = 10) + public async Task<(List, string?)> GetCertChainPemAsync(string target, string serverName, int timeout = 4) { var pemList = new List(); try @@ -257,7 +263,13 @@ public class CertPemManager using var ssl = new SslStream(client.GetStream(), false, ValidateServerCertificate); - await ssl.AuthenticateAsClientAsync(serverName); + var sslOptions = new SslClientAuthenticationOptions + { + TargetHost = serverName, + RemoteCertificateValidationCallback = ValidateServerCertificate + }; + + await ssl.AuthenticateAsClientAsync(sslOptions, cts.Token); if (ssl.RemoteCertificate is not X509Certificate2 certChain) { @@ -330,10 +342,74 @@ public class CertPemManager return TrustedCaThumbprints.Contains(rootThumbprint); } - public string ExportCertToPem(X509Certificate2 cert) + public static string ExportCertToPem(X509Certificate2 cert) { var der = cert.Export(X509ContentType.Cert); - var b64 = Convert.ToBase64String(der, Base64FormattingOptions.InsertLineBreaks); + var b64 = Convert.ToBase64String(der); return $"-----BEGIN CERTIFICATE-----\n{b64}\n-----END CERTIFICATE-----\n"; } + + /// + /// Parse concatenated PEM certificates string into a list of individual certificates + /// Normalizes format: removes line breaks from base64 content for better compatibility + /// + /// Concatenated PEM certificates string (supports both \r\n and \n line endings) + /// List of individual PEM certificate strings with normalized format + public static List ParsePemChain(string pemChain) + { + var certs = new List(); + if (string.IsNullOrWhiteSpace(pemChain)) + { + return certs; + } + + // Normalize line endings (CRLF -> LF) at the beginning + pemChain = pemChain.Replace("\r\n", "\n").Replace("\r", "\n"); + + const string beginMarker = "-----BEGIN CERTIFICATE-----"; + const string endMarker = "-----END CERTIFICATE-----"; + + var index = 0; + while (index < pemChain.Length) + { + var beginIndex = pemChain.IndexOf(beginMarker, index, StringComparison.Ordinal); + if (beginIndex == -1) + break; + + var endIndex = pemChain.IndexOf(endMarker, beginIndex, StringComparison.Ordinal); + if (endIndex == -1) + break; + + // Extract certificate content + var base64Start = beginIndex + beginMarker.Length; + var base64Content = pemChain.Substring(base64Start, endIndex - base64Start); + + // Remove all whitespace from base64 content + base64Content = new string(base64Content.Where(c => !char.IsWhiteSpace(c)).ToArray()); + + // Reconstruct with clean format: BEGIN marker + base64 (no line breaks) + END marker + var normalizedCert = $"{beginMarker}\n{base64Content}\n{endMarker}\n"; + certs.Add(normalizedCert); + + // Move to next certificate + index = endIndex + endMarker.Length; + } + + return certs; + } + + /// + /// Concatenate a list of PEM certificates into a single string + /// + /// List of individual PEM certificate strings + /// Concatenated PEM certificates string + public static string ConcatenatePemChain(IEnumerable pemList) + { + if (pemList == null) + { + return string.Empty; + } + + return string.Concat(pemList); + } } diff --git a/v2rayN/ServiceLib/Manager/CoreAdminManager.cs b/v2rayN/ServiceLib/Manager/CoreAdminManager.cs index 6c54e1e1..254688e4 100644 --- a/v2rayN/ServiceLib/Manager/CoreAdminManager.cs +++ b/v2rayN/ServiceLib/Manager/CoreAdminManager.cs @@ -67,7 +67,7 @@ public class CoreAdminManager try { - var shellFileName = Utils.IsOSX() ? Global.KillAsSudoOSXShellFileName : Global.KillAsSudoLinuxShellFileName; + var shellFileName = Utils.IsMacOS() ? Global.KillAsSudoOSXShellFileName : Global.KillAsSudoLinuxShellFileName; var shFilePath = await FileUtils.CreateLinuxShellFile("kill_as_sudo.sh", EmbedUtils.GetEmbedText(shellFileName), true); if (shFilePath.Contains(' ')) { diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index dca8f3cd..f9d9493e 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -2599,8 +2599,10 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 Server certificate (PEM format, optional). Entering a certificate will pin it. - ///Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. 的本地化字符串。 + /// 查找类似 Server Certificate (PEM format, optional) + ///When specified, the certificate will be pinned, and "Allow Insecure" will be disabled. + /// + ///The "Get Certificate" action may fail if a self-signed certificate is used or if the system contains an untrusted or malicious CA. 的本地化字符串。 /// public static string TbCertPinningTips { get { @@ -3850,6 +3852,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 macOS displays this in the Dock (requires restart) 的本地化字符串。 + /// + public static string TbSettingsMacOSShowInDock { + get { + return ResourceManager.GetString("TbSettingsMacOSShowInDock", resourceCulture); + } + } + /// /// 查找类似 Main layout orientation (requires restart) 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 299f6f9f..67504966 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1606,8 +1606,10 @@ Certificate Pinning - Server certificate (PEM format, optional). Entering a certificate will pin it. -Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. + Server Certificate (PEM format, optional) +When specified, the certificate will be pinned, and "Allow Insecure" will be disabled. + +The "Get Certificate" action may fail if a self-signed certificate is used or if the system contains an untrusted or malicious CA. Fetch Certificate @@ -1630,4 +1632,7 @@ Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. Custom system proxy script file path + + macOS displays this in the Dock (requires restart) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.fr.resx b/v2rayN/ServiceLib/Resx/ResUI.fr.resx index e2703fbc..41d086d8 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fr.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fr.resx @@ -1603,8 +1603,10 @@ Certificate Pinning - Certificat serveur (PEM, optionnel). L’ajout d’un certificat le fixe. -Ne pas utiliser « Obtenir le certificat » si « Autoriser non sécurisé » est activé. + Server Certificate (PEM format, optional) +When specified, the certificate will be pinned, and "Allow Insecure" will be disabled. + +The "Get Certificate" action may fail if a self-signed certificate is used or if the system contains an untrusted or malicious CA. Obtenir le certificat @@ -1627,4 +1629,7 @@ Ne pas utiliser « Obtenir le certificat » si « Autoriser non sécurisé » es Chemin script proxy système personnalisé - + + macOS displays this in the Dock (requires restart) + + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index dd6a6a63..c71e741f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1606,8 +1606,10 @@ Certificate Pinning - Server certificate (PEM format, optional). Entering a certificate will pin it. -Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. + Server Certificate (PEM format, optional) +When specified, the certificate will be pinned, and "Allow Insecure" will be disabled. + +The "Get Certificate" action may fail if a self-signed certificate is used or if the system contains an untrusted or malicious CA. Fetch Certificate @@ -1630,4 +1632,7 @@ Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. Custom system proxy script file path + + macOS displays this in the Dock (requires restart) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index a59d068e..66381a90 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1606,8 +1606,10 @@ Certificate Pinning - Server certificate (PEM format, optional). Entering a certificate will pin it. -Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. + Server Certificate (PEM format, optional) +When specified, the certificate will be pinned, and "Allow Insecure" will be disabled. + +The "Get Certificate" action may fail if a self-signed certificate is used or if the system contains an untrusted or malicious CA. Fetch Certificate @@ -1630,4 +1632,7 @@ Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. Custom system proxy script file path + + macOS displays this in the Dock (requires restart) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 59176fa3..2694db03 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1606,8 +1606,10 @@ Certificate Pinning - Server certificate (PEM format, optional). Entering a certificate will pin it. -Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. + Server Certificate (PEM format, optional) +When specified, the certificate will be pinned, and "Allow Insecure" will be disabled. + +The "Get Certificate" action may fail if a self-signed certificate is used or if the system contains an untrusted or malicious CA. Fetch Certificate @@ -1630,4 +1632,7 @@ Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. Custom system proxy script file path + + macOS displays this in the Dock (requires restart) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index a58f3c57..2f3d0622 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1603,8 +1603,10 @@ 固定证书 - 服务器证书(PEM 格式,可选)。填入后将固定该证书。 -启用“跳过证书验证”时,请勿使用 '获取证书'。 + 服务器证书(PEM 格式,可选) +当指定此证书后,将固定该证书,并禁用“跳过证书验证”选项。 + +“获取证书”操作可能失败,原因可能是使用了自签证书,或系统中存在不受信任或恶意的 CA。 获取证书 @@ -1627,4 +1629,7 @@ 自定义系统代理脚本文件路径 + + macOS 在 Dock 栏中显示 (需重启) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index e76a044f..b45480a4 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1603,8 +1603,10 @@ Certificate Pinning - Server certificate (PEM format, optional). Entering a certificate will pin it. -Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. + Server Certificate (PEM format, optional) +When specified, the certificate will be pinned, and "Allow Insecure" will be disabled. + +The "Get Certificate" action may fail if a self-signed certificate is used or if the system contains an untrusted or malicious CA. Fetch Certificate @@ -1627,4 +1629,7 @@ Do not use the "Fetch Certificate" button when "Allow Insecure" is enabled. 自訂系統代理程式腳本檔案路徑 + + macOS 在 Dock 欄顯示 (需重啟) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs index 91f76ad9..76e90110 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs @@ -61,7 +61,7 @@ public partial class CoreConfigSingboxService } var tunInbound = JsonUtils.Deserialize(EmbedUtils.GetEmbedText(Global.TunSingboxInboundFileName)) ?? new Inbound4Sbox { }; - tunInbound.interface_name = Utils.IsOSX() ? $"utun{new Random().Next(99)}" : "singbox_tun"; + tunInbound.interface_name = Utils.IsMacOS() ? $"utun{new Random().Next(99)}" : "singbox_tun"; tunInbound.mtu = _config.TunModeItem.Mtu; tunInbound.auto_route = _config.TunModeItem.AutoRoute; tunInbound.strict_route = _config.TunModeItem.StrictRoute; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index 4db9d7cb..9671dc77 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -261,13 +261,7 @@ public partial class CoreConfigSingboxService } if (node.StreamSecurity == Global.StreamSecurity) { - var certs = node.Cert - ?.Split("-----END CERTIFICATE-----", StringSplitOptions.RemoveEmptyEntries) - .Select(s => s.TrimEx()) - .Where(s => !s.IsNullOrEmpty()) - .Select(s => s + "\n-----END CERTIFICATE-----") - .Select(s => s.Replace("\r\n", "\n")) - .ToList() ?? new(); + var certs = CertPemManager.ParsePemChain(node.Cert); if (certs.Count > 0) { tls.certificate = certs; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index 73a3a1fd..351c7bf0 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -245,13 +245,6 @@ public partial class CoreConfigV2rayService var host = node.RequestHost.TrimEx(); var path = node.Path.TrimEx(); var sni = node.Sni.TrimEx(); - var certs = node.Cert - ?.Split("-----END CERTIFICATE-----", StringSplitOptions.RemoveEmptyEntries) - .Select(s => s.TrimEx()) - .Where(s => !s.IsNullOrEmpty()) - .Select(s => s + "\n-----END CERTIFICATE-----") - .Select(s => s.Replace("\r\n", "\n")) - .ToList() ?? new(); var useragent = ""; if (!_config.CoreBasicItem.DefUserAgent.IsNullOrEmpty()) { @@ -284,6 +277,7 @@ public partial class CoreConfigV2rayService { tlsSettings.serverName = Utils.String2List(host)?.First(); } + var certs = CertPemManager.ParsePemChain(node.Cert); if (certs.Count > 0) { var certsettings = new List(); diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index b5129fc7..fc636c60 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -313,7 +313,7 @@ public class UpdateService(Config config, Func updateFunc) _ => null, }; } - else if (Utils.IsOSX()) + else if (Utils.IsMacOS()) { return RuntimeInformation.ProcessArchitecture switch { diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index 221d28d0..804287c5 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -2,8 +2,6 @@ namespace ServiceLib.ViewModels; public class AddServerViewModel : MyReactiveObject { - private string _certError = string.Empty; - [Reactive] public ProfileItem SelectedSource { get; set; } @@ -112,11 +110,11 @@ public class AddServerViewModel : MyReactiveObject } } - private void UpdateCertTip() + private void UpdateCertTip(string? errorMessage = null) { - CertTip = _certError.IsNullOrEmpty() + CertTip = errorMessage.IsNullOrEmpty() ? (Cert.IsNullOrEmpty() ? ResUI.CertNotSet : ResUI.CertSet) - : _certError; + : errorMessage; } private async Task FetchCert() @@ -137,17 +135,16 @@ public class AddServerViewModel : MyReactiveObject } if (!Utils.IsDomain(serverName)) { - _certError = ResUI.ServerNameMustBeValidDomain; - UpdateCertTip(); - _certError = string.Empty; + UpdateCertTip(ResUI.ServerNameMustBeValidDomain); return; } if (SelectedSource.Port > 0) { domain += $":{SelectedSource.Port}"; } - (Cert, _certError) = await CertPemManager.Instance.GetCertPemAsync(domain, serverName); - UpdateCertTip(); + string certError; + (Cert, certError) = await CertPemManager.Instance.GetCertPemAsync(domain, serverName); + UpdateCertTip(certError); } private async Task FetchCertChain() @@ -168,17 +165,16 @@ public class AddServerViewModel : MyReactiveObject } if (!Utils.IsDomain(serverName)) { - _certError = ResUI.ServerNameMustBeValidDomain; - UpdateCertTip(); - _certError = string.Empty; + UpdateCertTip(ResUI.ServerNameMustBeValidDomain); return; } if (SelectedSource.Port > 0) { domain += $":{SelectedSource.Port}"; } - (var certs, _certError) = await CertPemManager.Instance.GetCertChainPemAsync(domain, serverName); - UpdateCertTip(); - Cert = string.Join("\n", certs); + string certError; + (var certs, certError) = await CertPemManager.Instance.GetCertChainPemAsync(domain, serverName); + Cert = CertPemManager.ConcatenatePemChain(certs); + UpdateCertTip(certError); } } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index ad91fa02..c3bb0fe3 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -62,9 +62,9 @@ public class MainWindowViewModel : MyReactiveObject [Reactive] public int TabMainSelectedIndex { get; set; } - #endregion Menu + [Reactive] public bool BlIsWindows { get; set; } - private bool _hasNextReloadJob = false; + #endregion Menu #region Init @@ -72,6 +72,7 @@ public class MainWindowViewModel : MyReactiveObject { _config = AppManager.Instance.Config; _updateView = updateView; + BlIsWindows = Utils.IsWindows(); #region WhenAnyValue && ReactiveCommand @@ -268,7 +269,6 @@ public class MainWindowViewModel : MyReactiveObject } await RefreshServers(); - SetReloadEnabled(true); await Reload(); } @@ -514,7 +514,7 @@ public class MainWindowViewModel : MyReactiveObject { ProcUtils.ProcessStart("xdg-open", path); } - else if (Utils.IsOSX()) + else if (Utils.IsMacOS()) { ProcUtils.ProcessStart("open", path); } @@ -525,49 +525,59 @@ public class MainWindowViewModel : MyReactiveObject #region core job + private bool _hasNextReloadJob = false; + private readonly SemaphoreSlim _reloadSemaphore = new(1, 1); + public async Task Reload() { //If there are unfinished reload job, marked with next job. - if (!BlReloadEnabled) + if (!await _reloadSemaphore.WaitAsync(0)) { _hasNextReloadJob = true; return; } - SetReloadEnabled(false); - - var msgs = await ActionPrecheckManager.Instance.Check(_config.IndexId); - if (msgs.Count > 0) + try { - foreach (var msg in msgs) + SetReloadEnabled(false); + + var msgs = await ActionPrecheckManager.Instance.Check(_config.IndexId); + if (msgs.Count > 0) { - NoticeManager.Instance.SendMessage(msg); + foreach (var msg in msgs) + { + NoticeManager.Instance.SendMessage(msg); + } + NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true)); + return; } - NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true)); + + await Task.Run(async () => + { + await LoadCore(); + await SysProxyHandler.UpdateSysProxy(_config, false); + await Task.Delay(1000); + }); + AppEvents.TestServerRequested.Publish(); + + var showClashUI = _config.IsRunningCore(ECoreType.sing_box); + if (showClashUI) + { + AppEvents.ProxiesReloadRequested.Publish(); + } + + ReloadResult(showClashUI); + } + finally + { SetReloadEnabled(true); - return; - } - - await Task.Run(async () => - { - await LoadCore(); - await SysProxyHandler.UpdateSysProxy(_config, false); - await Task.Delay(1000); - }); - AppEvents.TestServerRequested.Publish(); - - var showClashUI = _config.IsRunningCore(ECoreType.sing_box); - if (showClashUI) - { - AppEvents.ProxiesReloadRequested.Publish(); - } - - ReloadResult(showClashUI); - SetReloadEnabled(true); - if (_hasNextReloadJob) - { - _hasNextReloadJob = false; - await Reload(); + _reloadSemaphore.Release(); + //If there is a next reload job, execute it. + if (_hasNextReloadJob) + { + _hasNextReloadJob = false; + await Reload(); + } } } diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index 81f63d00..73ec2681 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -50,6 +50,7 @@ public class OptionSettingViewModel : MyReactiveObject [Reactive] public bool EnableUpdateSubOnlyRemarksExist { get; set; } [Reactive] public bool AutoHideStartup { get; set; } [Reactive] public bool Hide2TrayWhenClose { get; set; } + [Reactive] public bool MacOSShowInDock { get; set; } [Reactive] public bool EnableDragDropSort { get; set; } [Reactive] public bool DoubleClick2Activate { get; set; } [Reactive] public int AutoUpdateInterval { get; set; } @@ -69,6 +70,15 @@ public class OptionSettingViewModel : MyReactiveObject #endregion UI + #region UI visibility + + [Reactive] public bool BlIsWindows { get; set; } + [Reactive] public bool BlIsLinux { get; set; } + [Reactive] public bool BlIsIsMacOS { get; set; } + [Reactive] public bool BlIsNonWindows { get; set; } + + #endregion UI visibility + #region System proxy [Reactive] public bool notProxyLocalAddress { get; set; } @@ -108,6 +118,10 @@ public class OptionSettingViewModel : MyReactiveObject { _config = AppManager.Instance.Config; _updateView = updateView; + BlIsWindows = Utils.IsWindows(); + BlIsLinux = Utils.IsLinux(); + BlIsIsMacOS = Utils.IsMacOS(); + BlIsNonWindows = Utils.IsNonWindows(); SaveCmd = ReactiveCommand.CreateFromTask(async () => { @@ -169,6 +183,7 @@ public class OptionSettingViewModel : MyReactiveObject EnableUpdateSubOnlyRemarksExist = _config.UiItem.EnableUpdateSubOnlyRemarksExist; AutoHideStartup = _config.UiItem.AutoHideStartup; Hide2TrayWhenClose = _config.UiItem.Hide2TrayWhenClose; + MacOSShowInDock = _config.UiItem.MacOSShowInDock; EnableDragDropSort = _config.UiItem.EnableDragDropSort; DoubleClick2Activate = _config.UiItem.DoubleClick2Activate; AutoUpdateInterval = _config.GuiItem.AutoUpdateInterval; @@ -330,6 +345,7 @@ public class OptionSettingViewModel : MyReactiveObject _config.UiItem.EnableUpdateSubOnlyRemarksExist = EnableUpdateSubOnlyRemarksExist; _config.UiItem.AutoHideStartup = AutoHideStartup; _config.UiItem.Hide2TrayWhenClose = Hide2TrayWhenClose; + _config.UiItem.MacOSShowInDock = MacOSShowInDock; _config.GuiItem.AutoUpdateInterval = AutoUpdateInterval; _config.UiItem.EnableDragDropSort = EnableDragDropSort; _config.UiItem.DoubleClick2Activate = DoubleClick2Activate; diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index b7c2a1e7..7617ac6f 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -504,7 +504,7 @@ public class StatusBarViewModel : MyReactiveObject { return AppManager.Instance.LinuxSudoPwd.IsNotEmpty(); } - else if (Utils.IsOSX()) + else if (Utils.IsMacOS()) { return AppManager.Instance.LinuxSudoPwd.IsNotEmpty(); } diff --git a/v2rayN/v2rayN.Desktop/Base/WindowBase.cs b/v2rayN/v2rayN.Desktop/Base/WindowBase.cs index 63b00036..d1419b30 100644 --- a/v2rayN/v2rayN.Desktop/Base/WindowBase.cs +++ b/v2rayN/v2rayN.Desktop/Base/WindowBase.cs @@ -26,7 +26,7 @@ public class WindowBase : ReactiveWindow where TViewMode Height = sizeItem.Height; var workingArea = (Screens.ScreenFromWindow(this) ?? Screens.Primary).WorkingArea; - var scaling = (Utils.IsOSX() ? null : VisualRoot?.RenderScaling) ?? 1.0; + var scaling = (Utils.IsMacOS() ? null : VisualRoot?.RenderScaling) ?? 1.0; var x = workingArea.X + ((workingArea.Width - (Width * scaling)) / 2); var y = workingArea.Y + ((workingArea.Height - (Height * scaling)) / 2); diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml index f01da56d..95c9891b 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml @@ -800,9 +800,11 @@ + Text="{x:Static resx:ResUI.TbCertPinningTips}" + TextWrapping="Wrap" />