fix(config): support low performance device config#480
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds configuration-based detection of low performance devices using DConfig before falling back to existing DBus-based logic. Sequence diagram for updated isLowPerformanceBoard configuration checksequenceDiagram
participant GlobalUtils
participant DConfig
participant SystemInfoService
GlobalUtils->>DConfig: DConfig::create(org.deepin.camera, org.deepin.movie.encode)
alt [dconfig && isValid && keyList contains isLowPerformanceDevice]
GlobalUtils->>DConfig: value(isLowPerformanceDevice)
alt [value.toBool is true]
GlobalUtils-->>GlobalUtils: return true
else [value.toBool is false]
GlobalUtils-->>DConfig: delete dconfig
GlobalUtils-->>SystemInfoService: continue DBus-based detection
end
else [no config or key]
GlobalUtils-->>DConfig: delete dconfig
GlobalUtils-->>SystemInfoService: continue DBus-based detection
end
GlobalUtils->>SystemInfoService: QDBusInterface(com.deepin.system.SystemInfo)
SystemInfoService-->>GlobalUtils: isValid / properties (existing logic)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider managing the
DConfiginstance with RAII (e.g.,std::unique_ptrorQScopedPointer) to avoid manualnew/deleteand reduce the risk of lifetime/cleanup issues, especially with early returns. - You can simplify the DConfig logic by avoiding
keyList().contains(...)on every call and instead directly reading the value with a default (e.g.,value("isLowPerformanceDevice", false).toBool()), which will be more efficient and concise.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider managing the `DConfig` instance with RAII (e.g., `std::unique_ptr` or `QScopedPointer`) to avoid manual `new`/`delete` and reduce the risk of lifetime/cleanup issues, especially with early returns.
- You can simplify the DConfig logic by avoiding `keyList().contains(...)` on every call and instead directly reading the value with a default (e.g., `value("isLowPerformanceDevice", false).toBool()`), which will be more efficient and concise.
## Individual Comments
### Comment 1
<location path="src/src/globalutils.cpp" line_range="61" />
<code_context>
bool GlobalUtils::isLowPerformanceBoard()
{
+#ifdef DTKCORE_CLASS_DConfigFile
+ DTK_CORE_NAMESPACE::DConfig *dconfig = DTK_CORE_NAMESPACE::DConfig::create("org.deepin.camera","org.deepin.movie.encode");
+ if(dconfig && dconfig->isValid() && dconfig->keyList().contains("isLowPerformanceDevice")){
+ if (dconfig->value("isLowPerformanceDevice").toBool()) {
</code_context>
<issue_to_address>
**issue (bug_risk):** Possible mismatch between DConfig ID and the JSON asset name
The config is created with ID "org.deepin.movie.encode" but the added asset is `org.deepin.camera.encode.json`. If DConfig requires this argument to match the config ID / file name, the config may never load and the override will silently be ignored. Please confirm whether this ID should be "org.deepin.camera.encode" (or otherwise aligned with the asset name) so the config is actually used.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Log: 支持通过配置标记低性能设备 Bug: https://pms.uniontech.com/bug-view-358869.html Influence: 可通过配置直接识别低性能设备,优化低性能设备判断逻辑。
deepin pr auto review这份代码的主要目的是为相机应用引入一种基于 以下是详细的审查意见: 1. 语法与逻辑
2. 代码性能
3. 代码质量
4. 代码安全
改进后的代码建议1. 修改 JSON 配置 (org.deepin.camera.encode.json) "isLowPerformanceDevice": {
"value": false,
"serial": 0,
"flags": ["global"],
"name": "is low performance device",
"name[zh_CN]": "是否是低性能设备",
"description": "Is low performance device",
"permissions": "read", // 建议:如果不希望用户随意篡改,改为只读
"visibility": "private"
}2. 修改 C++ 头文件 class GlobalUtils
{
private:
static QStringList m_LowPerformanceBoards;
static bool m_isLowPerformanceDevice; // 统一为小驼峰
// 建议增加常量提取
static const QString DCONFIG_APP_ID;
static const QString DCONFIG_META_NAME;
static const QString DCONFIG_KEY_LOW_PERF;
};3. 修改 C++ 实现文件 // Copyright (C) 2020 ~ 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "globalutils.h"
#include <QDBusArgument>
#include <QDBusReply>
#ifdef HAS_DCONFIG // 建议通过 CMake 传入更准确的宏
#include <DConfig>
#include <memory>
#endif
// 相机配置文件
const QString CAMERA_CONF_PATH = "/usr/share/deepin-camera/camera.conf";
#define LOW_PERFORMANCE_BOARD "LowPerformanceBoard"
// 提取常量
const QString GlobalUtils::DCONFIG_APP_ID = "org.deepin.camera";
const QString GlobalUtils::DCONFIG_META_NAME = "org.deepin.camera.encode";
const QString GlobalUtils::DCONFIG_KEY_LOW_PERF = "isLowPerformanceDevice";
QStringList GlobalUtils::m_LowPerformanceBoards = QStringList();
bool GlobalUtils::m_isLowPerformanceDevice = false;
// ... (DMIInfo 及其流操作符保持不变) ...
bool GlobalUtils::isLowPerformanceBoard()
{
#ifdef HAS_DCONFIG
if (m_isLowPerformanceDevice) {
return true;
}
#endif
qDBusRegisterMetaType<DMIInfo>();
// 优化:使用栈对象代替堆对象,避免内存泄漏
QDBusInterface monitorInterface("com.deepin.system.SystemInfo",
"/com/deepin/system/SystemInfo",
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus());
if (!monitorInterface.isValid())
return false;
// 优化:增加超时控制(例如 3000 毫秒),防止 DBus 阻塞
QDBusMessage reply = monitorInterface.call(QDBus::BlockWithGui, 3000, "Get",
"com.deepin.system.SystemInfo", "DMIInfo");
if (reply.type() == QDBusMessage::ReplyMessage) {
QVariant variant = reply.arguments().at(0);
if (variant.canConvert<QDBusVariant>()) {
QVariant innerVar = variant.value<QDBusVariant>().variant();
if (innerVar.canConvert<QDBusArgument>()) {
QDBusArgument arg = innerVar.value<QDBusArgument>();
DMIInfo info;
arg >> info;
return m_LowPerformanceBoards.contains(info.boardName);
}
}
}
return false;
}
void GlobalUtils::loadCameraConf()
{
QSettings settings(CAMERA_CONF_PATH, QSettings::IniFormat);
settings.beginGroup("Base");
QString boards = settings.value(LOW_PERFORMANCE_BOARD).toString();
settings.endGroup();
if (!boards.isEmpty()) {
m_LowPerformanceBoards = boards.split(",", QString::SkipEmptyParts);
} else {
m_LowPerformanceBoards = QStringList();
}
#ifdef HAS_DCONFIG
// 逻辑优化:无需提前置 false,因为默认值已经是 false,且创建失败时不应覆盖可能存在的上一次状态
std::unique_ptr<DTK_CORE_NAMESPACE::DConfig> dconfig(
DTK_CORE_NAMESPACE::DConfig::create(DCONFIG_APP_ID, DCONFIG_META_NAME));
if (dconfig && dconfig->isValid()) {
if (dconfig->keyList().contains(DCONFIG_KEY_LOW_PERF)) {
m_isLowPerformanceDevice = dconfig->value(DCONFIG_KEY_LOW_PERF).toBool();
}
} else {
qWarning() << "DConfig is invalid or create failed for" << DCONFIG_APP_ID;
}
#endif
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, Resurgamz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
|
This pr cannot be merged! (status: unstable) |
Log: 支持通过配置标记低性能设备
Bug: https://pms.uniontech.com/bug-view-358869.html
Influence: 可通过配置直接识别低性能设备,优化低性能设备判断逻辑。
Summary by Sourcery
New Features: