Skip to content

Commit

Permalink
Added termination speed test
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Feb 25, 2024
1 parent 4c5546b commit 5ff4d35
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 20 deletions.
2 changes: 2 additions & 0 deletions v2rayN/v2rayN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ internal class Global
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;
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Handler/NoticeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public void Enqueue(object content)

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);
}
}
}
36 changes: 35 additions & 1 deletion v2rayN/v2rayN/Handler/SpeedtestHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using ReactiveUI;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using v2rayN.Model;
Expand Down Expand Up @@ -213,8 +214,24 @@ private async Task RunSpeedTestAsync()

DownloadHandle downloadHandle = new();

var exitLoop = false;
MessageBus.Current.Listen<string>(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;
Expand Down Expand Up @@ -270,8 +287,25 @@ private async Task RunSpeedTestMulti()

DownloadHandle downloadHandle = new();

var exitLoop = false;
MessageBus.Current.Listen<string>(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;
Expand Down
29 changes: 19 additions & 10 deletions v2rayN/v2rayN/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion v2rayN/v2rayN/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@
<value>Enable hardware acceleration(Require restart)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>Waiting for testing......</value>
<value>Waiting for testing (press ESC to terminate)...</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>Please turn off when there is an abnormal disconnection</value>
Expand Down Expand Up @@ -1192,4 +1192,7 @@
<data name="TbSettingsEnableUpdateSubOnlyRemarksExist" xml:space="preserve">
<value>Updating subscription, only determine remarks exists</value>
</data>
<data name="SpeedtestingStop" xml:space="preserve">
<value>Test terminating...</value>
</data>
</root>
5 changes: 4 additions & 1 deletion v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@
<value>启用硬件加速(需重启)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>等待测试中......</value>
<value>等待测试中(按ESC终止)...</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>当有异常断流时请关闭</value>
Expand Down Expand Up @@ -1189,4 +1189,7 @@
<data name="TbSettingsEnableUpdateSubOnlyRemarksExist" xml:space="preserve">
<value>更新订阅时只判断别名已存在否</value>
</data>
<data name="SpeedtestingStop" xml:space="preserve">
<value>测试终止中...</value>
</data>
</root>
5 changes: 4 additions & 1 deletion v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@
<value>啟用硬體加速(需重啟)</value>
</data>
<data name="SpeedtestingWait" xml:space="preserve">
<value>等待測試中......</value>
<value>等待测试中(按ESC终止)...</value>
</data>
<data name="TipDisplayLog" xml:space="preserve">
<value>當有異常斷流時請關閉</value>
Expand Down Expand Up @@ -1162,4 +1162,7 @@
<data name="TbSettingsEnableUpdateSubOnlyRemarksExist" xml:space="preserve">
<value>更新訂閱時只判斷別名是否存在</value>
</data>
<data name="SpeedtestingStop" xml:space="preserve">
<value>測試終止中...</value>
</data>
</root>
10 changes: 7 additions & 3 deletions v2rayN/v2rayN/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
ViewModel?.Reload();
}
else if (e.Key == Key.Escape)
{
MessageBus.Current.SendMessage("true", Global.CommandStopSpeedTest);
}
}
}

Expand Down Expand Up @@ -475,10 +479,10 @@ private void RestoreUI()

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)
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Views/MsgView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MsgView()
{
InitializeComponent();
_config = LazyConfig.Instance.GetConfig();
MessageBus.Current.Listen<string>("MsgView").Subscribe(x => DelegateAppendText(x));
MessageBus.Current.Listen<string>(Global.CommandSendMsgView).Subscribe(x => DelegateAppendText(x));
Global.PresetMsgFilters.ForEach(it =>
{
cmbMsgFilter.Items.Add(it);
Expand Down

0 comments on commit 5ff4d35

Please sign in to comment.