fix(tray): pre-create stashed popup to eliminate first-open lag#1508
fix(tray): pre-create stashed popup to eliminate first-open lag#1508Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuidePre-creates the stashed tray popup at startup with zero opacity and then closes it shortly after to eliminate first-open lag, adding a preCreation state and a timer-driven lifecycle around the popup. Sequence diagram for pre-created stashed tray popup lifecycle at startupsequenceDiagram
actor User
participant SystemStartup
participant TrayApplet
participant stashedPopup
participant preCreateCloseTimer
SystemStartup->>TrayApplet: initialize()
TrayApplet->>stashedPopup: set preCreating = true
TrayApplet->>stashedPopup: set opacity = 0
TrayApplet->>TrayApplet: Qt.callLater(callback)
TrayApplet-->>SystemStartup: initialization complete
Note over TrayApplet,stashedPopup: Deferred pre-creation callback
TrayApplet->>stashedPopup: preCreating = false
TrayApplet->>stashedPopup: open()
TrayApplet->>preCreateCloseTimer: start(interval = 200ms)
preCreateCloseTimer-->>TrayApplet: triggered
TrayApplet->>stashedPopup: close()
TrayApplet->>stashedPopup: preCreating = false
Note over User,TrayApplet: First user interaction after pre-creation
User->>TrayApplet: hover_or_click_tray_icon()
TrayApplet->>stashedPopup: open() (components already initialized)
State diagram for stashed tray popup pre-creation lifecyclestateDiagram-v2
[*] --> PreCreatingInvisible
PreCreatingInvisible: preCreating = true
PreCreatingInvisible: opacity = 0
PreCreatingInvisible --> PreOpenVisible: Qt.callLater callback
PreOpenVisible: preCreating = false
PreOpenVisible: open()
PreOpenVisible --> ClosedReady: preCreateCloseTimer triggered
ClosedReady: preCreating = false
ClosedReady: closed but fully initialized
ClosedReady --> OpenVisibleOnUserAction: user hover_or_click_tray_icon
OpenVisibleOnUserAction: popup opened without lag
OpenVisibleOnUserAction --> ClosedReady: popup close
ClosedReady --> [*]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
preCreatingflag is never set totrue(it’s initialized asfalseand then explicitly reset tofalseagain), so the opacity binding is effectively a no-op; consider initializing it totrueand only setting it tofalseafter the pre-creation open/close sequence finishes so the popup is actually transparent during pre-creation. - There’s a potential race where
preCreateCloseTimerwill close the popup if the user opens it manually within the first 200ms after startup; consider stopping the timer or guarding the close logic based on the popup’s current state to avoid closing a user-opened popup.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `preCreating` flag is never set to `true` (it’s initialized as `false` and then explicitly reset to `false` again), so the opacity binding is effectively a no-op; consider initializing it to `true` and only setting it to `false` after the pre-creation open/close sequence finishes so the popup is actually transparent during pre-creation.
- There’s a potential race where `preCreateCloseTimer` will close the popup if the user opens it manually within the first 200ms after startup; consider stopping the timer or guarding the close logic based on the popup’s current state to avoid closing a user-opened popup.
## Individual Comments
### Comment 1
<location path="panels/dock/tray/package/tray.qml" line_range="46-48" />
<code_context>
property alias dropHover: stashContainer.dropHover
property alias stashItemDragging: stashContainer.stashItemDragging
+ property bool preCreating: false
+
+ opacity: preCreating ? 0 : 1
popupX: DockPanelPositioner.x
</code_context>
<issue_to_address>
**issue (bug_risk):** The `preCreating` flag is never set to `true`, so the opacity binding has no effect.
Since `preCreating` is only ever set to `false`, `opacity` will always be `1` and this binding has no effect. If the goal is to hide the popup during pre-creation, set `preCreating = true` before `open()` and reset it to `false` after `close()` (or when pre-creation finishes). As written, the new property doesn’t change behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
PS:想要一个不用定时器的修改方法。 |
Pre-create the stashed tray popup during initialization to avoid lag when first opening it, especially noticeable at high DPI scales (225%). The popup is opened with zero opacity during startup and closed after 200ms, ensuring all components are fully initialized. This eliminates the frame drops and stuttering that occurred when hovering over or clicking the application tray button for the first time. 修复系统托盘折叠弹窗首次打开时的卡顿问题。在初始化时预创建弹窗, 通过设置透明度为0在后台完成组件初始化和渲染,避免首次打开时的 帧率下降和卡顿,特别是在高DPI缩放(225%)下的表现。 PMS: BUG-344705
ed9fd77 to
60e5d00
Compare
deepin pr auto review这段代码是为了解决托盘弹出窗口首次打开时的延迟问题,通过预先打开并迅速关闭弹出窗口来实现预热。以下是对该代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议以下是优化后的代码示例: AppletItem {
// ... 其他代码 ...
property bool preCreating: false
property int preCreateDelay: 200 // 可配置的预热延迟时间
opacity: preCreating ? 0 : 1
// ... 其他代码 ...
Component.onCompleted: {
DockPanelPositioner.bounding = Qt.binding(function () {
return Qt.rect(collapsedBtnCenterPoint.x, collapsedBtnCenterPoint.y, stashedPopup.width, stashedPopup.height)
})
// 预热弹出窗口
Qt.callLater(preCreatePopup)
}
function preCreatePopup() {
try {
stashedPopup.preCreating = true
stashedPopup.open()
preCreateCloseTimer.start()
} catch (error) {
console.error("Failed to pre-create popup:", error)
stashedPopup.preCreating = false
}
}
Timer {
id: preCreateCloseTimer
interval: preCreateDelay
repeat: false
onTriggered: {
try {
stashedPopup.close()
} finally {
stashedPopup.preCreating = false
}
}
}
// ... 其他代码 ...
}主要改进点:
测试建议
通过以上改进,代码的健壮性、可维护性和性能都会得到提升。 |
Pre-create the stashed tray popup during initialization to avoid lag when first opening it, especially noticeable at high DPI scales (225%). The popup is opened with zero opacity during startup and closed after 200ms, ensuring all components are fully initialized. This eliminates the frame drops and stuttering that occurred when hovering over or clicking the application tray button for the first time.
修复系统托盘折叠弹窗首次打开时的卡顿问题。在初始化时预创建弹窗,
通过设置透明度为0在后台完成组件初始化和渲染,避免首次打开时的
帧率下降和卡顿,特别是在高DPI缩放(225%)下的表现。
PMS: BUG-344705
Summary by Sourcery
Eliminate the initial lag when opening the stashed tray popup by pre-creating and briefly showing it invisibly during initialization.
Bug Fixes:
Enhancements: