Skip to content

Conversation

@GongHeng2017
Copy link
Contributor

@GongHeng2017 GongHeng2017 commented Nov 7, 2025

-- Some special platform, GPU info not show.
-- Pre cache the GPU info.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-340131.html

Summary by Sourcery

Load special platform configuration and pre-generate GPU information at application startup to fix missing GPU info, and remove duplicate config loading from the MainWindow.

Bug Fixes:

  • Pre-cache GPU information for custom specialComType to ensure GPU info is displayed correctly.

Enhancements:

  • Move DConfig-based loading of specialComType and TomlFilesName to the main function.
  • Remove redundant DConfig initialization code from MainWindow.

-- Some special platform, GPU info not show.
-- Pre cache the GPU info.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-340131.html
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 7, 2025

Reviewer's Guide

Centralize platform configuration loading in main.cpp, add GPU info pre-caching for custom device types, and remove redundant config logic from MainWindow.

Sequence diagram for GPU info pre-caching on custom device types

sequenceDiagram
    participant Main as main.cpp
    participant DConfig as DConfig
    participant Common as Common
    participant CommonTools as CommonTools
    Main->>DConfig: create("org.deepin.devicemanager")
    DConfig-->>Main: DConfig instance
    Main->>DConfig: isValid()
    DConfig-->>Main: true/false
    Main->>DConfig: keyList().contains("specialComType")
    DConfig-->>Main: true/false
    Main->>DConfig: value("specialComType")
    DConfig-->>Main: int value
    Main->>Common: set specialComType
    Main->>DConfig: keyList().contains("TomlFilesName")
    DConfig-->>Main: true/false
    Main->>DConfig: value("TomlFilesName")
    DConfig-->>Main: tomlFilesName
    Main->>Common: tomlFilesNameSet(tomlFilesName)
    alt specialComType == kCustomType
        Main->>CommonTools: preGenerateGpuInfo()
    end
Loading

Class diagram for updated Common and CommonTools usage

classDiagram
    class Common {
        +int specialComType
        +static void tomlFilesNameSet(QString)
        +const int kCustomType
        +static QString boardVendorType()
    }
    class CommonTools {
        +static void preGenerateGpuInfo()
    }
    CommonTools <.. Main : uses
    Common <.. Main : uses
Loading

File-Level Changes

Change Details Files
Centralize platform config loading to application entrypoint
  • Added commonfunction.h include
  • Created and validated DConfig instance in main.cpp
  • Populated Common::specialComType and Common::tomlFilesNameSet
  • Removed redundant DConfig logic from MainWindow::initWindowTitle
deepin-devicemanager/src/main.cpp
deepin-devicemanager/src/Page/MainWindow.cpp
Pre-cache GPU information for custom device types
  • Added conditional CommonTools::preGenerateGpuInfo() call when specialComType matches custom type
deepin-devicemanager/src/main.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个diff进行审查:

  1. 代码重构分析:
    这次修改主要将DConfig相关配置的初始化代码从MainWindow::initWindowTitle()移到了main()函数中,这是一个好的改动,因为:
  • 配置初始化应该尽早完成,放在main函数更合适
  • 避免了在UI初始化时进行配置读取,提高启动效率
  1. 代码质量改进建议:
  • 内存泄漏风险:DConfig对象创建后没有释放,应该添加delete或使用智能指针
    建议改为:
DConfig *dconfig = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
// ... 使用dconfig
delete dconfig;

或者使用QScopedPointer:

QScopedPointer<DConfig> dconfig(DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager"));
  1. 代码性能优化:
  • 重复的dconfig有效性检查:代码中多次检查dconfig && dconfig->isValid(),可以将其提取为变量
    建议改为:
bool isValid = dconfig && dconfig->isValid();
if (isValid && dconfig->keyList().contains("specialComType")) {
    // ...
}
if (isValid && dconfig->keyList().contains("TomlFilesName")) {
    // ...
}
  1. 代码安全性:
  • 配置值的类型转换:直接使用toInt()和toString()可能存在风险,应该添加类型检查
    建议改进:
if (dconfig && dconfig->isValid() && dconfig->keyList().contains("specialComType")) {
    QVariant value = dconfig->value("specialComType");
    if (value.canConvert<int>()) {
        Common::specialComType = value.toInt();
    } else {
        qCWarning(appLog) << "Invalid specialComType value in config";
    }
}
  1. 其他建议:
  • 配置键名应该使用常量定义,避免硬编码字符串
    建议添加:
namespace ConfigKeys {
    const QString SPECIAL_COM_TYPE = "specialComType";
    const QString TOML_FILES_NAME = "TomlFilesName";
}
  1. 日志改进:
  • 日志信息应该包含更多上下文,比如配置文件路径
    建议改进:
qCInfo(appLog) << "Loading config from org.deepin.devicemanager, specialComType:" << Common::specialComType;
  1. 代码组织:
  • DConfig相关代码应该封装成单独的配置管理类,而不是直接在main函数中处理
    建议创建ConfigManager类来处理所有配置相关操作。

这些改进将使代码更加健壮、安全和可维护。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/src/main.cpp:112` </location>
<code_context>
         }
     });
     titlebar()->addWidget(mp_ButtonBox);
-#ifdef DTKCORE_CLASS_DConfigFile
-    //需要查询是否支持特殊机型静音恢复,例如hw机型
-    DConfig *dconfig = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
</code_context>

<issue_to_address>
**issue (complexity):** Consider consolidating configuration validation and key reading into a single block or helper function for improved clarity and reduced repetition.

```cpp
#ifdef DTKCORE_CLASS_DConfigFile
// collapse validation & read all keys in one block, then handle GPU logic
auto dconfig = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
if (dconfig && dconfig->isValid()) {
    // read both keys without repeating isValid()
    if (dconfig->keyList().contains("specialComType")) {
        Common::specialComType = dconfig->value("specialComType").toInt();
    }
    if (dconfig->keyList().contains("TomlFilesName")) {
        Common::tomlFilesNameSet(dconfig->value("TomlFilesName").toString());
    }
    qCInfo(appLog) << "Common::specialComType value is:" << Common::specialComType;

    // isolate GPU pre-generation
    if (Common::specialComType == Common::kCustomType) {
        CommonTools::preGenerateGpuInfo();
    }
}
#endif
```

Or extract into a helper for clarity:

```cpp
#ifdef DTKCORE_CLASS_DConfigFile
static void loadCustomConfig() {
    auto cfg = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
    if (!cfg || !cfg->isValid()) return;

    Common::specialComType = cfg->value("specialComType", Common::specialComType).toInt();
    Common::tomlFilesNameSet(cfg->value("TomlFilesName", QString()).toString());
    qCInfo(appLog) << "Common::specialComType value is:" << Common::specialComType;

    if (Common::specialComType == Common::kCustomType)
        CommonTools::preGenerateGpuInfo();
}

loadCustomConfig();
#endif
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@GongHeng2017
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 7, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit beb3ba1 into linuxdeepin:develop/eagle Nov 7, 2025
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants