diff --git a/plugins/remotesystemvolume/remotesystemvolumeplugin.cpp b/plugins/remotesystemvolume/remotesystemvolumeplugin.cpp index a7a5406bd..4a492a46b 100644 --- a/plugins/remotesystemvolume/remotesystemvolumeplugin.cpp +++ b/plugins/remotesystemvolume/remotesystemvolumeplugin.cpp @@ -56,13 +56,6 @@ void RemoteSystemVolumePlugin::sendMuted(const QString &name, bool muted) sendPacket(np); } -void RemoteSystemVolumePlugin::connected() -{ - NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST); - np.set(QStringLiteral("requestSinks"), true); - sendPacket(np); -} - QByteArray RemoteSystemVolumePlugin::sinks() { return m_sinks; diff --git a/plugins/remotesystemvolume/remotesystemvolumeplugin.h b/plugins/remotesystemvolume/remotesystemvolumeplugin.h index dbc31c15d..5f202e098 100644 --- a/plugins/remotesystemvolume/remotesystemvolumeplugin.h +++ b/plugins/remotesystemvolume/remotesystemvolumeplugin.h @@ -24,7 +24,6 @@ public: using KdeConnectPlugin::KdeConnectPlugin; void receivePacket(const NetworkPacket &np) override; - void connected() override; QString dbusPath() const override; QString deviceId() const diff --git a/plugins/systemvolume/systemvolumeplugin-macos.cpp b/plugins/systemvolume/systemvolumeplugin-macos.cpp index f5edff9bc..47933f61e 100644 --- a/plugins/systemvolume/systemvolumeplugin-macos.cpp +++ b/plugins/systemvolume/systemvolumeplugin-macos.cpp @@ -221,21 +221,17 @@ SystemvolumePlugin::~SystemvolumePlugin() void SystemvolumePlugin::receivePacket(const NetworkPacket &np) { - if (np.has(QStringLiteral("requestSinks"))) { - sendSinkList(); - } else { - QString name = np.get(QStringLiteral("name")); + QString name = np.get(QStringLiteral("name")); - if (m_sinksMap.contains(name)) { - if (np.has(QStringLiteral("volume"))) { - m_sinksMap[name]->setVolume(np.get(QStringLiteral("volume")) / 100.0); - } - if (np.has(QStringLiteral("muted"))) { - m_sinksMap[name]->setMuted(np.get(QStringLiteral("muted"))); - } - if (np.has(QStringLiteral("enabled"))) { - m_sinksMap[name]->setDefault(np.get(QStringLiteral("enabled"))); - } + if (m_sinksMap.contains(name)) { + if (np.has(QStringLiteral("volume"))) { + m_sinksMap[name]->setVolume(np.get(QStringLiteral("volume")) / 100.0); + } + if (np.has(QStringLiteral("muted"))) { + m_sinksMap[name]->setMuted(np.get(QStringLiteral("muted"))); + } + if (np.has(QStringLiteral("enabled"))) { + m_sinksMap[name]->setDefault(np.get(QStringLiteral("enabled"))); } } } diff --git a/plugins/systemvolume/systemvolumeplugin-pulse.cpp b/plugins/systemvolume/systemvolumeplugin-pulse.cpp index 668654b36..7a1e28759 100644 --- a/plugins/systemvolume/systemvolumeplugin-pulse.cpp +++ b/plugins/systemvolume/systemvolumeplugin-pulse.cpp @@ -33,24 +33,20 @@ void SystemvolumePlugin::receivePacket(const NetworkPacket &np) if (!PulseAudioQt::Context::instance()->isValid()) return; - if (np.has(QStringLiteral("requestSinks"))) { - sendSinkList(); - } else { - QString name = np.get(QStringLiteral("name")); + QString name = np.get(QStringLiteral("name")); - PulseAudioQt::Sink *sink = sinksMap.value(name); - if (sink) { - if (np.has(QStringLiteral("volume"))) { - int volume = np.get(QStringLiteral("volume")); - sink->setVolume(volume); - sink->setMuted(false); - } - if (np.has(QStringLiteral("muted"))) { - sink->setMuted(np.get(QStringLiteral("muted"))); - } - if (np.has(QStringLiteral("enabled"))) { - sink->setDefault(np.get(QStringLiteral("enabled"))); - } + PulseAudioQt::Sink *sink = sinksMap.value(name); + if (sink) { + if (np.has(QStringLiteral("volume"))) { + int volume = np.get(QStringLiteral("volume")); + sink->setVolume(volume); + sink->setMuted(false); + } + if (np.has(QStringLiteral("muted"))) { + sink->setMuted(np.get(QStringLiteral("muted"))); + } + if (np.has(QStringLiteral("enabled"))) { + sink->setDefault(np.get(QStringLiteral("enabled"))); } } } diff --git a/plugins/systemvolume/systemvolumeplugin-win.cpp b/plugins/systemvolume/systemvolumeplugin-win.cpp index 0489c8d2f..8658a2c5d 100644 --- a/plugins/systemvolume/systemvolumeplugin-win.cpp +++ b/plugins/systemvolume/systemvolumeplugin-win.cpp @@ -404,38 +404,34 @@ void SystemvolumePlugin::receivePacket(const NetworkPacket &np) if (!valid) return; - if (np.has(QStringLiteral("requestSinks"))) { - sendSinkList(); - } else { - QString name = np.get(QStringLiteral("name")); + QString name = np.get(QStringLiteral("name")); - auto sinkListIterator = this->sinkList.find(name); - if (sinkListIterator != this->sinkList.end()) { - auto &sink = sinkListIterator.value(); + auto sinkListIterator = this->sinkList.find(name); + if (sinkListIterator != this->sinkList.end()) { + auto &sink = sinkListIterator.value(); - if (np.has(QStringLiteral("volume"))) { - float requestedVolume = (float)np.get(QStringLiteral("volume"), 100) / 100; - sinkList[name].first->SetMasterVolumeLevelScalar(requestedVolume, NULL); - } + if (np.has(QStringLiteral("volume"))) { + float requestedVolume = (float)np.get(QStringLiteral("volume"), 100) / 100; + sinkList[name].first->SetMasterVolumeLevelScalar(requestedVolume, NULL); + } - if (np.has(QStringLiteral("muted"))) { - BOOL requestedMuteStatus = np.get(QStringLiteral("muted"), false); - sinkList[name].first->SetMute(requestedMuteStatus, NULL); - } + if (np.has(QStringLiteral("muted"))) { + BOOL requestedMuteStatus = np.get(QStringLiteral("muted"), false); + sinkList[name].first->SetMute(requestedMuteStatus, NULL); + } - if (np.has(QStringLiteral("enabled"))) { - // get the current default device ID - IMMDevice *defaultDevice = nullptr; - deviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &defaultDevice); - LPWSTR defaultId = NULL; - defaultDevice->GetId(&defaultId); - defaultDevice->Release(); - // get current sink's device ID - QString qDefaultId = QString::fromWCharArray(defaultId); - QString currentDeviceId = idToNameMap.key(name); - if (qDefaultId != currentDeviceId) { - setDefaultAudioPlaybackDevice(name, np.get(QStringLiteral("enabled"))); - } + if (np.has(QStringLiteral("enabled"))) { + // get the current default device ID + IMMDevice *defaultDevice = nullptr; + deviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &defaultDevice); + LPWSTR defaultId = NULL; + defaultDevice->GetId(&defaultId); + defaultDevice->Release(); + // get current sink's device ID + QString qDefaultId = QString::fromWCharArray(defaultId); + QString currentDeviceId = idToNameMap.key(name); + if (qDefaultId != currentDeviceId) { + setDefaultAudioPlaybackDevice(name, np.get(QStringLiteral("enabled"))); } } }