Showing latency on status bar

pull/695/head
YFdyh000 5 years ago
parent 1722e50402
commit 2708ff7c1a

@ -55,14 +55,14 @@
this.menuTcpingServer = new System.Windows.Forms.ToolStripMenuItem();
this.menuRealPingServer = new System.Windows.Forms.ToolStripMenuItem();
this.menuSpeedServer = new System.Windows.Forms.ToolStripMenuItem();
this.tsbTestMe = new System.Windows.Forms.ToolStripMenuItem();
this.menuTestMe = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
this.menuExport2ClientConfig = new System.Windows.Forms.ToolStripMenuItem();
this.menuExport2ServerConfig = new System.Windows.Forms.ToolStripMenuItem();
this.menuExport2ShareUrl = new System.Windows.Forms.ToolStripMenuItem();
this.menuExport2SubContent = new System.Windows.Forms.ToolStripMenuItem();
this.tsbServer = new System.Windows.Forms.ToolStripDropDownButton();
this.qrCodeControl = new v2rayN.Forms.QRCodeControl();
this.tsbServer = new System.Windows.Forms.ToolStripDropDownButton();
this.notifyMain = new System.Windows.Forms.NotifyIcon(this.components);
this.cmsMain = new System.Windows.Forms.ContextMenuStrip(this.components);
this.menuSysAgentMode = new System.Windows.Forms.ToolStripMenuItem();
@ -94,6 +94,7 @@
this.toolSslPacPortLab = new System.Windows.Forms.ToolStripStatusLabel();
this.toolSslPacPort = new System.Windows.Forms.ToolStripStatusLabel();
this.toolSslBlank3 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolSslServerLatency = new System.Windows.Forms.ToolStripStatusLabel();
this.toolSslServerSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolSslBlank4 = new System.Windows.Forms.ToolStripStatusLabel();
this.panel1 = new System.Windows.Forms.Panel();
@ -196,7 +197,7 @@
this.menuTcpingServer,
this.menuRealPingServer,
this.menuSpeedServer,
this.tsbTestMe,
this.menuTestMe,
this.toolStripSeparator6,
this.menuExport2ClientConfig,
this.menuExport2ServerConfig,
@ -335,11 +336,11 @@
resources.ApplyResources(this.menuSpeedServer, "menuSpeedServer");
this.menuSpeedServer.Click += new System.EventHandler(this.menuSpeedServer_Click);
//
// tsbTestMe
// menuTestMe
//
this.tsbTestMe.Name = "tsbTestMe";
resources.ApplyResources(this.tsbTestMe, "tsbTestMe");
this.tsbTestMe.Click += new System.EventHandler(this.tsbTestMe_Click);
this.menuTestMe.Name = "menuTestMe";
resources.ApplyResources(this.menuTestMe, "menuTestMe");
this.menuTestMe.Click += new System.EventHandler(this.menuTestMe_Click);
//
// toolStripSeparator6
//
@ -370,6 +371,11 @@
resources.ApplyResources(this.menuExport2SubContent, "menuExport2SubContent");
this.menuExport2SubContent.Click += new System.EventHandler(this.menuExport2SubContent_Click);
//
// qrCodeControl
//
resources.ApplyResources(this.qrCodeControl, "qrCodeControl");
this.qrCodeControl.Name = "qrCodeControl";
//
// tsbServer
//
this.tsbServer.DropDown = this.cmsLv;
@ -377,11 +383,6 @@
resources.ApplyResources(this.tsbServer, "tsbServer");
this.tsbServer.Name = "tsbServer";
//
// qrCodeControl
//
resources.ApplyResources(this.qrCodeControl, "qrCodeControl");
this.qrCodeControl.Name = "qrCodeControl";
//
// notifyMain
//
this.notifyMain.ContextMenuStrip = this.cmsMain;
@ -543,6 +544,7 @@
this.toolSslPacPortLab,
this.toolSslPacPort,
this.toolSslBlank3,
this.toolSslServerLatency,
this.toolSslServerSpeed,
this.toolSslBlank4});
resources.ApplyResources(this.ssMain, "ssMain");
@ -597,11 +599,19 @@
this.toolSslBlank3.Name = "toolSslBlank3";
this.toolSslBlank3.Spring = true;
//
// toolSslServerLatency
//
resources.ApplyResources(this.toolSslServerLatency, "toolSslServerLatency");
this.toolSslServerLatency.Name = "toolSslServerLatency";
this.toolSslServerLatency.Spring = true;
this.toolSslServerLatency.Click += new System.EventHandler(this.toolSslServerLatency_Click);
//
// toolSslServerSpeed
//
resources.ApplyResources(this.toolSslServerSpeed, "toolSslServerSpeed");
this.toolSslServerSpeed.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.toolSslServerSpeed.Name = "toolSslServerSpeed";
this.toolSslServerSpeed.Click += new System.EventHandler(this.toolSslServerSpeed_Click);
//
// toolSslBlank4
//
@ -932,9 +942,10 @@
private System.Windows.Forms.ToolStripMenuItem tsbV2rayWebsite;
private System.Windows.Forms.ToolStripMenuItem menuKeepNothing;
private System.Windows.Forms.ToolStripMenuItem menuKeepPACNothing;
private System.Windows.Forms.ToolStripMenuItem tsbTestMe;
private System.Windows.Forms.ToolStripMenuItem menuTestMe;
private System.Windows.Forms.ToolStripButton tsbReload;
private System.Windows.Forms.ToolStripButton tsbQRCodeSwitch;
private System.Windows.Forms.ToolStripStatusLabel toolSslServerLatency;
}
}

@ -11,6 +11,7 @@ using v2rayN.Tool;
using System.Diagnostics;
using System.Drawing;
using System.Net;
using System.Threading.Tasks;
namespace v2rayN.Forms
{
@ -379,8 +380,23 @@ namespace v2rayN.Forms
#endregion
#region v2ray 操作
public static Task autoLatencyRefreshTask;
private void autoLatencyRefresh()
{
if (config.listenerType != ListenerType.noHttpProxy)
{
if (autoLatencyRefreshTask == null || autoLatencyRefreshTask.IsCompleted)
{
autoLatencyRefreshTask = Task.Run(async delegate
{
await Task.Delay(2000);
toolSslServerLatencyRefresh();
});
}
}
}
#region v2ray 操作
/// <summary>
/// 载入V2ray
/// </summary>
@ -400,6 +416,8 @@ namespace v2rayN.Forms
ChangePACButtonStatus(config.listenerType);
tsbReload.Enabled = true;
autoLatencyRefresh();
}
/// <summary>
@ -674,15 +692,15 @@ namespace v2rayN.Forms
SpeedtestHandler statistics = new SpeedtestHandler(ref config, ref v2rayHandler, lvSelecteds, actionType, UpdateSpeedtestHandler);
}
private void tsbTestMe_Click(object sender, EventArgs e)
private async void menuTestMe_Click(object sender, EventArgs e)
{
string result = httpProxyTest() + "ms";
string result = await httpProxyTest() + "ms";
AppendText(false, string.Format(UIRes.I18N("TestMeOutput"), result));
}
private int httpProxyTest()
private async Task<int> httpProxyTest()
{
SpeedtestHandler statistics = new SpeedtestHandler(ref config, ref v2rayHandler, lvSelecteds, "", UpdateSpeedtestHandler);
return statistics.RunAvailabilityCheck();
return await Task.Run(() => statistics.RunAvailabilityCheck());
}
private void menuExport2ClientConfig_Click(object sender, EventArgs e)
@ -783,6 +801,7 @@ namespace v2rayN.Forms
//刷新
RefreshServers();
LoadV2ray();
toolSslServerLatencySet();
}
return 0;
}
@ -1220,11 +1239,11 @@ namespace v2rayN.Forms
#region CheckUpdate
private void askToDownload(DownloadHandle downloadHandle, string url)
private async void askToDownload(DownloadHandle downloadHandle, string url)
{
if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.Yes)
{
if (httpProxyTest() > 0)
if (await httpProxyTest() > 0)
{
int httpPort = config.GetLocalPort(Global.InboundHttp);
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort);
@ -1566,5 +1585,25 @@ namespace v2rayN.Forms
#endregion
private async void toolSslServerLatencyRefresh()
{
toolSslServerLatencySet("Measuring...");
string result = await httpProxyTest() + "ms";
toolSslServerLatencySet(result);
}
private void toolSslServerLatencySet(string text = "")
{
toolSslServerLatency.Text = "Latency: " + text;
}
private void toolSslServerLatency_Click(object sender, EventArgs e)
{
toolSslServerLatencyRefresh();
}
private void toolSslServerSpeed_Click(object sender, EventArgs e)
{
//toolSslServerLatencyRefresh();
}
}
}

@ -716,6 +716,18 @@
<data name="&gt;&gt;menuTcpingServer.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;menuTestMe.Name" xml:space="preserve">
<value>menuTestMe</value>
</data>
<data name="menuTestMe.Size" type="System.Drawing.Size, System.Drawing">
<value>355, 22</value>
</data>
<data name="menuTestMe.Text" xml:space="preserve">
<value>Test current service status</value>
</data>
<data name="&gt;&gt;menuTestMe.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;menuUpdateSubscriptions.Name" xml:space="preserve">
<value>menuUpdateSubscriptions</value>
</data>
@ -873,7 +885,7 @@
<value>toolSslBlank1</value>
</data>
<data name="toolSslBlank1.Size" type="System.Drawing.Size, System.Drawing">
<value>195, 17</value>
<value>152, 17</value>
</data>
<data name="&gt;&gt;toolSslBlank1.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
@ -885,7 +897,7 @@
<value>toolSslBlank2</value>
</data>
<data name="toolSslBlank2.Size" type="System.Drawing.Size, System.Drawing">
<value>195, 17</value>
<value>152, 17</value>
</data>
<data name="&gt;&gt;toolSslBlank2.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
@ -897,7 +909,7 @@
<value>toolSslBlank3</value>
</data>
<data name="toolSslBlank3.Size" type="System.Drawing.Size, System.Drawing">
<value>195, 17</value>
<value>152, 17</value>
</data>
<data name="&gt;&gt;toolSslBlank3.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
@ -959,6 +971,27 @@
<data name="&gt;&gt;toolSslPacPortLab.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="toolSslServerLatency.AutoSize" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="&gt;&gt;toolSslServerLatency.Name" xml:space="preserve">
<value>toolSslServerLatency</value>
</data>
<data name="toolSslServerLatency.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 17</value>
</data>
<data name="toolSslServerLatency.Text" xml:space="preserve">
<value>Latency:</value>
</data>
<data name="toolSslServerLatency.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="toolSslServerLatency.ToolTipText" xml:space="preserve">
<value>The http proxy's latency time.</value>
</data>
<data name="&gt;&gt;toolSslServerLatency.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="toolSslServerSpeed.AutoSize" type="System.Boolean, mscorlib">
<value>False</value>
</data>
@ -972,7 +1005,7 @@
<value>No</value>
</data>
<data name="toolSslServerSpeed.Size" type="System.Drawing.Size, System.Drawing">
<value>220, 17</value>
<value>200, 17</value>
</data>
<data name="toolSslServerSpeed.Text" xml:space="preserve">
<value>SPEED Disabled</value>
@ -1418,18 +1451,6 @@
<data name="&gt;&gt;tsbSubUpdate.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tsbTestMe.Name" xml:space="preserve">
<value>tsbTestMe</value>
</data>
<data name="tsbTestMe.Size" type="System.Drawing.Size, System.Drawing">
<value>355, 22</value>
</data>
<data name="tsbTestMe.Text" xml:space="preserve">
<value>Test current service status</value>
</data>
<data name="&gt;&gt;tsbTestMe.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tsbV2rayWebsite.Name" xml:space="preserve">
<value>tsbV2rayWebsite</value>
</data>

@ -145,29 +145,24 @@ namespace v2rayN.Handler
}
}
public int RunAvailabilityCheck() // alias: isLive
public async Task<int> RunAvailabilityCheck() // alias: isLive
{
try
{
int httpPort = _config.GetLocalPort(Global.InboundHttp);
Task<int> t = Task.Run(() =>
try
{
try
{
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort);
int responseTime = -1;
string status = GetRealPingTime(Global.AvailabilityTestUrl, webProxy, out responseTime);
bool noError = Utils.IsNullOrEmpty(status);
return noError ? responseTime : -1;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return -1;
}
});
return t.Result;
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort);
int responseTime = -1;
string status = GetRealPingTime(Global.AvailabilityTestUrl, webProxy, out responseTime);
bool noError = Utils.IsNullOrEmpty(status);
return noError ? responseTime : -1;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return -1;
}
}
catch (Exception ex)
{

Loading…
Cancel
Save