From 6e499c394883052d8c30fa5b31709067e24dfbfd Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Thu, 7 Jan 2021 10:52:58 +0800
Subject: [PATCH] Update Option items Notification
---
Netch/Controllers/NFController.cs | 1 -
Netch/Forms/MainForm.MenuStrip.cs | 24 +++++++++++++++---------
Netch/Forms/MainForm.Status.cs | 5 +++--
Netch/Forms/MainForm.cs | 5 +++--
Netch/Resources/zh-CN | 2 +-
5 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs
index 798705de..b2f57009 100644
--- a/Netch/Controllers/NFController.cs
+++ b/Netch/Controllers/NFController.cs
@@ -363,7 +363,6 @@ namespace Netch.Controllers
/// 是否成功卸载
public static bool UninstallDriver()
{
- Global.MainForm.StatusText(i18N.TranslateFormat("Uninstalling {0}", "NF Service"));
Logging.Info("卸载 NF 驱动");
try
{
diff --git a/Netch/Forms/MainForm.MenuStrip.cs b/Netch/Forms/MainForm.MenuStrip.cs
index 8fdf3a2e..6e28019c 100644
--- a/Netch/Forms/MainForm.MenuStrip.cs
+++ b/Netch/Forms/MainForm.MenuStrip.cs
@@ -212,12 +212,16 @@ namespace Netch.Forms
DNS.Cache.Clear();
});
- StatusText(i18N.Translate("DNS cache cleanup succeeded"));
+ NotifyTip(i18N.Translate("DNS cache cleanup succeeded"));
}
catch (Exception)
{
// ignored
}
+ finally
+ {
+ StatusText();
+ }
}
private void updateACLWithProxyToolStripMenuItem_Click(object sender, EventArgs e)
@@ -239,8 +243,7 @@ namespace Netch.Forms
}
Enabled = false;
-
- NotifyTip(i18N.Translate("Updating in the background"));
+ StatusText(i18N.TranslateFormat("Updating {0}", "ACL"));
try
{
if (useProxy)
@@ -274,6 +277,7 @@ namespace Netch.Forms
State = State.Stopped;
}
+ StatusText();
Enabled = true;
}
}
@@ -282,12 +286,12 @@ namespace Netch.Forms
{
Enabled = false;
- NotifyTip(i18N.Translate("Updating in the background"));
+ StatusText(i18N.TranslateFormat("Updating {0}", "PAC"));
try
{
var req = WebUtil.CreateRequest(Global.Settings.PAC);
- string pac = Path.Combine(Global.NetchDir, $"bin\\pac.txt");
+ string pac = Path.Combine(Global.NetchDir, "bin\\pac.txt");
await WebUtil.DownloadFileAsync(req, pac);
@@ -300,6 +304,7 @@ namespace Netch.Forms
}
finally
{
+ StatusText();
Enabled = true;
}
}
@@ -314,24 +319,25 @@ namespace Netch.Forms
{
if (NFController.UninstallDriver())
{
- StatusText(i18N.TranslateFormat("{0} has been uninstalled", "NF Service"));
+ NotifyTip(i18N.TranslateFormat("{0} has been uninstalled", "NF Service"));
}
});
}
finally
{
+ StatusText();
Enabled = true;
}
}
private async void UninstallTapDriverToolStripMenuItem_Click(object sender, EventArgs e)
{
- StatusText(i18N.TranslateFormat("Uninstalling {0}", "TUN/TAP driver"));
Enabled = false;
+ StatusText(i18N.TranslateFormat("Uninstalling {0}", "TUN/TAP driver"));
try
{
await Task.Run(TUNTAP.deltapall);
- StatusText(i18N.TranslateFormat("{0} has been uninstalled", "TUN/TAP driver"));
+ NotifyTip(i18N.TranslateFormat("{0} has been uninstalled", "TUN/TAP driver"));
}
catch (Exception exception)
{
@@ -339,7 +345,7 @@ namespace Netch.Forms
}
finally
{
- State = State.Waiting;
+ StatusText();
Enabled = true;
}
}
diff --git a/Netch/Forms/MainForm.Status.cs b/Netch/Forms/MainForm.Status.cs
index 74820be6..89bd6d42 100644
--- a/Netch/Forms/MainForm.Status.cs
+++ b/Netch/Forms/MainForm.Status.cs
@@ -47,7 +47,7 @@ namespace Netch.Forms
_state = value;
- StatusText(i18N.Translate(StateExtension.GetStatusString(value)));
+ StatusText();
switch (value)
{
case State.Waiting:
@@ -173,7 +173,7 @@ namespace Netch.Forms
/// 更新状态栏文本
///
///
- public void StatusText(string text)
+ public void StatusText(string text = null)
{
if (InvokeRequired)
{
@@ -181,6 +181,7 @@ namespace Netch.Forms
return;
}
+ text ??= i18N.Translate(StateExtension.GetStatusString(State));
StatusLabel.Text = i18N.Translate("Status", ": ") + text;
}
diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs
index 22f68296..cd0b6fad 100644
--- a/Netch/Forms/MainForm.cs
+++ b/Netch/Forms/MainForm.cs
@@ -348,12 +348,13 @@ namespace Netch.Forms
try
{
await Task.Run(TestServer);
+ Refresh();
+ NotifyTip(i18N.Translate("Test done"));
}
finally
{
Enabled = true;
- StatusText(i18N.Translate("Test done"));
- Refresh();
+ StatusText();
}
}
diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN
index f4596a0c..9d8f217f 100644
--- a/Netch/Resources/zh-CN
+++ b/Netch/Resources/zh-CN
@@ -67,7 +67,7 @@
"Manage Subscribe Links": "管理订阅链接",
"Update Servers From Subscribe Links": "从订阅链接更新服务器",
"No subscription link": "没有任何一条订阅链接",
- "Updating in the background": "正在后台更新中",
+ "Updating {0}": "正在更新 {0}",
"Update {1} server(s) from {0}": "从 {0} 更新 {1} 个服务器",
"Update servers error from {0}": "从 {0} 更新服务器失败",
"Delete the corresponding group of items in the server list?": "是否删除订阅对应服务器?",