From 233d605256aa117d7e7249f3543fbc5381a2e206 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:09:44 +0800 Subject: [PATCH] Optimize the information function --- v2rayN/ServiceLib/Handler/UpdateHandler.cs | 10 +++------- .../ServiceLib/ViewModels/MainWindowViewModel.cs | 15 +++------------ v2rayN/ServiceLib/ViewModels/MsgViewModel.cs | 4 ++++ 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/UpdateHandler.cs b/v2rayN/ServiceLib/Handler/UpdateHandler.cs index 48c4f5e94d..11e7787457 100644 --- a/v2rayN/ServiceLib/Handler/UpdateHandler.cs +++ b/v2rayN/ServiceLib/Handler/UpdateHandler.cs @@ -261,14 +261,10 @@ public async Task UpdateGeoFileAll(Config config, Action update) _updateFunc(true, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, "geo")); } - public void RunAvailabilityCheck(Action update) + public async Task RunAvailabilityCheck(Action update) { - Task.Run(async () => - { - var time = await (new DownloadHandler()).RunAvailabilityCheck(null); - - update(false, string.Format(ResUI.TestMeOutput, time)); - }); + var time = await (new DownloadHandler()).RunAvailabilityCheck(null); + update(false, string.Format(ResUI.TestMeOutput, time)); } #region private diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index c11f60350d..7977bce281 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -349,10 +349,6 @@ private void Init() private void UpdateHandler(bool notify, string msg) { - if (!_config.uiItem.showInTaskbar) - { - return; - } _noticeHandler?.SendMessage(msg); if (notify) { @@ -611,21 +607,16 @@ private void ServerSelectedChanged(bool c) SetDefaultServer(SelectedServer.ID); } - public void TestServerAvailability() + public async Task TestServerAvailability() { var item = ConfigHandler.GetDefaultServer(_config); if (item == null) { return; } - (new UpdateHandler()).RunAvailabilityCheck(async (bool success, string msg) => + await (new UpdateHandler()).RunAvailabilityCheck(async (bool success, string msg) => { _noticeHandler?.SendMessageEx(msg); - - if (!_config.uiItem.showInTaskbar) - { - return; - } await _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg); }); } @@ -715,7 +706,7 @@ public void Reload() LoadCore().ContinueWith(async task => { - TestServerAvailability(); + await TestServerAvailability(); await _updateView?.Invoke(EViewAction.DispatcherReload, null); }); diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index e638410646..c2d9f1cd54 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -60,6 +60,10 @@ private async Task AppendQueueMsg(string msg) } _blLockShow = true; + if (!_config.uiItem.showInTaskbar) + { + await Task.Delay(1000); + } await Task.Delay(100); var txt = string.Join("", _queueMsg.ToArray());