Skip to content

fix: stop submenu loader delay timer when menu becomes visible#1509

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-290637
Mar 18, 2026
Merged

fix: stop submenu loader delay timer when menu becomes visible#1509
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-290637

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Mar 17, 2026

Fixed an issue where the submenu loader delay timer was not properly stopped when the menu becomes visible. This could cause timing issues where the timer might interfere with submenu loading behavior. The fix ensures that when the menu becomes visible, the delay timer is immediately stopped before activating the submenu loader, preventing any potential race conditions or unexpected behavior.

Influence:

  1. Test opening and closing system tray menus to ensure smooth submenu transitions
  2. Verify that submenus load correctly without delays when menu becomes visible
  3. Check that timer functionality still works correctly when menu is hidden
  4. Test with various system tray items that have submenus to ensure consistent behavior

fix: 当菜单可见时停止子菜单加载器延迟计时器

修复了当菜单变为可见时子菜单加载器延迟计时器未正确停止的问题。这可能导致
计时问题,计时器可能干扰子菜单加载行为。此修复确保当菜单变为可见时,在激
活子菜单加载器之前立即停止延迟计时器,防止任何潜在的竞争条件或意外行为。

Influence:

  1. 测试打开和关闭系统托盘菜单,确保子菜单转换流畅
  2. 验证当菜单变为可见时,子菜单能正确加载且无延迟
  3. 检查当菜单隐藏时,计时器功能仍能正常工作
  4. 测试具有子菜单的各种系统托盘项,确保行为一致

PMS: BUG-290637

Summary by Sourcery

Bug Fixes:

  • Stop the submenu loader delay timer as soon as the menu becomes visible to prevent race conditions and unintended loading delays in tray menus.

Fixed an issue where the submenu loader delay timer was not properly
stopped when the menu becomes visible. This could cause timing issues
where the timer might interfere with submenu loading behavior. The
fix ensures that when the menu becomes visible, the delay timer is
immediately stopped before activating the submenu loader, preventing any
potential race conditions or unexpected behavior.

Influence:
1. Test opening and closing system tray menus to ensure smooth submenu
transitions
2. Verify that submenus load correctly without delays when menu becomes
visible
3. Check that timer functionality still works correctly when menu is
hidden
4. Test with various system tray items that have submenus to ensure
consistent behavior

fix: 当菜单可见时停止子菜单加载器延迟计时器

修复了当菜单变为可见时子菜单加载器延迟计时器未正确停止的问题。这可能导致
计时问题,计时器可能干扰子菜单加载行为。此修复确保当菜单变为可见时,在激
活子菜单加载器之前立即停止延迟计时器,防止任何潜在的竞争条件或意外行为。

Influence:
1. 测试打开和关闭系统托盘菜单,确保子菜单转换流畅
2. 验证当菜单变为可见时,子菜单能正确加载且无延迟
3. 检查当菜单隐藏时,计时器功能仍能正常工作
4. 测试具有子菜单的各种系统托盘项,确保行为一致

PMS: BUG-290637
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures that when tray-related menus become visible, any pending submenu loader delay timer is stopped before activating the submenu loader, preventing race conditions and timing issues for submenu appearance in system tray popups.

Sequence diagram for submenu loading when menu becomes visible

sequenceDiagram
    actor User
    participant MenuPopup
    participant subMenuLoaderDelayTimer
    participant subMenuLoader

    User->>MenuPopup: openOrHoverTrayItem()
    MenuPopup->>MenuPopup: set menuVisible = true
    MenuPopup->>subMenuLoaderDelayTimer: stop()
    MenuPopup->>subMenuLoader: set active = true

    User->>MenuPopup: closeMenu()
    MenuPopup->>MenuPopup: set menuVisible = false
    MenuPopup->>subMenuLoaderDelayTimer: start()
    subMenuLoaderDelayTimer-->>subMenuLoader: triggerDelayedDeactivation()
Loading

File-Level Changes

Change Details Files
Stop the submenu loader delay timer when the tray surface popup menu becomes visible before activating the submenu loader.
  • In the menu visibility change handler, immediately stop the submenu loader delay timer if the menu is becoming visible.
  • Ensure submenu loader activation happens only after the delay timer is stopped to avoid overlapping behavior with the timer-based start when hidden.
panels/dock/tray/SurfacePopup.qml
Apply the same delay-timer stop behavior to tray item surface popups when their menus become visible.
  • Mirror the visibility-change handling logic to stop the submenu loader delay timer on menu show.
  • Maintain existing behavior of starting the delay timer when the menu becomes hidden so delayed loading still applies appropriately.
panels/dock/tray/TrayItemSurfacePopup.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

@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 - I've left some high level feedback:

  • The onMenuVisibleChanged handlers in SurfacePopup.qml and TrayItemSurfacePopup.qml are now identical; consider extracting this behavior into a shared component or helper to avoid duplication and keep future changes in one place.
  • Since subMenuLoaderDelayTimer.stop() is now called unconditionally when menuVisible becomes true, it may be worth confirming that stop() is safe when the timer is not running; if not guaranteed by the type, add a simple guard (e.g., if (subMenuLoaderDelayTimer.running)) to make the intent explicit.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `onMenuVisibleChanged` handlers in `SurfacePopup.qml` and `TrayItemSurfacePopup.qml` are now identical; consider extracting this behavior into a shared component or helper to avoid duplication and keep future changes in one place.
- Since `subMenuLoaderDelayTimer.stop()` is now called unconditionally when `menuVisible` becomes true, it may be worth confirming that `stop()` is safe when the timer is not running; if not guaranteed by the type, add a simple guard (e.g., `if (subMenuLoaderDelayTimer.running)`) to make the intent explicit.

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

deepin pr auto review

这段代码修改涉及 QML (Qt Modeling Language) 中的状态管理和定时器控制,主要目的是优化子菜单加载器的行为。以下是对该代码的详细审查和改进意见:

1. 代码逻辑审查

当前逻辑:
menuVisible 变为 true 时,代码执行了两个操作:

  1. 停止定时器 (subMenuLoaderDelayTimer.stop())
  2. 激活加载器 (subMenuLoader.active = true)

menuVisible 变为 false 时,启动定时器。

潜在问题:

  • 竞态条件:如果 menuVisible 在定时器运行期间频繁切换,可能会导致状态不一致。
  • 资源浪费:每次 menuVisible 变为 true 都会无条件激活加载器,即使加载器可能已经处于活动状态。

2. 代码质量建议

  1. 添加状态检查
    在激活加载器前检查其当前状态,避免不必要的操作:

    if (menuVisible) {
        subMenuLoaderDelayTimer.stop()
        if (!subMenuLoader.active) {
            subMenuLoader.active = true
        }
    }
  2. 定时器处理
    确保定时器在不需要时被正确清理。可以添加组件销毁时的处理:

    Component.onDestruction: {
        subMenuLoaderDelayTimer.stop()
    }

3. 性能优化建议

  1. 延迟加载优化
    如果子菜单加载耗时,可以考虑添加加载状态指示器:

    Loader {
        id: subMenuLoader
        asynchronous: true  // 异步加载
        onLoaded: {
            // 加载完成后的处理
        }
    }
  2. 内存管理
    当不再需要子菜单时,确保及时释放资源:

    onMenuVisibleChanged: {
        if (menuVisible) {
            subMenuLoaderDelayTimer.stop()
            subMenuLoader.active = true
        } else {
            subMenuLoaderDelayTimer.start()
            // 可选:延迟后卸载
            subMenuLoaderDelayTimer.onTriggered: {
                subMenuLoader.active = false
            }
        }
    }

4. 安全性建议

  1. 空指针检查
    确保 subMenuLoadersubMenuLoaderDelayTimer 在使用前已正确初始化:

    onMenuVisibleChanged: {
        if (menuVisible) {
            if (subMenuLoaderDelayTimer) {
                subMenuLoaderDelayTimer.stop()
            }
            if (subMenuLoader) {
                subMenuLoader.active = true
            }
        } else {
            if (subMenuLoaderDelayTimer) {
                subMenuLoaderDelayTimer.start()
            }
        }
    }
  2. 错误处理
    添加加载失败的错误处理:

    Loader {
        id: subMenuLoader
        onStatusChanged: {
            if (status === Loader.Error) {
                console.error("Failed to load sub menu:", sourceComponent.errorString())
            }
        }
    }

5. 综合改进建议代码

onMenuVisibleChanged: {
    if (menuVisible) {
        // 停止延迟卸载定时器
        if (subMenuLoaderDelayTimer && subMenuLoaderDelayTimer.running) {
            subMenuLoaderDelayTimer.stop()
        }
        // 激活加载器(如果尚未激活)
        if (subMenuLoader && !subMenuLoader.active) {
            subMenuLoader.active = true
        }
    } else {
        // 启动延迟卸载定时器
        if (subMenuLoaderDelayTimer) {
            subMenuLoaderDelayTimer.restart()
        }
    }
}

总结

这段代码的主要改进点包括:

  1. 添加了状态检查,避免不必要的操作
  2. 增强了错误处理和空指针检查
  3. 优化了资源管理
  4. 提高了代码的健壮性和可维护性

这些改进将使代码更加可靠,减少潜在的错误和性能问题。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@wjyrich
Copy link
Contributor Author

wjyrich commented Mar 18, 2026

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 18, 2026

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit 5892655 into linuxdeepin:master Mar 18, 2026
10 of 12 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