From 5ff4d35a305654a9f4d5cae30b267f17c3c9e56d Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 25 Feb 2024 18:28:59 +0800 Subject: [PATCH] Added termination speed test --- v2rayN/v2rayN/Global.cs | 2 ++ v2rayN/v2rayN/Handler/NoticeHandler.cs | 4 +-- v2rayN/v2rayN/Handler/SpeedtestHandler.cs | 36 ++++++++++++++++++++++- v2rayN/v2rayN/Resx/ResUI.Designer.cs | 29 +++++++++++------- v2rayN/v2rayN/Resx/ResUI.resx | 5 +++- v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 5 +++- v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx | 5 +++- v2rayN/v2rayN/Views/MainWindow.xaml.cs | 10 +++++-- v2rayN/v2rayN/Views/MsgView.xaml.cs | 2 +- 9 files changed, 78 insertions(+), 20 deletions(-) diff --git a/v2rayN/v2rayN/Global.cs b/v2rayN/v2rayN/Global.cs index d85ffd7c..690d2985 100644 --- a/v2rayN/v2rayN/Global.cs +++ b/v2rayN/v2rayN/Global.cs @@ -78,6 +78,8 @@ namespace v2rayN public const string GrpcMultiMode = "multi"; public const int MaxPort = 65536; public const string CommandClearMsg = "CommandClearMsg"; + public const string CommandSendMsgView = "CommandSendMsgView"; + public const string CommandStopSpeedTest = "CommandStopSpeedTest"; public const string DelayUnit = ""; public const string SpeedUnit = ""; public const int MinFontSize = 10; diff --git a/v2rayN/v2rayN/Handler/NoticeHandler.cs b/v2rayN/v2rayN/Handler/NoticeHandler.cs index f74f8e65..3402bf42 100644 --- a/v2rayN/v2rayN/Handler/NoticeHandler.cs +++ b/v2rayN/v2rayN/Handler/NoticeHandler.cs @@ -21,13 +21,13 @@ namespace v2rayN.Handler public void SendMessage(string msg) { - MessageBus.Current.SendMessage(msg, "MsgView"); + MessageBus.Current.SendMessage(msg, Global.CommandSendMsgView); } public void SendMessage(string msg, bool time) { msg = $"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} {msg}"; - MessageBus.Current.SendMessage(msg, "MsgView"); + MessageBus.Current.SendMessage(msg, Global.CommandSendMsgView); } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs index b5ad1b81..db5ac6b4 100644 --- a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs +++ b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using ReactiveUI; +using System.Diagnostics; using System.Net; using System.Net.Sockets; using v2rayN.Model; @@ -213,8 +214,24 @@ namespace v2rayN.Handler DownloadHandle downloadHandle = new(); + var exitLoop = false; + MessageBus.Current.Listen(Global.CommandStopSpeedTest) + .Subscribe(x => + { + if (!exitLoop) + { + UpdateFunc("", ResUI.SpeedtestingStop); + } + exitLoop = true; + }); + foreach (var it in _selecteds) { + if (exitLoop) + { + UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip); + continue; + } if (!it.allowTest) { continue; @@ -270,8 +287,25 @@ namespace v2rayN.Handler DownloadHandle downloadHandle = new(); + var exitLoop = false; + MessageBus.Current.Listen(Global.CommandStopSpeedTest) + .Subscribe(x => + { + if (!exitLoop) + { + UpdateFunc("", ResUI.SpeedtestingStop); + } + exitLoop = true; + }); + foreach (var it in _selecteds) { + if (exitLoop) + { + UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip); + continue; + } + if (!it.allowTest) { continue; diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index da7c8307..b824e6dc 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -916,7 +916,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Clear All 的本地化字符串。 + /// 查找类似 Clear all 的本地化字符串。 /// public static string menuMsgViewClear { get { @@ -934,7 +934,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Copy All 的本地化字符串。 + /// 查找类似 Copy all 的本地化字符串。 /// public static string menuMsgViewCopyAll { get { @@ -952,7 +952,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Select All (Ctrl+A) 的本地化字符串。 + /// 查找类似 Select all (Ctrl+A) 的本地化字符串。 /// public static string menuMsgViewSelectAll { get { @@ -1123,7 +1123,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Rule Add 的本地化字符串。 + /// 查找类似 Add Rule 的本地化字符串。 /// public static string menuRuleAdd { get { @@ -1150,7 +1150,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Remove Rules (Delete) 的本地化字符串。 + /// 查找类似 Remove Rule (Delete) 的本地化字符串。 /// public static string menuRuleRemove { get { @@ -1159,7 +1159,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Select All (Ctrl+A) 的本地化字符串。 + /// 查找类似 Select all (Ctrl+A) 的本地化字符串。 /// public static string menuSelectAll { get { @@ -1339,7 +1339,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Pac Mode 的本地化字符串。 + /// 查找类似 PAC mode 的本地化字符串。 /// public static string menuSystemProxyPac { get { @@ -1780,7 +1780,16 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Waiting for testing...... 的本地化字符串。 + /// 查找类似 Test terminating... 的本地化字符串。 + /// + public static string SpeedtestingStop { + get { + return ResourceManager.GetString("SpeedtestingStop", resourceCulture); + } + } + + /// + /// 查找类似 Waiting for testing (press ESC to terminate)... 的本地化字符串。 /// public static string SpeedtestingWait { get { @@ -2078,7 +2087,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Set directly by pressing the keyboard, Take effect after restart 的本地化字符串。 + /// 查找类似 Set directly by pressing the keyboard, take effect after restart 的本地化字符串。 /// public static string TbGlobalHotkeySettingTip { get { @@ -3086,7 +3095,7 @@ namespace v2rayN.Resx { } /// - /// 查找类似 Pac Mode 的本地化字符串。 + /// 查找类似 PAC mode 的本地化字符串。 /// public static string TbSystemProxyPac { get { diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index e28d3a6d..d52d52c9 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1079,7 +1079,7 @@ Enable hardware acceleration(Require restart) - Waiting for testing...... + Waiting for testing (press ESC to terminate)... Please turn off when there is an abnormal disconnection @@ -1192,4 +1192,7 @@ Updating subscription, only determine remarks exists + + Test terminating... + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index f1a1fb7f..f654a0e1 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1079,7 +1079,7 @@ 启用硬件加速(需重启) - 等待测试中...... + 等待测试中(按ESC终止)... 当有异常断流时请关闭 @@ -1189,4 +1189,7 @@ 更新订阅时只判断别名已存在否 + + 测试终止中... + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx index f7cb8a72..7ba2cce0 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx @@ -1079,7 +1079,7 @@ 啟用硬體加速(需重啟) - 等待測試中...... + 等待测试中(按ESC终止)... 當有異常斷流時請關閉 @@ -1162,4 +1162,7 @@ 更新訂閱時只判斷別名是否存在 + + 測試終止中... + \ No newline at end of file diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index ad8503b1..925dd17e 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -356,6 +356,10 @@ namespace v2rayN.Views { ViewModel?.Reload(); } + else if (e.Key == Key.Escape) + { + MessageBus.Current.SendMessage("true", Global.CommandStopSpeedTest); + } } } @@ -475,10 +479,10 @@ namespace v2rayN.Views var lvColumnItem = _config.uiItem.mainColumnItem.OrderBy(t => t.Index).ToList(); var displayIndex = 0; - foreach(var item in lvColumnItem) + foreach (var item in lvColumnItem) { - foreach (MyDGTextColumn item2 in lstProfiles.Columns) - { + foreach (MyDGTextColumn item2 in lstProfiles.Columns) + { if (item2.ExName == item.Name) { if (item.Width < 0) diff --git a/v2rayN/v2rayN/Views/MsgView.xaml.cs b/v2rayN/v2rayN/Views/MsgView.xaml.cs index 7afd201f..6d207f92 100644 --- a/v2rayN/v2rayN/Views/MsgView.xaml.cs +++ b/v2rayN/v2rayN/Views/MsgView.xaml.cs @@ -18,7 +18,7 @@ namespace v2rayN.Views { InitializeComponent(); _config = LazyConfig.Instance.GetConfig(); - MessageBus.Current.Listen("MsgView").Subscribe(x => DelegateAppendText(x)); + MessageBus.Current.Listen(Global.CommandSendMsgView).Subscribe(x => DelegateAppendText(x)); Global.PresetMsgFilters.ForEach(it => { cmbMsgFilter.Items.Add(it);