diff --git a/v2rayN/ServiceLib/Enums/EMsgCommand.cs b/v2rayN/ServiceLib/Enums/EMsgCommand.cs index 31d7556f..c955e830 100644 --- a/v2rayN/ServiceLib/Enums/EMsgCommand.cs +++ b/v2rayN/ServiceLib/Enums/EMsgCommand.cs @@ -5,6 +5,7 @@ ClearMsg, SendMsgView, SendSnackMsg, - RefreshProfiles + RefreshProfiles, + StopSpeedtest } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index 61bfd7c1..d8411903 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -1,7 +1,7 @@ -using System.Diagnostics; +using ReactiveUI; +using System.Diagnostics; using System.Net; using System.Net.Sockets; - namespace ServiceLib.Services { public class SpeedtestService @@ -80,10 +80,12 @@ namespace ServiceLib.Services Task.Run(RunMixedtestAsync); break; } + MessageBus.Current.Listen(EMsgCommand.StopSpeedtest.ToString()).Subscribe(ExitLoop); } - public void ExitLoop() + private void ExitLoop(string x) { + if(_exitLoop) return; _exitLoop = true; UpdateFunc("", ResUI.SpeedtestingStop); } diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 5a430a9c..1a8e8d64 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -6,12 +6,10 @@ namespace ServiceLib.Services public class UpdateService { private Action? _updateFunc; - private Config _config; private int _timeout = 30; public async Task CheckUpdateGuiN(Config config, Action updateFunc, bool preRelease) { - _config = config; _updateFunc = updateFunc; var url = string.Empty; var fileName = string.Empty; @@ -53,7 +51,6 @@ namespace ServiceLib.Services public async Task CheckUpdateCore(ECoreType type, Config config, Action updateFunc, bool preRelease) { - _config = config; _updateFunc = updateFunc; var url = string.Empty; var fileName = string.Empty; @@ -108,7 +105,6 @@ namespace ServiceLib.Services public async Task UpdateSubscriptionProcess(Config config, string subId, bool blProxy, Action updateFunc) { - _config = config; _updateFunc = updateFunc; _updateFunc?.Invoke(false, ResUI.MsgUpdateSubscriptionStart); @@ -454,7 +450,6 @@ namespace ServiceLib.Services private async Task UpdateGeoFile(string geoName, Config config, Action updateFunc) { - _config = config; _updateFunc = updateFunc; var geoUrl = string.IsNullOrEmpty(config?.ConstItem.GeoSourceUrl) @@ -470,7 +465,6 @@ namespace ServiceLib.Services private async Task UpdateSrsFileAll(Config config, Action updateFunc) { - _config = config; _updateFunc = updateFunc; var geoipFiles = new List(); @@ -521,9 +515,9 @@ namespace ServiceLib.Services private async Task UpdateSrsFile(string type, string srsName, Config config, Action updateFunc) { - var srsUrl = string.IsNullOrEmpty(_config.ConstItem.SrsSourceUrl) + var srsUrl = string.IsNullOrEmpty(config.ConstItem.SrsSourceUrl) ? Global.SingboxRulesetUrl - : _config.ConstItem.SrsSourceUrl; + : config.ConstItem.SrsSourceUrl; var fileName = $"{type}-{srsName}.srs"; var targetPath = Path.Combine(Utils.GetBinPath("srss"), fileName); diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 8249d6e8..66d38ddc 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -16,7 +16,6 @@ namespace ServiceLib.ViewModels private List _lstProfile; private string _serverFilter = string.Empty; private Dictionary _dicHeaderSort = new(); - private SpeedtestService? _speedtestHandler; #endregion private prop @@ -686,12 +685,13 @@ namespace ServiceLib.ViewModels } //ClearTestResult(); - _speedtestHandler = new SpeedtestService(_config, lstSelecteds, actionType, UpdateSpeedtestHandler); + _ = new SpeedtestService(_config, lstSelecteds, actionType, UpdateSpeedtestHandler); + } public void ServerSpeedtestStop() { - _speedtestHandler?.ExitLoop(); + MessageBus.Current.SendMessage("", EMsgCommand.StopSpeedtest.ToString()); } private async Task Export2ClientConfigAsync(bool blClipboard) diff --git a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml index 4ff25dcb..99dd5121 100644 --- a/v2rayN/v2rayN.Desktop/Views/MsgView.axaml +++ b/v2rayN/v2rayN.Desktop/Views/MsgView.axaml @@ -83,6 +83,7 @@ Classes="TextArea" IsReadOnly="True" TextAlignment="Left" + VerticalAlignment="Stretch" TextWrapping="Wrap"> diff --git a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj index fcdf3e0d..8ab9c55f 100644 --- a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj +++ b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj @@ -20,16 +20,16 @@ - - - - - - + + + + + + - - + +