Skip to content

fix: prevent duplicate OSD actions for same type#1113

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
May 7, 2025
Merged

fix: prevent duplicate OSD actions for same type#1113
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

@18202781743 18202781743 commented May 6, 2025

  1. Added lastOsdType tracking in OsdPanel to store previous OSD type
  2. Modified displaymode, kblayout, and windoweffect OSD handlers to only
    trigger actions when current type matches last type
  3. This prevents duplicate actions when receiving multiple OSD
    notifications of same type in quick succession
  4. Added Q_PROPERTY for lastOsdType to make it accessible from QML
  5. Updated hideOsd and showOsd methods to properly manage lastOsdType
    state

fix: 防止相同类型OSD的重复操作

  1. 在OsdPanel中添加lastOsdType跟踪以存储先前的OSD类型
  2. 修改了displaymode、kblayout和windoweffect的OSD处理程序,仅在当前类型
    与上次类型匹配时才触发操作
  3. 防止在快速连续收到相同类型的多个OSD通知时出现重复操作
  4. 添加了lastOsdType的Q_PROPERTY使其可从QML访问
  5. 更新了hideOsd和showOsd方法以正确管理lastOsdType状态

pms: BUG-304139

Summary by Sourcery

Prevent duplicate OSD actions for the same type by tracking the last OSD type and adding logic to only trigger actions when the current OSD type matches the previous one

New Features:

  • Added lastOsdType Q_PROPERTY to make OSD type history accessible from QML

Bug Fixes:

  • Prevent duplicate OSD notifications from triggering multiple actions in quick succession

Enhancements:

  • Added tracking of last OSD type in OsdPanel
  • Implemented conditional action triggering based on OSD type

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 6, 2025

Reviewer's Guide

This pull request prevents duplicate On-Screen Display (OSD) actions for rapidly received notifications of the same type. It introduces state tracking in the C++ OsdPanel by adding a lastOsdType variable, which is updated when the OSD is shown or hidden. This state is exposed to QML via a Q_PROPERTY. The QML handlers for display mode, keyboard layout, and window effect OSDs were modified to only trigger their respective actions if the current OSD type matches the stored lastOsdType.

Sequence diagram for QML OSD action check

sequenceDiagram
    participant OsdPanel as OsdPanel (C++)
    participant QMLHandler as QML Handler (e.g., displaymode)

    OsdPanel->>QMLHandler: osdTypeChanged(newType) signal
    activate QMLHandler
    QMLHandler->>QMLHandler: update(newType) function called
    QMLHandler->>OsdPanel: Read lastOsdType property
    activate OsdPanel
    OsdPanel-->>QMLHandler: Return lastOsdTypeValue
    deactivate OsdPanel
    QMLHandler->>QMLHandler: Check if lastOsdTypeValue == newType
    alt Condition is true (lastOsdTypeValue == newType)
        QMLHandler->>QMLHandler: Perform OSD Action (e.g., Applet.next())
    else Condition is false
        QMLHandler->>QMLHandler: Skip OSD Action
    end
    deactivate QMLHandler
Loading

Class diagram for OsdPanel changes

classDiagram
    class OsdPanel {
        <<C++ Class>>
        -QString m_lastOsdType
        +QString lastOsdType() const
        #void hideOsd()
        #void showOsd()
        #void updateLastOsdType(const QString &osdType)
        +Q_PROPERTY(QString lastOsdType READ lastOsdType CONSTANT)
    }
    note for OsdPanel "New members:\n- m_lastOsdType\n- lastOsdType()\n- updateLastOsdType()\n- Q_PROPERTY lastOsdType\nModified methods:\n- hideOsd()\n- showOsd()"
Loading

File-Level Changes

Change Details Files
Added state tracking for the last displayed OSD type.
  • Introduced m_lastOsdType member variable.
  • Added updateLastOsdType slot and lastOsdType getter.
  • Modified showOsd and hideOsd to manage m_lastOsdType state.
  • Exposed lastOsdType to QML via Q_PROPERTY.
panels/notification/osd/osdpanel.h
panels/notification/osd/osdpanel.cpp
Conditionally trigger OSD actions based on the last OSD type.
  • Added a check Panel.lastOsdType === osdType before executing actions in display mode, keyboard layout, and window effect handlers.
panels/notification/osd/windoweffect/package/main.qml
panels/notification/osd/displaymode/package/main.qml
panels/notification/osd/kblayout/package/main.qml

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

@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 @18202781743 - I've reviewed your changes - here's some feedback:

  • The logic triggers actions (like cycling modes) only when the current OSD type matches the previous one; consider if the action should trigger on the first notification instead.
  • The lastOsdType Q_PROPERTY is marked CONSTANT but its underlying value changes; consider adding a NOTIFY signal or removing CONSTANT.
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.

Comment thread panels/notification/osd/osdpanel.h Outdated
mhduiy
mhduiy previously approved these changes May 7, 2025
Comment thread panels/notification/osd/osdpanel.h Outdated
@18202781743 18202781743 force-pushed the master branch 2 times, most recently from 41c8a9d to b8b76aa Compare May 7, 2025 02:54
@18202781743 18202781743 requested a review from mhduiy May 7, 2025 03:36
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

1. Added lastOsdType tracking in OsdPanel to store the most recent OSD
type
2. Modified displaymode, kblayout and windoweffect OSD handlers to only
perform actions if the current OSD type matches the last one
3. This prevents duplicate actions when multiple OSD events of same type
are triggered in quick succession
4. Added updateLastOsdType method to track and clear the last OSD type
when hiding

fix: 防止相同类型OSD的重复操作

1. 在OsdPanel中添加lastOsdType跟踪最近显示的OSD类型
2. 修改了displaymode、kblayout和windoweffect的OSD处理逻辑,仅在当前OSD类
型与最后一次相同时才执行操作
3. 防止在快速连续触发相同类型OSD事件时重复执行操作
4. 添加updateLastOsdType方法来跟踪并在隐藏时清除最后OSD类型
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. osdpanel.cpp文件中,updateLastOsdType函数中,如果m_lastOsdType的值没有改变,则没有必要执行任何操作。可以考虑添加一个日志记录或者条件判断来避免不必要的操作。

  2. osdpanel.h文件中,lastOsdType函数被标记为Q_INVOKABLE,这意味着它可以通过QML调用。如果这个函数不是必须通过QML访问的,建议移除Q_INVOKABLE标记,以减少QML和C++之间的耦合。

  3. main.qml文件中,Panel.lastOsdType()函数的调用被包裹在一个条件判断中,这可能是为了确保只有在osdType匹配时才执行Applet.next()Qt.callLater。这种做法是合理的,但需要确保Panel.lastOsdType()函数的调用不会引入性能问题,特别是在高频调用的场景下。

  4. main.qml文件中,Qt.callLater函数的使用可能不是最优的选择,因为它会在当前事件循环的末尾执行,可能会导致延迟。如果延迟不是问题,可以考虑使用setTimeout函数来代替。

  5. main.qml文件中,match(osdType)函数的调用没有在代码片段中显示,需要确保这个函数的实现是正确的,并且能够正确地匹配osdType

  6. main.qml文件中,Applet.next()Qt.callLater函数的调用没有错误处理机制。如果这些操作失败,应该添加适当的错误处理逻辑。

  7. main.qml文件中,effectModel.count的使用没有在代码片段中显示,需要确保effectModel是一个有效的模型,并且count属性是可访问的。

  8. main.qml文件中,control.selectIndex的更新使用了模运算符%,这可能会导致selectIndex的值超出有效范围。需要确保effectModel.count的值是有效的,并且不会导致selectIndex的值变为负数。

以上是针对代码审查的几点意见,希望能够对你有所帮助。

@18202781743
Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented May 7, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 53be1c3 into linuxdeepin:master May 7, 2025
7 of 10 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