-
Notifications
You must be signed in to change notification settings - Fork 54
feat: add delayed window state reset with singleShot #1291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR introduces a QTimer-based singleShot mechanism in DQmlGlobal to defer JavaScript callbacks, updates PanelPopupWindow to leverage delayed resets, and adds necessary includes to support the new functionality, addressing timing issues by delaying window state cleanup by 200ms. Class diagram for updated DQmlGlobal with singleShot methodclassDiagram
class DQmlGlobal {
+void singleShot(int msec, const QJSValue &callback)
+static void closeChildrenWindows(QWindow *target)
+bool grabKeyboard(QWindow *target, bool grab = true)
+bool grabMouse(QWindow *target, bool grab = true)
+DApplet *rootApplet() const
+static DQmlGlobal *instance()
}
DQmlGlobal --|> QObject
DQmlGlobal --|> DObject
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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 - here's some feedback:
- Use the public QJSValue header () instead of the private qjsvalue_p.h in dsqmlglobal_p.h to avoid relying on Qt private APIs.
- Protect the delayed singleShot call against DQmlGlobal being destroyed (for example by tying it to a QPointer or context) to avoid invoking callbacks on deleted objects.
- In PanelPopupWindow.qml, schedule only one pending reset (debounce) or cancel previous timers when visibility toggles rapidly to ensure the window state stays consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Use the public QJSValue header (<QJSValue>) instead of the private qjsvalue_p.h in dsqmlglobal_p.h to avoid relying on Qt private APIs.
- Protect the delayed singleShot call against DQmlGlobal being destroyed (for example by tying it to a QPointer or context) to avoid invoking callbacks on deleted objects.
- In PanelPopupWindow.qml, schedule only one pending reset (debounce) or cancel previous timers when visibility toggles rapidly to ensure the window state stays consistent.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
2889f4a
to
747e1ca
Compare
1. Added singleShot method to DQmlGlobal for delayed JavaScript callback execution 2. Implemented QTimer-based delayed callback with proper error handling 3. Modified PanelPopupWindow to use delayed reset instead of immediate cleanup 4. Added necessary includes for QTimer and QQmlEngine in implementation 5. Fixed potential timing issues by delaying window state reset by 200ms feat: 添加延迟窗口状态重置功能 1. 在 DQmlGlobal 中添加 singleShot 方法用于延迟执行 JavaScript 回调 2. 实现基于 QTimer 的延迟回调并包含错误处理 3. 修改 PanelPopupWindow 使用延迟重置替代立即清理 4. 在实现中添加必要的 QTimer 和 QQmlEngine 头文件包含 5. 通过延迟 200ms 重置窗口状态修复潜在时序问题
747e1ca
to
3aea476
Compare
deepin pr auto review我来对这段代码进行审查,从语法逻辑、代码质量、性能和安全性几个方面分析: 语法逻辑分析
代码质量分析
性能分析
安全性分析
具体改进建议
void DQmlGlobal::singleShot(int msec, QJSValue callback)
{
// 添加参数验证
if (msec < 0) {
qCWarning(dsLog) << "singleShot: invalid timeout value:" << msec;
return;
}
if (!callback.isCallable()) {
qCWarning(dsLog) << "singleShot: callback is not callable";
return;
}
// 使用 QWeakPointer 避免悬空指针
QWeakPointer<QObject> weakThis(this);
QTimer::singleShot(msec, this, [callback, weakThis]() {
if (weakThis.isNull()) {
return;
}
if (callback.isCallable()) {
// 设置执行超时
QFuture<void> future = QtConcurrent::run([callback]() {
QElapsedTimer timer;
timer.start();
callback.call();
if (timer.elapsed() > 1000) { // 假设最大执行时间为1秒
qCWarning(dsLog) << "singleShot callback execution time exceeded limit";
}
});
// 等待任务完成,但设置超时
if (!future.waitForFinished(1000)) {
qCWarning(dsLog) << "singleShot callback execution timeout";
}
}
});
}
// 定义常量
readonly property int HIDE_DELAY: 200
onVisibleChanged: DS.singleShot(HIDE_DELAY, (function () {
if(!root.visible)
return
currentItem = null
root.width = 10
root.height = 10
DS.closeChildrenWindows(root)
})) 这些改进可以提高代码的健壮性、安全性和可维护性。 |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, wjyrich The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/forcemerge |
This pr force merged! (status: behind) |
feat: 添加延迟窗口状态重置功能
Summary by Sourcery
Implement a QTimer-based singleShot API in DQmlGlobal for delayed JS callbacks and update PanelPopupWindow to use this delay for state reset, fixing timing glitches
New Features:
Bug Fixes:
Enhancements:
Build: