refine UI performance

This commit is contained in:
YFdyh000 2020-04-18 10:16:29 +08:00
parent 1c04b752cd
commit fbfbc811d4
4 changed files with 56 additions and 53 deletions

View file

@ -34,14 +34,7 @@ namespace v2rayN.Forms
Application.ApplicationExit += (sender, args) => Application.ApplicationExit += (sender, args) =>
{ {
v2rayHandler.V2rayStop(); Closes();
HttpProxyHandle.CloseHttpAgent(config);
PACServerHandle.Stop();
ConfigHandler.SaveConfig(ref config);
statistics?.SaveToFile();
statistics?.Close();
}; };
} }
@ -347,6 +340,7 @@ namespace v2rayN.Forms
} }
private void DisplayToolStatus() private void DisplayToolStatus()
{ {
ssMain.SuspendLayout();
toolSslSocksPort.Text = toolSslSocksPort.Text =
toolSslHttpPort.Text = toolSslHttpPort.Text =
toolSslPacPort.Text = "OFF"; toolSslPacPort.Text = "OFF";
@ -388,6 +382,7 @@ namespace v2rayN.Forms
break; break;
} }
toolSslRouting.Text = routingStatus; toolSslRouting.Text = routingStatus;
ssMain.ResumeLayout();
RefreshTaryIcon(); RefreshTaryIcon();
} }
@ -411,7 +406,10 @@ namespace v2rayN.Forms
autoLatencyRefreshTask = Task.Run(async delegate autoLatencyRefreshTask = Task.Run(async delegate
{ {
await Task.Delay(2000); await Task.Delay(2000);
toolSslServerLatencyRefresh(); this.Invoke((MethodInvoker)(delegate
{
toolSslServerLatencyRefresh();
}));
}); });
} }
} }
@ -421,37 +419,42 @@ namespace v2rayN.Forms
/// <summary> /// <summary>
/// 载入V2ray /// 载入V2ray
/// </summary> /// </summary>
private void LoadV2ray() private async void LoadV2ray()
{ {
tsbReload.Enabled = false; this.Invoke((MethodInvoker)(delegate
if (Global.reloadV2ray)
{ {
ClearMsg(); tsbReload.Enabled = false;
}
v2rayHandler.LoadV2ray(config); if (Global.reloadV2ray)
{
ClearMsg();
}
}));
await v2rayHandler.LoadV2ray(config);
Global.reloadV2ray = false; Global.reloadV2ray = false;
ConfigHandler.SaveConfig(ref config, false); ChangePACButtonStatus(config.listenerType);
//ConfigHandler.SaveConfig(ref config, false); // ChangePACButtonStatus does it.
statistics?.SaveToFile(); statistics?.SaveToFile();
ChangePACButtonStatus(config.listenerType); this.Invoke((MethodInvoker)(delegate
{
tsbReload.Enabled = true;
tsbReload.Enabled = true; autoLatencyRefresh();
}));
autoLatencyRefresh();
} }
/// <summary> /// <summary>
/// 关闭V2ray /// 关闭相关组件
/// </summary> /// </summary>
private void CloseV2ray() private void Closes()
{ {
ConfigHandler.SaveConfig(ref config, false); //ConfigHandler.SaveConfig(ref config, false); // ChangePACButtonStatus does it.
Task.Run(() => ChangePACButtonStatus(ListenerType.noHttpProxy));
Task.Run(() => v2rayHandler.V2rayStop());
Task.Run(() => PACServerHandle.Stop());
statistics?.SaveToFile(); statistics?.SaveToFile();
statistics?.Close();
ChangePACButtonStatus(0);
v2rayHandler.V2rayStop();
} }
#endregion #endregion
@ -785,13 +788,18 @@ namespace v2rayN.Forms
{ {
string tab = ""; string tab = "";
if (sender == toolSslRouting) tab = "tabPreDefinedRules"; if (sender == toolSslRouting) tab = "tabPreDefinedRules";
OptionSettingForm fm = new OptionSettingForm(tab); OptionSettingForm fm = new OptionSettingForm(tab);
if (fm.ShowDialog() == DialogResult.OK) if (fm.ShowDialog() == DialogResult.OK)
{ {
//刷新 //刷新
RefreshServers(); RefreshServers();
LoadV2ray(); //Application.DoEvents();
HttpProxyHandle.RestartHttpAgent(config, true); Task.Run(() =>
{
LoadV2ray();
HttpProxyHandle.RestartHttpAgent(config, true);
});
} }
} }
@ -1253,7 +1261,8 @@ namespace v2rayN.Forms
item.Checked = ((int)type == k); item.Checked = ((int)type == k);
} }
ConfigHandler.SaveConfig(ref config, false); Global.reloadV2ray = false;
ConfigHandler.SaveConfig(ref config);
DisplayToolStatus(); DisplayToolStatus();
} }
@ -1369,7 +1378,7 @@ namespace v2rayN.Forms
try try
{ {
CloseV2ray(); Closes();
string fileName = downloadHandle.DownloadFileName; string fileName = downloadHandle.DownloadFileName;
fileName = Utils.GetPath(fileName); fileName = Utils.GetPath(fileName);

View file

@ -171,7 +171,7 @@ namespace v2rayN
#region #region
/// <summary> /// <summary>
/// 是否需要重启服务V2ray /// 是否需要重启服务V2ray。如果为假LoadV2ray()不做任何事。
/// </summary> /// </summary>
public static bool reloadV2ray public static bool reloadV2ray
{ {

View file

@ -334,26 +334,22 @@ namespace v2rayN.Handler
} }
/// <summary> /// <summary>
/// 保参数 /// 保参数
/// </summary> /// </summary>
/// <param name="config"></param> /// <param name="config"></param>
/// <returns></returns> /// <returns></returns>
public static int SaveConfig(ref Config config, bool reload = true) public static int SaveConfig(ref Config config)
{ {
Global.reloadV2ray = reload; return ToJsonFile(config);
ToJsonFile(config);
return 0;
} }
/// <summary> /// <summary>
/// 存储文件 /// 存储文件
/// </summary> /// </summary>
/// <param name="config"></param> /// <param name="config"></param>
private static void ToJsonFile(Config config) private static int ToJsonFile(Config config)
{ {
Utils.ToJsonFile(config, Utils.GetPath(configRes)); return Utils.ToJsonFile(config, Utils.GetPath(configRes));
} }
/// <summary> /// <summary>

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks;
using v2rayN.Mode; using v2rayN.Mode;
namespace v2rayN.Handler namespace v2rayN.Handler
@ -38,21 +39,18 @@ namespace v2rayN.Handler
/// <summary> /// <summary>
/// 载入V2ray /// 载入V2ray
/// </summary> /// </summary>
public void LoadV2ray(Config config) public Task LoadV2ray(Config config)
{ {
if (Global.reloadV2ray) return Task.Run(() =>
{ {
if (!Global.reloadV2ray) return;
string fileName = Utils.GetPath(v2rayConfigRes); string fileName = Utils.GetPath(v2rayConfigRes);
if (V2rayConfigHandler.GenerateClientConfig(config, fileName, false, out string msg) != 0) bool bOk = V2rayConfigHandler.GenerateClientConfig(config, fileName, false, out string msg) == 0;
{ ShowMsg(bOk, msg);
ShowMsg(false, msg); if (bOk)
}
else
{
ShowMsg(true, msg);
V2rayRestart(); V2rayRestart();
} });
}
} }
/// <summary> /// <summary>