From 278237ebcb646037d6c77ebbbf3a9629d2b086c0 Mon Sep 17 00:00:00 2001
From: luoqing <luoqing@kylinsec.com.cn>
Date: Fri, 23 Feb 2024 14:27:17 +0800
Subject: [PATCH 0/1] fix(audio):when the tray is initialized, determine
 whether there is asound card,if not, the volume icon is disabled
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 托盘初始化时，判断是否存在声卡，若不存在则音量图标显示禁用

Related #22865
---
 plugins/audio/src/system-tray/audio-system-tray.cpp   | 10 +++++++---
 plugins/audio/src/system-tray/volume-setting-page.cpp |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/plugins/audio/src/system-tray/audio-system-tray.cpp b/plugins/audio/src/system-tray/audio-system-tray.cpp
index 5b2522f..c4b726c 100644
--- a/plugins/audio/src/system-tray/audio-system-tray.cpp
+++ b/plugins/audio/src/system-tray/audio-system-tray.cpp
@@ -83,9 +83,13 @@ void AudioSystemTray::initMixedSettingPage()
 
 void AudioSystemTray::initTrayIcon()
 {
-    QDBusPendingReply<QString> defaultSinkPath = m_audioInterface->GetDefaultSink();
-    AudioDeviceInterface defaultSink (AUDIO_DBUS_NAME, defaultSinkPath, QDBusConnection::sessionBus());
-    double currentVolumeDouble = defaultSink.volume() * 100;
+    double currentVolumeDouble = 0;
+    if(!m_audioInterface->getCards().isEmpty())
+    {
+        QDBusPendingReply<QString> defaultSinkPath = m_audioInterface->GetDefaultSink();
+        AudioDeviceInterface defaultSink (AUDIO_DBUS_NAME, defaultSinkPath, QDBusConnection::sessionBus());
+        currentVolumeDouble = defaultSink.volume() * 100;
+    }
     setTrayIcon(round(currentVolumeDouble));
 }
 
diff --git a/plugins/audio/src/system-tray/volume-setting-page.cpp b/plugins/audio/src/system-tray/volume-setting-page.cpp
index b2dcb62..1925c8d 100644
--- a/plugins/audio/src/system-tray/volume-setting-page.cpp
+++ b/plugins/audio/src/system-tray/volume-setting-page.cpp
@@ -296,6 +296,7 @@ void VolumeSettingPage::disableSettings()
     ui->volume->setText(QString::number(0) + "%");
     ui->volumeSetting->setEnabled(false);
     setVolumeIcon(0);
+    emit volumeChanged(0);
 }
 
 void VolumeSettingPage::hideLine()
-- 
2.27.0

