From d5b850a0249c2f2b19341acc5bd3a72eebcfa626 Mon Sep 17 00:00:00 2001 From: liuxinhao Date: Fri, 2 Jun 2023 14:46:07 +0800 Subject: [PATCH 6/9] fix(default device): Device adapters do not update default devices that do not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 设备适配器不更新不存在的默认设备 --- src/daemon/device/device-adaptor-factory.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/daemon/device/device-adaptor-factory.cpp b/src/daemon/device/device-adaptor-factory.cpp index d3ffe19..531e0d9 100644 --- a/src/daemon/device/device-adaptor-factory.cpp +++ b/src/daemon/device/device-adaptor-factory.cpp @@ -189,11 +189,16 @@ void DeviceAdaptorFactory::onDefaultDeviceChanged(int authType, const QString &deviceID) { auto deviceAdaptor = this->getDeviceAdaptor(authType); - if (deviceAdaptor && deviceAdaptor->getDeviceID() != deviceID) - { - auto dbusDeviceProxy = this->getDBusDeviceProxy(authType, deviceID); - deviceAdaptor->updateDBusDeviceProxy(dbusDeviceProxy); - } + // 当前不存在设备设配器的情况,不更新设备适配器代理,需要时会优先考虑默认设备 + // 设备适配器已使用默认设备代理,不需要更新设备适配器 + RETURN_IF_FALSE(deviceAdaptor && deviceAdaptor->getDeviceID()!=deviceID); + + // 尝试通过默认设备ID,拿到设备代理 + auto recommendedDeviceProxy = this->getDBusDeviceProxy(authType, deviceID); + // 未能拿到设备,或者拿不到默认设备,不更新设备适配器代理 + RETURN_IF_FALSE( recommendedDeviceProxy && recommendedDeviceProxy->deviceID()==deviceID); + + deviceAdaptor->updateDBusDeviceProxy(recommendedDeviceProxy); } void DeviceAdaptorFactory::onAuthDeviceManagerLost(const QString &service) -- 2.33.0