From 5628b4b31eeb7493abe41bb9a6935955f0ca090a Mon Sep 17 00:00:00 2001
From: luoqing <luoqing@kylinsec.com.cn>
Date: Fri, 15 Sep 2023 16:19:15 +0800
Subject: [PATCH] fix(network-tray):Improved the notification logic. "Wired
 NIC: xxx is unavailable" and "Network is Unavailable" are no longer displayed
 during sleep recovery.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 完善通知弹窗逻辑，从休眠中恢复过程中不再提示“有线网卡：xxx不可用”和“网络不可用”。

Close #15619
---
 plugins/network/src/tray/network-tray.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/plugins/network/src/tray/network-tray.cpp b/plugins/network/src/tray/network-tray.cpp
index 7397e28..dd5ff12 100644
--- a/plugins/network/src/tray/network-tray.cpp
+++ b/plugins/network/src/tray/network-tray.cpp
@@ -473,9 +473,21 @@ void NetworkTray::handleDeviceStateChanged(NetworkManager::Device::State newstat
         }
     }
 
-    // 设备变为不可用时，如果无线和有线均不可用则显示网络不可用的提示
-    if (newstate == Device::Unavailable || newstate == Device::Unmanaged || newstate == Device::UnknownState)
+    QSet<Device::State> unavailableStates = {
+        Device::Unavailable,
+        Device::Unmanaged,
+        Device::UnknownState
+    };
+
+    // 非休眠的情况下，从可用状态到不可用状态通知
+    if (!unavailableStates.contains(oldstate)
+        && 
+        unavailableStates.contains(newstate)
+        &&
+        reason != Device::SleepingReason
+        )
     {
+        // 设备变为不可用时，如果无线和有线均不可用则显示网络不可用的提示
         KLOG_DEBUG() << "device is unavailable";
         if ((NetworkUtils::getAvailableDeviceList(Device::Ethernet).count() == 0) &&
             (NetworkUtils::getAvailableDeviceList(Device::Wifi).count() == 0))
-- 
2.33.0

