Skip to content

Conversation

@fly602
Copy link
Contributor

@fly602 fly602 commented Dec 9, 2025

Add conditional display for charging protection status in battery tips When battery is not charging and percentage is below 100%, show "charging protection active" message
When battery is not charging but percentage is 100%, maintain original "not charging" message
This provides clearer indication when charging protection feature is active versus normal not-charging state

Log: Added charging protection status indication in battery tips

Influence:

  1. Test with battery percentage below 100% and charging protection active
  2. Test with battery at 100% and not charging
  3. Verify tooltip and applet tip display correct messages for each scenario
  4. Check message consistency between tooltip and applet display
  5. Test with different battery percentages to ensure proper conditional logic

feat: 添加充电保护状态显示

在电池提示信息中添加充电保护状态的条件显示
当电池未充电且电量低于100%时,显示"充电保护已激活"信息
当电池未充电但电量为100%时,保持原有的"未充电"显示
这提供了更清晰的充电保护功能激活状态与普通未充电状态的区分

Log: 在电池提示信息中新增充电保护状态指示

Influence:

  1. 测试电池电量低于100%且充电保护激活时的显示
  2. 测试电池电量为100%且未充电时的显示
  3. 验证工具提示和应用提示在不同场景下显示正确的消息
  4. 检查工具提示和应用提示之间消息显示的一致性
  5. 测试不同电池电量百分比以确保条件逻辑正确

Summary by Sourcery

Clarify battery status tips for non-charging states.

New Features:

  • Show a distinct charging protection active message in battery tips and applet tips when the battery is not charging and below 100%.

Enhancements:

  • Preserve the existing not charging messaging when the battery is at 100% to distinguish normal non-charging from charging protection behavior.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 9, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds conditional logic to the dock power plugin so that when the battery is in NOT_CHARGED state, the tooltip and applet tip distinguish between normal not-charging at 100% and charging protection being active below 100%.

Sequence diagram for updated battery tooltip messages in NOT_CHARGED state

sequenceDiagram
    actor User
    participant DockApplet
    participant PowerPlugin
    participant BatteryService

    User->>DockApplet: Hover_over_battery_icon()
    DockApplet->>PowerPlugin: refreshTipsData()
    PowerPlugin->>BatteryService: getBatteryState()
    BatteryService-->>PowerPlugin: batteryState = NOT_CHARGED
    PowerPlugin->>BatteryService: getBatteryPercentage()
    BatteryService-->>PowerPlugin: percentage

    alt percentage < 100
        PowerPlugin-->>DockApplet: tips = Capacity_%1,_charging_protection_active
        PowerPlugin-->>DockApplet: appletTips = Charging_protection_active
    else percentage == 100
        PowerPlugin-->>DockApplet: tips = Capacity_%1,_not_charging
        PowerPlugin-->>DockApplet: appletTips = Not_charging
    end

    DockApplet-->>User: Show_tooltip_and_applet_tip()
Loading

Flow diagram for conditional tooltip logic in NOT_CHARGED state

flowchart TD
    A[batteryState == NOT_CHARGED] --> B{percentage < 100}
    B -->|Yes| C[Set tips to Capacity_%1,_charging_protection_active]
    C --> D[Set appletTips to Charging_protection_active]
    B -->|No| E[Set tips to Capacity_%1,_not_charging]
    E --> F[Set appletTips to Not_charging]
Loading

File-Level Changes

Change Details Files
Add conditional messaging for NOT_CHARGED battery state to indicate charging protection status when charge is below 100%.
  • Wrap existing NOT_CHARGED tooltip/applet tip assignment in a percentage-based conditional
  • For percentage below 100, set tooltip to show capacity with 'charging protection active' and applet tip to 'Charging protection active'
  • For percentage at 100, preserve existing messages: capacity with 'not charging' and applet tip 'Not charging'
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

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 - here's some feedback:

  • The new charging protection active branch is keyed only on batteryState == NOT_CHARGED && percentage < 100, which may mislabel normal unplugged states as protection mode; consider wiring this to an explicit charging-protection flag or state instead of inferring solely from percentage.
  • With the new logic, batteryState == NOT_CHARGED && percentage == 100 now bypasses the FULLY_CHARGED || percentage == 100 branch; verify this ordering matches the intended state model, or consider restructuring the conditions so that the 100% case is handled in a single place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `charging protection active` branch is keyed only on `batteryState == NOT_CHARGED && percentage < 100`, which may mislabel normal unplugged states as protection mode; consider wiring this to an explicit charging-protection flag or state instead of inferring solely from percentage.
- With the new logic, `batteryState == NOT_CHARGED && percentage == 100` now bypasses the `FULLY_CHARGED || percentage == 100` branch; verify this ordering matches the intended state model, or consider restructuring the conditions so that the 100% case is handled in a single place.

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.

if (m_chargingProtectThreshold < CHARGING_PROTECT_THRESHOLD_MIN || m_chargingProtectThreshold >= CHARGING_PROTECT_THRESHOLD_MAX) {
m_chargingProtectThreshold = CHARGING_PROTECT_THRESHOLD_MIN;
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个else 分支,是不是不需要?否则下面的refreshTipsData()执行不到了,

Add conditional display for charging protection status in battery tips
When battery is not charging and percentage is below 100%, show
"charging protection active" message
When battery is not charging but percentage is 100%, maintain original
"not charging" message
This provides clearer indication when charging protection feature is
active versus normal not-charging state

Log: Added charging protection status indication in battery tips

Influence:
1. Test with battery percentage below 100% and charging protection
active
2. Test with battery at 100% and not charging
3. Verify tooltip and applet tip display correct messages for each
scenario
4. Check message consistency between tooltip and applet display
5. Test with different battery percentages to ensure proper conditional
logic

feat: 添加充电保护状态显示

在电池提示信息中添加充电保护状态的条件显示
当电池未充电且电量低于100%时,显示"充电保护已激活"信息
当电池未充电但电量为100%时,保持原有的"未充电"显示
这提供了更清晰的充电保护功能激活状态与普通未充电状态的区分

Log: 在电池提示信息中新增充电保护状态指示

Influence:
1. 测试电池电量低于100%且充电保护激活时的显示
2. 测试电池电量为100%且未充电时的显示
3. 验证工具提示和应用提示在不同场景下显示正确的消息
4. 检查工具提示和应用提示之间消息显示的一致性
5. 测试不同电池电量百分比以确保条件逻辑正确
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个 diff 进行详细的代码审查:

  1. 功能变更分析:
  • 添加了充电保护功能,允许用户设置充电保护阈值(80-99%)
  • 当电量在保护阈值范围内且未充电时,显示充电保护激活状态
  1. 代码质量审查:

优点:

  • 配置项定义清晰,包含了多语言支持
  • 使用了合理的常量定义(CHARGING_PROTECT_THRESHOLD_MIN/MAX)
  • 增加了输入值验证,确保阈值在有效范围内
  • 代码结构清晰,逻辑分离良好

需要改进的地方:

  1. 常量定义问题:
#define CHARGING_PROTECT_THRESHOLD_MAX 100

这里最大值定义为100,但实际配置允许的最大值是99,建议改为:

#define CHARGING_PROTECT_THRESHOLD_MAX 99
  1. 输入验证逻辑优化:
if (m_chargingProtectThreshold < CHARGING_PROTECT_THRESHOLD_MIN || m_chargingProtectThreshold >= CHARGING_PROTECT_THRESHOLD_MAX) {
    m_chargingProtectThreshold = CHARGING_PROTECT_THRESHOLD_MIN;
}

建议添加日志记录,方便调试:

if (m_chargingProtectThreshold < CHARGING_PROTECT_THRESHOLD_MIN || m_chargingProtectThreshold >= CHARGING_PROTECT_THRESHOLD_MAX) {
    qWarning() << "Invalid charging protect threshold:" << m_chargingProtectThreshold << ", using default value";
    m_chargingProtectThreshold = CHARGING_PROTECT_THRESHOLD_MIN;
}
  1. 代码安全性:
  • 配置值的读取没有进行类型检查,建议增加:
bool ok;
int threshold = m_config->value("chargingProtectThreshold").toInt(&ok);
if (!ok) {
    qWarning() << "Failed to parse charging protect threshold";
    m_chargingProtectThreshold = CHARGING_PROTECT_THRESHOLD_MIN;
    return;
}
  1. 性能考虑:
  • 每次配置变更都会触发 refreshTipsData(),可以考虑添加防抖机制,避免频繁更新
  1. 代码组织:
  • 建议将充电保护相关的逻辑抽取为独立的方法,提高代码可维护性:
bool PowerPlugin::isChargingProtectionActive(int percentage) const {
    return percentage < CHARGING_PROTECT_THRESHOLD_MAX && 
           percentage >= m_chargingProtectThreshold;
}
  1. 翻译文件:
  • 新增的翻译字符串需要确保在所有语言版本中都得到正确翻译
  1. 错误处理:
  • 配置文件无效时的处理可以更完善,目前只是简单返回,建议添加错误恢复机制
  1. 测试建议:
  • 需要增加边界值测试(80、99等)
  • 需要测试配置无效值时的行为
  • 需要测试多语言环境下的显示效果

总结:
这个功能实现基本正确,但在错误处理、代码组织和性能优化方面还有改进空间。建议在正式发布前进行充分的测试,特别是边界条件和异常情况的测试。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, fly602

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

@fly602 fly602 merged commit ce31029 into linuxdeepin:master Dec 10, 2025
10 of 11 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