fix: handle notification closed signal properly#1066
fix: handle notification closed signal properly#1066wjyrich merged 1 commit intolinuxdeepin:masterfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds handling of the NotificationClosed signal in the Bluetooth notification initialization so that the global notification ID is reset when its corresponding notification is closed, preventing stale ID references and improving notification lifecycle correctness. Sequence diagram for notification closed handling with globalNotifyId resetsequenceDiagram
participant User
participant BluetoothModule
participant NotificationService
User->>BluetoothModule: Trigger Bluetooth event
BluetoothModule->>NotificationService: Create notification
NotificationService-->>BluetoothModule: Return notification id
BluetoothModule->>BluetoothModule: Set globalNotifyId = id
NotificationService-->>BluetoothModule: Signal NotificationClosed(id, reason)
BluetoothModule->>BluetoothModule: ConnectNotificationClosed handler invoked
BluetoothModule->>BluetoothModule: Lock globalNotifyMu
alt Closed notification matches current id
BluetoothModule->>BluetoothModule: globalNotifyId = 0
else Different notification id
BluetoothModule->>BluetoothModule: Leave globalNotifyId unchanged
end
BluetoothModule->>BluetoothModule: Unlock globalNotifyMu
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 left some high level feedback:
- In the
ConnectNotificationClosedcallback, consider usingdefer globalNotifyMu.Unlock()immediately afterglobalNotifyMu.Lock()to make the critical section safer and less error-prone if the callback body is modified in the future.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the `ConnectNotificationClosed` callback, consider using `defer globalNotifyMu.Unlock()` immediately after `globalNotifyMu.Lock()` to make the critical section safer and less error-prone if the callback body is modified in the future.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Added connection to the NotificationClosed signal in initNotifications function to properly handle when notifications are closed. When a notification is closed, the globalNotifyId should be reset to 0 to prevent stale notification ID references. This ensures the system correctly tracks active notifications and avoids potential issues with notification management. Influence: 1. Test notification creation and closure scenarios 2. Verify globalNotifyId is properly reset when notifications are closed 3. Check for any race conditions in notification ID management 4. Ensure notification system stability after multiple open/close cycles fix: 正确处理通知关闭信号 在 initNotifications 函数中添加了对 NotificationClosed 信号的连接,以正 确处理通知关闭事件。当通知被关闭时,需要将 globalNotifyId 重置为 0,以 防止过时的通知ID引用。这确保系统能正确跟踪活动通知,避免通知管理中的潜在 问题。 主要为了,蓝牙模块在连接后,通知发出来后,此时等待通知bubble消失,然后断开蓝牙连接,会导致通知读取不到原来窗口,导致不显示窗口, 目前处理是监听通知横幅关闭,从而重置窗口id,保证断开后能够显示正确一个新窗口。 PMS: BUG-352131
deepin pr auto review这段代码的 diff 展示了对 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议总结
修改后的代码示例(包含注释和日志格式优化): _, err = globalNotifications.ConnectNotificationClosed(func(id uint32, reason uint32) {
globalNotifyMu.Lock()
// 如果关闭的是当前记录的通知ID,则重置全局ID,防止状态残留
if globalNotifyId == id {
globalNotifyId = 0
}
globalNotifyMu.Unlock()
})
if err != nil {
// 增加了空格,优化了可读性
logger.Warningf("listen notification closed failed, err: %v", err)
}总体而言,这段代码的修改是正确且安全的,主要改进点在于细节的打磨和健壮性的考量。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, wjyrich 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 |
Added connection to the NotificationClosed signal in initNotifications function to properly handle when notifications are closed. When a notification is closed, the globalNotifyId should be reset to 0 to prevent stale notification ID references. This ensures the system correctly tracks active notifications and avoids potential issues with notification management.
Influence:
fix: 正确处理通知关闭信号
在 initNotifications 函数中添加了对 NotificationClosed 信号的连接,以正 确处理通知关闭事件。当通知被关闭时,需要将 globalNotifyId 重置为 0,以
防止过时的通知ID引用。这确保系统能正确跟踪活动通知,避免通知管理中的潜在
问题。
主要为了,蓝牙模块在连接后,通知发出来后,此时等待通知bubble消失,然后断开蓝牙连接,会导致通知读取不到原来窗口,导致不显示窗口, 目前处理是监听通知横幅关闭,从而重置窗口id,保证断开后能够显示正确一个新窗口。
PMS: BUG-352131
Summary by Sourcery
Bug Fixes: