fix(hotspot): optimize hotspot switch sync latency - #598
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIntroduces an optimistic hotspot status state machine in PageHotspot to eliminate UI latency when syncing hotspot switch state across secondary and tertiary pages, and fixes NetManagerThreadPrivate to pin its parent thread to the QCoreApplication thread instead of the thread at construction time. Sequence diagram for optimistic hotspot switch state updatessequenceDiagram
actor User
participant PageHotspot
participant switchControl as D_Switch
participant dccData
participant NetManager
participant NetItem
User->>switchControl: onClicked
alt [checked is true]
switchControl->>PageHotspot: hotspotStatus = Status.Enabling
switchControl->>dccData: exec(NetManager.SetConnectInfo, netItem_id, config)
else [checked is false]
switchControl->>PageHotspot: hotspotStatus = Status.Disabling
switchControl->>dccData: exec(NetManager.Disconnect, netItem_id, uuid)
end
dccData->>NetManager: SetConnectInfo/Disconnect
NetManager-->>NetItem: update isEnabled
NetItem-->>PageHotspot: onIsEnabledChanged()
PageHotspot->>PageHotspot: hotspotStatus = isEnabled ? Status.Enabled : Status.Disabled
PageHotspot-->>switchControl: checked bound to hotspotStatus
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Add Status enum (Disabling, Enabling, Disabled, Enabled) to track hotspot state independently from backend 2. Use optimistic update: set Enabling/Disabling on click, revert to Enabled/Disabled when onIsEnabledChanged fires 3. This eliminates the visible delay when navigating between secondary and tertiary hotspot pages Log: Hotspot switch state syncs instantly on page navigation PMS: BUG-298043 Influence: 1. Toggle hotspot on secondary page, enter tertiary page and back, verify switch reflects the clicked state immediately 2. Toggle hotspot on tertiary page, return to secondary page, verify switch state is consistent fix(hotspot): 优化个人热点开关状态同步延迟 1. 新增 Status 枚举(Disabling, Enabling, Disabled, Enabled), 独立于后端跟踪热点状态 2. 采用乐观更新策略:点击时设置 Enabling/Disabling, 收到 onIsEnabledChanged 后回归 Enabled/Disabled 3. 消除二级页面和三级页面切换时开关状态同步的可感知延迟 Log: 个人热点开关状态在页面切换时即时同步 PMS: BUG-298043 Influence: 1. 在二级页面开关热点,进入三级页面后返回,验证开关立即反映点击状态 2. 在三级页面开关热点,返回二级页面,验证开关状态一致
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 建议在 setNetItem 中增加状态重置逻辑,并考虑增加超时保护机制
function setNetItem(item) {
if (netItem !== item) {
netItem = item
// 重置状态以匹配新 item 的实际状态
root.hotspotStatus = (item && item.isEnabled) ? PageHotspot.Status.Enabled : PageHotspot.Status.Disabled
}
}
// 在异步操作处可考虑增加 Timer 作为超时回退机制(伪代码示例)
D.Switch {
id: switchControl
anchors.fill: parent
checked: root.hotspotStatus === PageHotspot.Status.Enabled || root.hotspotStatus === PageHotspot.Status.Enabling
enabled: netItem.enabledable && !isAirplane && netItem.deviceEnabled && root.hotspotStatus !== PageHotspot.Status.Enabling && root.hotspotStatus !== PageHotspot.Status.Disabling
onClicked: {
if (checked) {
root.hotspotStatus = PageHotspot.Status.Enabling
// operationTimeout.restart()
if (config["connection"]["uuid"] === "{00000000-0000-0000-0000-000000000000}") {
dccData.exec(NetManager.SetConnectInfo, netItem.id, config)
} else {
// ...
}
} else {
root.hotspotStatus = PageHotspot.Status.Disabling
// operationTimeout.restart()
dccData.exec(NetManager.Disconnect, netItem.id, {
"uuid": config["connection"]["uuid"]
})
}
}
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, caixr23 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 |
track hotspot state independently from backend
revert to Enabled/Disabled when onIsEnabledChanged fires
secondary and tertiary hotspot pages
Log: Hotspot switch state syncs instantly on page navigation
PMS: BUG-298043
Influence:
back, verify switch reflects the clicked state immediately
verify switch state is consistent
fix(hotspot): 优化个人热点开关状态同步延迟
独立于后端跟踪热点状态
收到 onIsEnabledChanged 后回归 Enabled/Disabled
Log: 个人热点开关状态在页面切换时即时同步
PMS: BUG-298043
Influence:
Summary by Sourcery
Optimize hotspot toggle state synchronization latency between hotspot pages.
Bug Fixes:
Enhancements: