diff --git a/.github/workflows/winget-publish.yml b/.github/workflows/winget-publish.yml new file mode 100644 index 00000000..391b61e7 --- /dev/null +++ b/.github/workflows/winget-publish.yml @@ -0,0 +1,31 @@ +name: WinGet submission on release +# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml +# inspired by https://github.com/microsoft/PowerToys/blob/main/.github/workflows/package-submissions.yml +# Modified by @MerrickZ https://github.com/anpho + +on: + workflow_dispatch: + release: + types: [released] + +jobs: + winget: + name: Publish winget package + runs-on: windows-latest + steps: + - name: Submit v2ray package to Windows Package Manager Community Repository + run: | + + $wingetPackage = "2dust.v2rayN" + $gitToken = "${{ secrets.PT_WINGET }}" + + $github = Invoke-RestMethod -uri "https://api.github.com/repos/2dust/v2rayN/releases" + + $targetRelease = $github | Where-Object -Property prerelease -match 'False' | Select -First 1 + $installerUrl = $targetRelease | Select -ExpandProperty assets -First 1 | Where-Object -Property name -match 'v2rayN-windows-64-With-Core\.zip*' | Select -ExpandProperty browser_download_url + + $ver = $targetRelease.tag_name + + # getting latest wingetcreate file + iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe + .\wingetcreate.exe update $wingetPackage -s -v $ver -u "$installerUrl|x64" -t $gitToken diff --git a/v2rayN/ServiceLib/Common/SemanticVersion.cs b/v2rayN/ServiceLib/Common/SemanticVersion.cs index fd236c89..0a5bd5b9 100644 --- a/v2rayN/ServiceLib/Common/SemanticVersion.cs +++ b/v2rayN/ServiceLib/Common/SemanticVersion.cs @@ -31,8 +31,8 @@ var parts = this.version.Split('.'); if (parts.Length == 2) { - this.major = int.Parse(parts[0]); - this.minor = int.Parse(parts[1]); + this.major = int.Parse(parts.First()); + this.minor = int.Parse(parts.Last()); this.patch = 0; } else if (parts.Length is 3 or 4) diff --git a/v2rayN/ServiceLib/Common/StringEx.cs b/v2rayN/ServiceLib/Common/StringEx.cs index 81965ada..c0d0a8cc 100644 --- a/v2rayN/ServiceLib/Common/StringEx.cs +++ b/v2rayN/ServiceLib/Common/StringEx.cs @@ -22,7 +22,7 @@ namespace ServiceLib.Common public static bool BeginWithAny(this string s, IEnumerable chars) { if (s.IsNullOrEmpty()) return false; - return chars.Contains(s[0]); + return chars.Contains(s.First()); } private static bool IsWhiteSpace(this string value) @@ -61,7 +61,7 @@ namespace ServiceLib.Common return string.Empty; } - return char.ToUpper(value[0]) + value[1..]; + return char.ToUpper(value.First()) + value[1..]; } public static string AppendQuotes(this string value) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index c5bf085a..05efe27a 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -313,8 +313,8 @@ namespace ServiceLib.Common continue; } - var key = Uri.UnescapeDataString(keyValue[0]); - var val = Uri.UnescapeDataString(keyValue[1]); + var key = Uri.UnescapeDataString(keyValue.First()); + var val = Uri.UnescapeDataString(keyValue.Last()); if (result[key] is null) { @@ -622,8 +622,8 @@ namespace ServiceLib.Common { if (host.StartsWith("#")) continue; var hostItem = host.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); - if (hostItem.Length < 2) continue; - systemHosts.Add(hostItem[1], hostItem[0]); + if (hostItem.Length != 2) continue; + systemHosts.Add(hostItem.Last(), hostItem.First()); } } } diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 620a8bc1..d7079097 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -62,7 +62,7 @@ namespace ServiceLib.Handler { if (config.Inbound.Count > 0) { - config.Inbound[0].Protocol = EInboundProtocol.socks.ToString(); + config.Inbound.First().Protocol = EInboundProtocol.socks.ToString(); } } @@ -70,7 +70,7 @@ namespace ServiceLib.Handler if (Utils.IsNullOrEmpty(config.RoutingBasicItem.DomainStrategy)) { - config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies[0];//"IPIfNonMatch"; + config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First();//"IPIfNonMatch"; } config.KcpItem ??= new KcpItem @@ -111,7 +111,7 @@ namespace ServiceLib.Handler { if (Thread.CurrentThread.CurrentCulture.Name.Equals("zh-cn", StringComparison.CurrentCultureIgnoreCase)) { - config.UiItem.CurrentLanguage = Global.Languages[0]; + config.UiItem.CurrentLanguage = Global.Languages.First(); } else { @@ -132,7 +132,7 @@ namespace ServiceLib.Handler } if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedTestUrl)) { - config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls[0]; + config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First(); } if (Utils.IsNullOrEmpty(config.SpeedTestItem.SpeedPingTestUrl)) { @@ -148,7 +148,7 @@ namespace ServiceLib.Handler config.Mux4SboxItem ??= new() { - Protocol = Global.SingboxMuxs[0], + Protocol = Global.SingboxMuxs.First(), MaxConnections = 8 }; @@ -429,7 +429,7 @@ namespace ServiceLib.Handler { return 0; } - sort = ProfileExHandler.Instance.GetSort(lstProfile[0].IndexId) - 1; + sort = ProfileExHandler.Instance.GetSort(lstProfile.First().IndexId) - 1; break; } diff --git a/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs index 1a697eb9..f9028c44 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs @@ -99,8 +99,8 @@ namespace ServiceLib.Handler.Fmt { return null; } - item.Security = userInfoParts[0]; - item.Id = Utils.UrlDecode(userInfoParts[1]); + item.Security = userInfoParts.First(); + item.Id = Utils.UrlDecode(userInfoParts.Last()); } else { @@ -111,8 +111,8 @@ namespace ServiceLib.Handler.Fmt { return null; } - item.Security = userInfoParts[0]; - item.Id = userInfoParts[1]; + item.Security = userInfoParts.First(); + item.Id = userInfoParts.Last(); } var queryParameters = Utils.ParseQueryString(parsedUrl.Query); diff --git a/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs index 1478d170..250f39e4 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs @@ -5,9 +5,8 @@ public static ProfileItem? Resolve(string str, out string msg) { msg = ResUI.ConfigurationFormatIncorrect; - ProfileItem? item; - item = ResolveSocksNew(str) ?? ResolveSocks(str); + var item = ResolveSocksNew(str) ?? ResolveSocks(str); if (item == null) { return null; @@ -25,19 +24,13 @@ public static string? ToUri(ProfileItem? item) { if (item == null) return null; - string url = string.Empty; + var url = string.Empty; - string remark = string.Empty; + var remark = string.Empty; if (Utils.IsNotEmpty(item.Remarks)) { remark = "#" + Utils.UrlEncode(item.Remarks); } - //url = string.Format("{0}:{1}@{2}:{3}", - // item.security, - // item.id, - // item.address, - // item.port); - //url = Utile.Base64Encode(url); //new var pw = Utils.Base64Encode($"{item.Security}:{item.Id}"); return ToUri(EConfigType.SOCKS, item.Address, item.Port, pw, null, remark); @@ -51,7 +44,7 @@ }; result = result[Global.ProtocolShares[EConfigType.SOCKS].Length..]; //remark - int indexRemark = result.IndexOf("#"); + var indexRemark = result.IndexOf("#"); if (indexRemark > 0) { try @@ -62,7 +55,7 @@ result = result[..indexRemark]; } //part decode - int indexS = result.IndexOf("@"); + var indexS = result.IndexOf("@"); if (indexS > 0) { } @@ -71,21 +64,20 @@ result = Utils.Base64Decode(result); } - string[] arr1 = result.Split('@'); + var arr1 = result.Split('@'); if (arr1.Length != 2) { return null; } - string[] arr21 = arr1[0].Split(':'); - //string[] arr22 = arr1[1].Split(':'); - int indexPort = arr1[1].LastIndexOf(":"); + var arr21 = arr1.First().Split(':'); + var indexPort = arr1.Last().LastIndexOf(":"); if (arr21.Length != 2 || indexPort < 0) { return null; } item.Address = arr1[1][..indexPort]; item.Port = Utils.ToInt(arr1[1][(indexPort + 1)..]); - item.Security = arr21[0]; + item.Security = arr21.First(); item.Id = arr21[1]; return item; @@ -106,10 +98,10 @@ // parse base64 UserInfo var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo); var userInfo = Utils.Base64Decode(rawUserInfo); - var userInfoParts = userInfo.Split(new[] { ':' }, 2); + var userInfoParts = userInfo.Split([':'], 2); if (userInfoParts.Length == 2) { - item.Security = userInfoParts[0]; + item.Security = userInfoParts.First(); item.Id = userInfoParts[1]; } diff --git a/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs index e5ed4577..4783716a 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs @@ -21,8 +21,8 @@ var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2); if (userInfoParts.Length == 2) { - item.Id = userInfoParts[0]; - item.Security = userInfoParts[1]; + item.Id = userInfoParts.First(); + item.Security = userInfoParts.Last(); } var query = Utils.ParseQueryString(url.Query); diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index 75943e2a..e7b8f079 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -222,7 +222,6 @@ public int ProxiesSorting { get; set; } public bool ProxiesAutoRefresh { get; set; } public int ProxiesAutoDelayTestInterval { get; set; } = 10; - public int ConnectionsSorting { get; set; } public bool ConnectionsAutoRefresh { get; set; } public int ConnectionsRefreshInterval { get; set; } = 2; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs index bb9e81d4..ca820d91 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs @@ -88,7 +88,7 @@ namespace ServiceLib.Services.CoreConfig //external-controller fileContent["external-controller"] = $"{Global.Loopback}:{AppHandler.Instance.StatePort2}"; //allow-lan - if (_config.Inbound[0].AllowLANConn) + if (_config.Inbound.First().AllowLANConn) { fileContent["allow-lan"] = "true"; fileContent["bind-address"] = "*"; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 3cdcbe3d..4ee4ff71 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -52,7 +52,7 @@ namespace ServiceLib.Services.CoreConfig await GenInbounds(singboxConfig); - await GenOutbound(node, singboxConfig.outbounds[0]); + await GenOutbound(node, singboxConfig.outbounds.First()); await GenMoreOutbounds(node, singboxConfig); @@ -495,8 +495,8 @@ namespace ServiceLib.Services.CoreConfig singboxConfig.inbounds.Add(inbound); inbound.listen_port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); - inbound.sniff = _config.Inbound[0].SniffingEnabled; - inbound.sniff_override_destination = _config.Inbound[0].RouteOnly ? false : _config.Inbound[0].SniffingEnabled; + inbound.sniff = _config.Inbound.First().SniffingEnabled; + inbound.sniff_override_destination = _config.Inbound.First().RouteOnly ? false : _config.Inbound.First().SniffingEnabled; inbound.domain_strategy = Utils.IsNullOrEmpty(_config.RoutingBasicItem.DomainStrategy4Singbox) ? null : _config.RoutingBasicItem.DomainStrategy4Singbox; var routing = await ConfigHandler.GetDefaultRouting(_config); @@ -509,9 +509,9 @@ namespace ServiceLib.Services.CoreConfig var inbound2 = GetInbound(inbound, EInboundProtocol.http, false); singboxConfig.inbounds.Add(inbound2); - if (_config.Inbound[0].AllowLANConn) + if (_config.Inbound.First().AllowLANConn) { - if (_config.Inbound[0].NewPort4LAN) + if (_config.Inbound.First().NewPort4LAN) { var inbound3 = GetInbound(inbound, EInboundProtocol.socks2, true); inbound3.listen = listen; @@ -522,10 +522,10 @@ namespace ServiceLib.Services.CoreConfig singboxConfig.inbounds.Add(inbound4); //auth - if (Utils.IsNotEmpty(_config.Inbound[0].User) && Utils.IsNotEmpty(_config.Inbound[0].Pass)) + if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass)) { - inbound3.users = new() { new() { username = _config.Inbound[0].User, password = _config.Inbound[0].Pass } }; - inbound4.users = new() { new() { username = _config.Inbound[0].User, password = _config.Inbound[0].Pass } }; + inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } }; + inbound4.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } }; } } else @@ -540,11 +540,11 @@ namespace ServiceLib.Services.CoreConfig { if (_config.TunModeItem.Mtu <= 0) { - _config.TunModeItem.Mtu = Utils.ToInt(Global.TunMtus[0]); + _config.TunModeItem.Mtu = Utils.ToInt(Global.TunMtus.First()); } if (Utils.IsNullOrEmpty(_config.TunModeItem.Stack)) { - _config.TunModeItem.Stack = Global.TunStacks[0]; + _config.TunModeItem.Stack = Global.TunStacks.First(); } var tunInbound = JsonUtils.Deserialize(Utils.GetEmbedText(Global.TunSingboxInboundFileName)) ?? new Inbound4Sbox { }; @@ -552,8 +552,8 @@ namespace ServiceLib.Services.CoreConfig tunInbound.mtu = _config.TunModeItem.Mtu; tunInbound.strict_route = _config.TunModeItem.StrictRoute; tunInbound.stack = _config.TunModeItem.Stack; - tunInbound.sniff = _config.Inbound[0].SniffingEnabled; - //tunInbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled; + tunInbound.sniff = _config.Inbound.First().SniffingEnabled; + //tunInbound.sniff_override_destination = _config.inbound.First().routeOnly ? false : _config.inbound.First().sniffingEnabled; if (_config.TunModeItem.EnableIPv6Address == false) { tunInbound.address = ["172.18.0.1/30"]; @@ -867,7 +867,7 @@ namespace ServiceLib.Services.CoreConfig } //current proxy - var outbound = singboxConfig.outbounds[0]; + var outbound = singboxConfig.outbounds.First(); var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound); //Previous proxy @@ -910,7 +910,7 @@ namespace ServiceLib.Services.CoreConfig try { var dnsOutbound = "dns_out"; - if (!_config.Inbound[0].SniffingEnabled) + if (!_config.Inbound.First().SniffingEnabled) { singboxConfig.route.rules.Add(new() { diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs index f03be85e..ca7e53b6 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs @@ -55,7 +55,7 @@ namespace ServiceLib.Services.CoreConfig await GenRouting(v2rayConfig); - await GenOutbound(node, v2rayConfig.outbounds[0]); + await GenOutbound(node, v2rayConfig.outbounds.First()); await GenMoreOutbounds(node, v2rayConfig); @@ -391,33 +391,33 @@ namespace ServiceLib.Services.CoreConfig var listen = "0.0.0.0"; v2rayConfig.inbounds = []; - Inbounds4Ray? inbound = GetInbound(_config.Inbound[0], EInboundProtocol.socks, true); + Inbounds4Ray? inbound = GetInbound(_config.Inbound.First(), EInboundProtocol.socks, true); v2rayConfig.inbounds.Add(inbound); //http - Inbounds4Ray? inbound2 = GetInbound(_config.Inbound[0], EInboundProtocol.http, false); + Inbounds4Ray? inbound2 = GetInbound(_config.Inbound.First(), EInboundProtocol.http, false); v2rayConfig.inbounds.Add(inbound2); - if (_config.Inbound[0].AllowLANConn) + if (_config.Inbound.First().AllowLANConn) { - if (_config.Inbound[0].NewPort4LAN) + if (_config.Inbound.First().NewPort4LAN) { - var inbound3 = GetInbound(_config.Inbound[0], EInboundProtocol.socks2, true); + var inbound3 = GetInbound(_config.Inbound.First(), EInboundProtocol.socks2, true); inbound3.listen = listen; v2rayConfig.inbounds.Add(inbound3); - var inbound4 = GetInbound(_config.Inbound[0], EInboundProtocol.http2, false); + var inbound4 = GetInbound(_config.Inbound.First(), EInboundProtocol.http2, false); inbound4.listen = listen; v2rayConfig.inbounds.Add(inbound4); //auth - if (Utils.IsNotEmpty(_config.Inbound[0].User) && Utils.IsNotEmpty(_config.Inbound[0].Pass)) + if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass)) { inbound3.settings.auth = "password"; - inbound3.settings.accounts = new List { new AccountsItem4Ray() { user = _config.Inbound[0].User, pass = _config.Inbound[0].Pass } }; + inbound3.settings.accounts = new List { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } }; inbound4.settings.auth = "password"; - inbound4.settings.accounts = new List { new AccountsItem4Ray() { user = _config.Inbound[0].User, pass = _config.Inbound[0].Pass } }; + inbound4.settings.accounts = new List { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } }; } } else @@ -587,7 +587,7 @@ namespace ServiceLib.Services.CoreConfig } else { - vnextItem = outbound.settings.vnext[0]; + vnextItem = outbound.settings.vnext.First(); } vnextItem.address = node.Address; vnextItem.port = node.Port; @@ -600,7 +600,7 @@ namespace ServiceLib.Services.CoreConfig } else { - usersItem = vnextItem.users[0]; + usersItem = vnextItem.users.First(); } //远程服务器用户ID usersItem.id = node.Id; @@ -630,7 +630,7 @@ namespace ServiceLib.Services.CoreConfig } else { - serversItem = outbound.settings.servers[0]; + serversItem = outbound.settings.servers.First(); } serversItem.address = node.Address; serversItem.port = node.Port; @@ -656,7 +656,7 @@ namespace ServiceLib.Services.CoreConfig } else { - serversItem = outbound.settings.servers[0]; + serversItem = outbound.settings.servers.First(); } serversItem.address = node.Address; serversItem.port = node.Port; @@ -691,7 +691,7 @@ namespace ServiceLib.Services.CoreConfig } else { - vnextItem = outbound.settings.vnext[0]; + vnextItem = outbound.settings.vnext.First(); } vnextItem.address = node.Address; vnextItem.port = node.Port; @@ -704,7 +704,7 @@ namespace ServiceLib.Services.CoreConfig } else { - usersItem = vnextItem.users[0]; + usersItem = vnextItem.users.First(); } usersItem.id = node.Id; usersItem.email = Global.UserEMail; @@ -740,7 +740,7 @@ namespace ServiceLib.Services.CoreConfig } else { - serversItem = outbound.settings.servers[0]; + serversItem = outbound.settings.servers.First(); } serversItem.address = node.Address; serversItem.port = node.Port; @@ -1167,7 +1167,7 @@ namespace ServiceLib.Services.CoreConfig { //fragment proxy if (_config.CoreBasicItem.EnableFragment - && Utils.IsNotEmpty(v2rayConfig.outbounds[0].streamSettings?.security)) + && Utils.IsNotEmpty(v2rayConfig.outbounds.First().streamSettings?.security)) { var fragmentOutbound = new Outbounds4Ray { @@ -1185,7 +1185,7 @@ namespace ServiceLib.Services.CoreConfig }; v2rayConfig.outbounds.Add(fragmentOutbound); - v2rayConfig.outbounds[0].streamSettings.sockopt = new() + v2rayConfig.outbounds.First().streamSettings.sockopt = new() { dialerProxy = fragmentOutbound.tag }; @@ -1205,7 +1205,7 @@ namespace ServiceLib.Services.CoreConfig } //current proxy - var outbound = v2rayConfig.outbounds[0]; + var outbound = v2rayConfig.outbounds.First(); var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); //Previous proxy diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index d0fdd775..41dbc02e 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -348,7 +348,7 @@ namespace ServiceLib.Services if (!IPAddress.TryParse(url, out IPAddress? ipAddress)) { IPHostEntry ipHostInfo = Dns.GetHostEntry(url); - ipAddress = ipHostInfo.AddressList[0]; + ipAddress = ipHostInfo.AddressList.First(); } var timer = Stopwatch.StartNew(); diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index e60ddbb9..f9b8cbda 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -21,9 +21,6 @@ namespace ServiceLib.ViewModels [Reactive] public string HostFilter { get; set; } - [Reactive] - public int SortingSelected { get; set; } - [Reactive] public bool AutoRefresh { get; set; } @@ -31,18 +28,12 @@ namespace ServiceLib.ViewModels { _config = AppHandler.Instance.Config; _updateView = updateView; - SortingSelected = _config.ClashUIItem.ConnectionsSorting; AutoRefresh = _config.ClashUIItem.ConnectionsAutoRefresh; var canEditRemove = this.WhenAnyValue( x => x.SelectedSource, selectedSource => selectedSource != null && Utils.IsNotEmpty(selectedSource.Id)); - this.WhenAnyValue( - x => x.SortingSelected, - y => y >= 0) - .Subscribe(async c => await DoSortingSelected(c)); - this.WhenAnyValue( x => x.AutoRefresh, y => y == true) @@ -84,20 +75,6 @@ namespace ServiceLib.ViewModels }); } - private async Task DoSortingSelected(bool c) - { - if (!c) - { - return; - } - if (SortingSelected != _config.ClashUIItem.ConnectionsSorting) - { - _config.ClashUIItem.ConnectionsSorting = SortingSelected; - } - - await GetClashConnections(); - } - private async Task GetClashConnections() { var ret = await ClashApiHandler.Instance.GetClashConnectionsAsync(_config); @@ -115,7 +92,7 @@ namespace ServiceLib.ViewModels var dtNow = DateTime.Now; var lstModel = new List(); - foreach (var item in connections ?? []) + foreach (var item in connections ?? new()) { var host = $"{(Utils.IsNullOrEmpty(item.metadata.host) ? item.metadata.destinationIP : item.metadata.host)}:{item.metadata.destinationPort}"; if (HostFilter.IsNotEmpty() && !host.Contains(HostFilter)) @@ -131,45 +108,14 @@ namespace ServiceLib.ViewModels model.Host = host; var sp = (dtNow - item.start); model.Time = sp.TotalSeconds < 0 ? 1 : sp.TotalSeconds; - model.Upload = item.upload; - model.Download = item.download; - model.UploadTraffic = $"{Utils.HumanFy((long)item.upload)}"; - model.DownloadTraffic = $"{Utils.HumanFy((long)item.download)}"; model.Elapsed = sp.ToString(@"hh\:mm\:ss"); - model.Chain = item.chains?.Count > 0 ? item.chains[0] : string.Empty; + item.chains?.Reverse(); + model.Chain = $"{item.rule} , {string.Join("->", item.chains ?? new())}"; lstModel.Add(model); } if (lstModel.Count <= 0) { return; } - //sort - switch (SortingSelected) - { - case 0: - lstModel = lstModel.OrderBy(t => t.Upload / t.Time).ToList(); - break; - - case 1: - lstModel = lstModel.OrderBy(t => t.Download / t.Time).ToList(); - break; - - case 2: - lstModel = lstModel.OrderBy(t => t.Upload).ToList(); - break; - - case 3: - lstModel = lstModel.OrderBy(t => t.Download).ToList(); - break; - - case 4: - lstModel = lstModel.OrderBy(t => t.Time).ToList(); - break; - - case 5: - lstModel = lstModel.OrderBy(t => t.Host).ToList(); - break; - } - _connectionItems.AddRange(lstModel); } diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 316e066d..3d1c82fa 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -239,7 +239,7 @@ namespace ServiceLib.ViewModels } else { - SelectedGroup = _proxyGroups[0]; + SelectedGroup = _proxyGroups.First(); } } else diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index 1a8de48a..c07001f3 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -122,7 +122,7 @@ namespace ServiceLib.ViewModels #region Core - var inbound = _config.Inbound[0]; + var inbound = _config.Inbound.First(); localPort = inbound.LocalPort; udpEnabled = inbound.UdpEnabled; sniffingEnabled = inbound.SniffingEnabled; @@ -285,15 +285,15 @@ namespace ServiceLib.ViewModels //} //Core - _config.Inbound[0].LocalPort = localPort; - _config.Inbound[0].UdpEnabled = udpEnabled; - _config.Inbound[0].SniffingEnabled = sniffingEnabled; - _config.Inbound[0].DestOverride = destOverride?.ToList(); - _config.Inbound[0].RouteOnly = routeOnly; - _config.Inbound[0].AllowLANConn = allowLANConn; - _config.Inbound[0].NewPort4LAN = newPort4LAN; - _config.Inbound[0].User = user; - _config.Inbound[0].Pass = pass; + _config.Inbound.First().LocalPort = localPort; + _config.Inbound.First().UdpEnabled = udpEnabled; + _config.Inbound.First().SniffingEnabled = sniffingEnabled; + _config.Inbound.First().DestOverride = destOverride?.ToList(); + _config.Inbound.First().RouteOnly = routeOnly; + _config.Inbound.First().AllowLANConn = allowLANConn; + _config.Inbound.First().NewPort4LAN = newPort4LAN; + _config.Inbound.First().User = user; + _config.Inbound.First().Pass = pass; if (_config.Inbound.Count > 1) { _config.Inbound.RemoveAt(1); diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index b4a2f982..dc87be16 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -374,7 +374,7 @@ namespace ServiceLib.ViewModels } else { - SelectedProfile = lstModel[0]; + SelectedProfile = lstModel.First(); } } } @@ -395,7 +395,7 @@ namespace ServiceLib.ViewModels } else { - SelectedSub = _subItems[0]; + SelectedSub = _subItems.First(); } } diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index dc9742d5..656f74c0 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -456,9 +456,9 @@ namespace ServiceLib.ViewModels sb.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http)}]"); InboundDisplay = $"{ResUI.LabLocal}:{sb}"; - if (_config.Inbound[0].AllowLANConn) + if (_config.Inbound.First().AllowLANConn) { - if (_config.Inbound[0].NewPort4LAN) + if (_config.Inbound.First().NewPort4LAN) { StringBuilder sb2 = new(); sb2.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks2)}]"); diff --git a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml index cbf48f38..dd1c94ac 100644 --- a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml +++ b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml @@ -25,22 +25,6 @@ VerticalContentAlignment="Center" Watermark="{x:Static resx:ResUI.ConnectionsHostFilterTitle}" /> - - - - - - - - - -