Skip to content

fix: power applet tips need not display when dconfig item was closed#355

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-powerAppletTips
Aug 26, 2025
Merged

fix: power applet tips need not display when dconfig item was closed#355
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-powerAppletTips

Conversation

@yixinshark

@yixinshark yixinshark commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

as title

Log: as title
Pms: BUG-301387

Summary by Sourcery

Bug Fixes:

  • Restrict tip display to only when m_showTimeToFull is true for both charging and discharging battery states

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来对这段代码进行审查:

语法逻辑

这段代码修改了一个条件判断语句,将原来的条件判断改写为更简洁的形式。原代码中使用了两个并列的条件,使用括号和逻辑运算符组合,新代码则通过调整条件的顺序,使逻辑更加清晰。

代码质量

  1. 改进后的代码质量有所提升,因为:

    • 减少了括号的嵌套层级,提高了可读性
    • m_showTimeToFull 作为前置条件,避免了不必要的条件判断
    • 逻辑更加直观,更容易理解
  2. 建议改进:

    • 可以考虑将 BatteryState 枚举值定义为常量或宏,以提高代码可维护性
    • 可以添加注释说明这个条件判断的具体目的,特别是对于 m_showTimeToFull 变量的用途

代码性能

  1. 性能影响:

    • 这次修改对性能影响微乎其微,因为只是改变了条件判断的顺序
    • 实际执行时间基本不变,因为逻辑运算的复杂度相同
  2. 优化建议:

    • 如果 m_showTimeToFull 是一个频繁变化的值,可以考虑将其缓存
    • 可以考虑将 BatteryState 的判断提取为一个单独的函数,提高代码复用性

代码安全

  1. 安全性分析:

    • 代码本身没有明显的安全问题
    • 条件判断使用了枚举类型,避免了魔法数字,提高了安全性
  2. 安全建议:

    • 可以考虑为 BatteryState 枚举添加边界检查,防止未来可能的枚举值扩展导致的问题
    • 建议添加对 m_tipsLabel 的空指针检查,防止潜在的空指针异常

总体而言,这次代码改写是合理的,提高了代码的可读性和可维护性。建议采纳上述改进建议,以进一步提升代码质量。

@sourcery-ai

sourcery-ai Bot commented Aug 26, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR simplifies and refines the conditional in PowerPlugin::refreshTipsData to ensure battery tips are only shown when the ‘showTimeToFull’ option is enabled and the battery is either charging or discharging, fixing the bug where tips still appeared when the config item was disabled.

Class diagram for updated PowerPlugin::refreshTipsData logic

classDiagram
    class PowerPlugin {
        - m_systemPowerInter : SystemPowerInter*
        - m_batteryStateChangedTimer : QTimer*
        - m_showTimeToFull : bool
        - m_tipsLabel : QLabel*
        + refreshTipsData()
    }
    class SystemPowerInter {
        + batteryStatus() : int
    }
    PowerPlugin --> SystemPowerInter : uses
Loading

File-Level Changes

Change Details Files
Unified and simplified the battery tips display condition
  • Merged two separate conditions into one combined check
  • Reordered operands to consistently require m_showTimeToFull
  • Simplified the boolean expression for clarity
plugins/dde-dock/power/powerplugin.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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!


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
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy, yixinshark

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

@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

1 similar comment
@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Aug 26, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 0575cc7 into linuxdeepin:master Aug 26, 2025
7 of 9 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.

4 participants