Skip to content

fix: Avoid datetime plugin seconds displayed not same with dcc's date…#358

Merged
yixinshark merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-dateTimeSecTips
Aug 28, 2025
Merged

fix: Avoid datetime plugin seconds displayed not same with dcc's date…#358
yixinshark merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-dateTimeSecTips

Conversation

@yixinshark

@yixinshark yixinshark commented Aug 27, 2025

Copy link
Copy Markdown
Contributor

…time

as title

Log: as title
Pms: BUG-289925

Summary by Sourcery

Ensure datetime plugin’s seconds display stays in sync with the control center by aligning the timer start to whole seconds and increasing its update frequency.

Bug Fixes:

  • Adjust the refresh timer to fire every 500ms instead of 1000ms to match the control center’s update frequency.
  • Use a singleShot timer to delay the initial update until the next whole second boundary.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

这段代码是关于日期时间插件的定时器设置部分,我来仔细审查并提供改进建议。

代码审查

语法逻辑

  1. 代码语法正确,逻辑基本清晰。
  2. 使用了lambda表达式和QTimer::singleShot来实现定时器的启动时间调整。
  3. 注释说明了修改原因:避免秒显示与控制中心显示不一致。

代码质量

  1. 变量命名 m_refershTimer 有拼写错误,应该是 m_refreshTimer
  2. 代码结构清晰,但可以增加适当的注释来解释lambda表达式的作用。

代码性能

  1. 将定时器间隔从1000ms改为500ms会增加CPU使用率,因为更新频率提高了一倍。
  2. 使用QTimer::singleShot来对齐整秒启动是合理的,但可以考虑是否真的需要如此频繁的更新。

代码安全

  1. 代码没有明显的安全问题。
  2. lambda表达式捕获了this指针,需要确保对象生命周期不会出现问题。

改进建议

  1. 修正变量命名错误:
m_refreshTimer->setInterval(500);  // 修正拼写错误
  1. 增加注释说明lambda表达式的作用:
// 整秒启动定时器,并增加更新频率,避免秒显示与控制中心显示不一致(控制中心500ms更新一次)
m_refreshTimer->setInterval(500);
// 计算距离下一个整秒的毫秒数,并在整秒时启动定时器
QTimer::singleShot(1000 - QTime::currentTime().msec(), [this]() {
    // 立即更新时间字符串
    updateCurrentTimeString();
    // 启动定时器,每500ms更新一次
    m_refreshTimer->start();
});
  1. 考虑性能优化:

    • 如果时间显示不需要500ms的更新频率,可以考虑保留1000ms的更新间隔,只在需要时(如秒变化时)更新显示。
    • 可以考虑使用QElapsedTimer来精确测量时间间隔,减少不必要的更新。
  2. 增加错误处理:

// 计算距离下一个整秒的毫秒数
int millisecondsToNextSecond = 1000 - QTime::currentTime().msec();
if (millisecondsToNextSecond < 0 || millisecondsToNextSecond > 1000) {
    // 如果计算结果异常,使用默认值100ms
    millisecondsToNextSecond = 100;
}
QTimer::singleShot(millisecondsToNextSecond, [this]() {
    try {
        updateCurrentTimeString();
        m_refreshTimer->start();
    } catch (...) {
        // 处理可能的异常
        qWarning() << "Failed to update current time string";
    }
});
  1. 考虑使用信号槽连接来确保对象生命周期安全:
// 使用Qt::QueuedConnection确保在对象存在时执行
connect(this, &DatetimePlugin::destroyed, m_refreshTimer, &QTimer::stop);

总结:这段代码的主要改进点在于修正拼写错误、增加适当的注释、考虑性能优化和增加错误处理。同时,可以进一步考虑更新频率的必要性,以及如何确保在对象生命周期内安全地使用定时器。

@sourcery-ai

sourcery-ai Bot commented Aug 27, 2025

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

Reviewer's Guide

Adjusted the datetime plugin’s refresh mechanism to increase update frequency and align the display of seconds with the control center by synchronizing the timer start at whole seconds.

File-Level Changes

Change Details Files
Synchronize and increase update frequency of the time display
  • Changed timer interval from 1000ms to 500ms
  • Used QTimer::singleShot to delay timer start until the next whole second
  • Added immediate updateCurrentTimeString() call before starting the periodic timer
plugins/dde-dock/datetime/datetimeplugin.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.

m_refershTimer->start();
// 整秒启动定时器,并增加更新频率,避免秒显示与控制中心显示不一致(控制中心500ms更新一次)
m_refershTimer->setInterval(500);
QTimer::singleShot(1000 - QTime::currentTime().msec(), [this]() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这个singleShot本身也不是一个精确的时间,这样能保证时间是要一致的么,

@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 merged commit 731064d into linuxdeepin:master Aug 28, 2025
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.

3 participants