From e4b218e4fbd632cb238ce33ff9a0b02f30924ba5 Mon Sep 17 00:00:00 2001 From: Ivy233 Date: Mon, 19 Oct 2026 17:26:08 +0800 Subject: [PATCH] fix: install the missing bluetooth DConfig meta file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bluetooth plugin's scanInterval configuration meta exists in the source tree but has no install rule, and the plugin reads it with the legacy org.deepin.dde.dock app id. On a clean system DConfig cannot load the resource, so every scanInterval read logs warnings and the configured value is never used. The configuration was never shipped in a package before, so install it only for org.deepin.dde.tray-loader, and read scanInterval with the tray-loader app id used by the other plugins. DConfig does not enforce a range for scanInterval. A value of 0 makes QTimer fire immediately, so discovery restarts as soon as it finishes and Bluetooth scanning churns continuously. Fall back to the default 5-second interval when the configured value is missing, non-numeric, or not positive. Log: install the missing bluetooth DConfig meta file Influence: 1. Verify org.deepin.dde.dock.plugin.bluetooth.json is installed under /usr/share/dsg/configs/org.deepin.dde.tray-loader/ 2. Verify bluetooth scanInterval is read from DConfig and no DConfig warning is logged for this config at startup 3. Verify the default 5-second interval still applies when the key is not overridden 4. Verify 0, negative, or non-numeric scanInterval values fall back to the 5-second default fix: 补齐蓝牙插件缺失的 DConfig 元数据文件 蓝牙插件的 scanInterval 配置元数据文件在源码中存在,但没有安装规则, 且插件仍使用旧的 org.deepin.dde.dock app id 读取。干净系统上 DConfig 无法加载该资源,导致每次读取 scanInterval 都打印告警,配置值也永远 不生效。 该配置此前从未随包发布,因此仅为 org.deepin.dde.tray-loader 安装 org.deepin.dde.dock.plugin.bluetooth.json,并改用其他插件统一使用的 tray-loader app id 读取 scanInterval。 DConfig 不会校验 scanInterval 的范围。值为 0 时 QTimer 会立即触发, 导致蓝牙发现刚结束就重新开始,形成持续扫描。当配置缺失、非数字或 不是正数时,回退到默认的 5 秒间隔。 Log: 补齐蓝牙插件缺失的 DConfig 元数据文件 Influence: 1. 验证 org.deepin.dde.dock.plugin.bluetooth.json 已安装到 /usr/share/dsg/configs/org.deepin.dde.tray-loader/ 2. 验证蓝牙 scanInterval 从 DConfig 读取,启动时不再打印该配置的 DConfig 告警 3. 验证未覆盖配置时仍使用默认 5 秒间隔 4. 验证 scanInterval 为 0、负数或非数字时回退到默认 5 秒间隔 PMS: TASK-394335 --- plugins/dde-dock/bluetooth/CMakeLists.txt | 2 ++ .../componments/bluetoothadapteritem.cpp | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/plugins/dde-dock/bluetooth/CMakeLists.txt b/plugins/dde-dock/bluetooth/CMakeLists.txt index 88f93db9e..13d5b1761 100644 --- a/plugins/dde-dock/bluetooth/CMakeLists.txt +++ b/plugins/dde-dock/bluetooth/CMakeLists.txt @@ -64,3 +64,5 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins/system-trays) install(FILES "resources/dcc-bluetooth.dci" DESTINATION share/dde-dock/icons/dcc-setting) + +dtk_add_config_meta_files(APPID org.deepin.dde.tray-loader FILES ../configs/org.deepin.dde.dock.plugin.bluetooth.json) diff --git a/plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.cpp b/plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.cpp index 5ebcbb40f..76963aab7 100644 --- a/plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.cpp +++ b/plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.cpp @@ -22,6 +22,30 @@ #include #include +namespace { + +constexpr int DefaultScanIntervalSeconds = 5; + +int scanIntervalMs() +{ + bool ok = false; + int seconds = DConfigHelper::instance()->getConfig( + "org.deepin.dde.tray-loader", + "org.deepin.dde.dock.plugin.bluetooth", + QString(), + "scanInterval", + DefaultScanIntervalSeconds).toInt(&ok); + + // DConfig does not enforce a range, and QTimer treats 0 as "fire + // immediately", which would restart discovery as soon as it finishes. + if (!ok || seconds <= 0) + seconds = DefaultScanIntervalSeconds; + + return seconds * 1000; +} + +} // namespace + BluetoothDeviceItem::BluetoothDeviceItem(QStyle *style, const Device *device, PluginListView *parent) : m_style(style) , m_device(device) @@ -404,9 +428,9 @@ void BluetoothAdapterItem::initUi() void BluetoothAdapterItem::initConnect() { - m_scanTimer->setInterval(DConfigHelper::instance()->getConfig("org.deepin.dde.dock", "org.deepin.dde.dock.plugin.bluetooth", "", "scanInterval", 5).toInt() * 1000); - DConfigHelper::instance()->bind("org.deepin.dde.dock", "org.deepin.dde.dock.plugin.bluetooth", "", this, "scanInterval", [this] (const QString&, const QVariant&, QObject*) { - m_scanTimer->setInterval(DConfigHelper::instance()->getConfig("org.deepin.dde.dock", "org.deepin.dde.dock.plugin.bluetooth", "", "scanInterval", 5).toInt() * 1000); + m_scanTimer->setInterval(scanIntervalMs()); + DConfigHelper::instance()->bind("org.deepin.dde.tray-loader", "org.deepin.dde.dock.plugin.bluetooth", "", this, "scanInterval", [this] (const QString&, const QVariant&, QObject*) { + m_scanTimer->setInterval(scanIntervalMs()); }); connect(m_scanTimer, &QTimer::timeout, this, [this] { if (isVisible())