From a4081b1a7f3ed74fb56e2ef39f7aca6fd02d5dd3 Mon Sep 17 00:00:00 2001 From: AmazingDM Date: Fri, 28 Aug 2020 13:58:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E5=87=BBNAT=20label=E5=92=8C=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=81=AF=E5=8D=B3=E5=8F=AF=E9=87=8D=E6=B5=8BNAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Controllers/MainController.cs | 16 ++++++++++++++++ Netch/Forms/MainForm.Designer.cs | 2 ++ Netch/Forms/MainForm.cs | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 7c2d7b6d..607e5c52 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -235,6 +235,22 @@ namespace Netch.Controllers return result; } + /// + /// 重测NAT + /// + public void RetryNatTest() + { + _ = Task.Run(() => + { + Global.MainForm.NatTypeStatusText(i18N.Translate("Starting NatTester")); + // Thread.Sleep(1000); + var (nttResult, natType, localEnd, publicEnd) = pNTTController.Start(); + var country = Utils.Utils.GetCityCode(publicEnd); + + if (nttResult) Global.MainForm.NatTypeStatusText(natType, country); + }); + } + /// /// 停止 /// diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs index 7b9b5d72..24beb70d 100644 --- a/Netch/Forms/MainForm.Designer.cs +++ b/Netch/Forms/MainForm.Designer.cs @@ -605,6 +605,7 @@ namespace Netch.Forms this.NatTypeStatusLabel.Size = new System.Drawing.Size(36, 17); this.NatTypeStatusLabel.Text = "NAT:"; this.NatTypeStatusLabel.TextAlign = System.Drawing.ContentAlignment.BottomLeft; + this.NatTypeStatusLabel.Click += new System.EventHandler(this.NatTypeStatusLabel_Click); // // NatTypeStatusLightLabel // @@ -616,6 +617,7 @@ namespace Netch.Forms this.NatTypeStatusLightLabel.Size = new System.Drawing.Size(18, 21); this.NatTypeStatusLightLabel.Text = "⬤"; this.NatTypeStatusLightLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter; + this.NatTypeStatusLightLabel.Click += new System.EventHandler(this.NatTypeStatusLabel_Click); // // ControlButton // diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index cd1469c3..1c993919 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -441,5 +441,14 @@ namespace Netch.Forms if (!_comboBoxInitialized) return; Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex; } + + private void NatTypeStatusLabel_Click(object sender, EventArgs e) + { + //一个不太优雅的🔒 + if (_state == State.Started && NatTypeStatusLabel.ToString().Contains("[")) + { + _mainController.RetryNatTest(); + } + } } } \ No newline at end of file