Skip to content

fix: timeDate plugin crash#321

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-datetimeCrash
Jun 9, 2025
Merged

fix: timeDate plugin crash#321
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-datetimeCrash

Conversation

@yixinshark

@yixinshark yixinshark commented Jun 6, 2025

Copy link
Copy Markdown
Contributor

dock position changed(from bottom to left), new dock size is not update, use bottom width to adjust font size, then assert in timeFontSize != 0 && dateFontSize != 0

Log: as title

Summary by Sourcery

Prevent invalid dock size values from causing font size assertion failures and ensure font size adjustment occurs after dock position changes.

Bug Fixes:

  • Guard against unreasonably large distance values in adjustFontSize to avoid zero font sizes crashing assertions
  • Replace hardcoded 999 with MAX_DISTANCE constant for font size mapping
  • Call adjustFontSize after updateDateTime on dock position change to apply new dock dimensions correctly

Enhancements:

  • Log dock size updates in setDockPanelSize for debugging purposes

@sourcery-ai

sourcery-ai Bot commented Jun 6, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces a MAX_DISTANCE guard to prevent invalid font-size calculations when the dock size isn’t updated, updates the font-size map bound, adds logging for dock size changes, and refines when font-size adjustment runs after a dock position change.

Updated Class Diagram for DatetimeWidget

classDiagram
    class DatetimeWidget {
        +adjustFontSize() void
        +setDockPanelSize(const QSize &dockSize) void
        +dockPositionChanged() void
    }
Loading

Flow Diagram for adjustFontSize Logic

graph TD
    A[Start adjustFontSize] --> B(Get dock position from qApp);
    B --> C(Calculate validDistance);
    C --> D{validDistance > MAX_DISTANCE?};
    D -- Yes --> E[Return early];
    D -- No --> F(Calculate font size using fontSizeMap);
    F --> G[Apply font size];
    G --> H[End adjustFontSize];
Loading

File-Level Changes

Change Details Files
Add safety guard for oversized dock sizes and update font-size map bounds
  • Define MAX_DISTANCE constant
  • Early-return if validDistance exceeds MAX_DISTANCE
  • Replace hardcoded 999 with MAX_DISTANCE in fontSizeMap
plugins/dde-dock/datetime/datetimewidget.cpp
Defer adjustFontSize to run after updateDateTime on dock position change
  • Add adjustFontSize call inside QTimer lambda after updateDateTime
  • Remove immediate adjustFontSize call at end of dockPositionChanged
plugins/dde-dock/datetime/datetimewidget.cpp
Log dock panel size on updates
  • Insert qInfo() logging in setDockPanelSize to output dockSize
plugins/dde-dock/datetime/datetimewidget.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 @yixinshark - I've reviewed your changes - here's some feedback:

  • Instead of returning early when validDistance exceeds MAX_DISTANCE, consider clamping it to MAX_DISTANCE so that maximum font sizes still get applied instead of skipping adjustment altogether.
  • The new qInfo() call in setDockPanelSize may clutter production logs—consider switching it to qDebug() or guarding it behind a verbosity check.
  • The hard-coded MAX_DISTANCE value (999) is arbitrary; think about deriving it from the fontSizeMap or documenting its origin to simplify future maintenance.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

validDistance = m_dockSize.width() / devicePixelRatioF();
}

// dock position changed(from bottom to left), new dock size is not update, use bottom width to adjust font size,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick: Improve clarity of English comment

The comment is unclear and has grammatical errors. Please rewrite it to clearly explain the fallback logic, such as: "If dock position changes before m_dockSize updates, use previous dimensions to prevent font size assertions."

@yixinshark yixinshark force-pushed the fix-datetimeCrash branch 2 times, most recently from 5a238c9 to 3bb5bd5 Compare June 6, 2025 09:48
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 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 yixinshark force-pushed the fix-datetimeCrash branch from 3bb5bd5 to 3433192 Compare June 9, 2025 02:38
dock position changed(from bottom to left), new dock size is not update,
use bottom width to adjust font size, then assert in timeFontSize != 0 && dateFontSize != 0

Log: as title
@yixinshark yixinshark force-pushed the fix-datetimeCrash branch from 3433192 to 49fe536 Compare June 9, 2025 02:38
@deepin-ci-robot

Copy link
Copy Markdown

@yixinshark: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
github-trigger-obs-ci 49fe536 link true /test github-trigger-obs-ci

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. 常量命名

    • MAX_DISTANCE 常量命名应遵循项目中的命名规范,例如使用全大写字母和下划线分隔,如 MAX_DISTANCE
  2. 注释

    • 注释应该更加详细,解释为什么需要 MAX_DISTANCE 以及它的具体作用。
  3. 逻辑判断

    • adjustFontSize 函数中,if (validDistance > MAX_DISTANCE) 判断后直接 return,这可能会导致在某些情况下字体大小没有被正确调整。建议添加注释说明为什么在这种情况下不调整字体大小。
  4. 代码重复

    • dockPositionChanged 函数中,adjustFontSize 被调用了两次,一次在 QTimer::singleShot 回调中,一次在函数末尾。建议只调用一次,以避免重复操作。
  5. 性能优化

    • adjustFontSize 函数中使用了 QMap 来存储字体大小映射,如果这个映射不会频繁变化,可以考虑使用 QHash 来提高查找效率。
  6. 错误处理

    • adjustFontSize 函数中,如果 validDistance 超过 MAX_DISTANCE,函数直接返回,没有错误处理或日志记录。建议添加错误处理或日志记录,以便在调试时能够追踪问题。
  7. 代码风格

    • adjustFontSize 函数中的注释应该使用中文,但代码主体部分最好使用英文注释,以保持代码的一致性。
  8. 代码可读性

    • adjustFontSize 函数中的注释应该更加详细,解释为什么需要根据 validDistance 来调整字体大小,以及如何根据 validDistance 来确定字体大小。

综合以上意见,代码可以进一步优化以提高可读性、性能和健壮性。

@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 9, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 84965c2 into linuxdeepin:master Jun 9, 2025
6 of 7 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