Skip to content

fix(hotspot): optimize hotspot switch sync latency - #598

Merged
caixr23 merged 1 commit into
linuxdeepin:masterfrom
caixr23:master
Aug 11, 2026
Merged

fix(hotspot): optimize hotspot switch sync latency#598
caixr23 merged 1 commit into
linuxdeepin:masterfrom
caixr23:master

Conversation

@caixr23

@caixr23 caixr23 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
  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. 在三级页面开关热点,返回二级页面,验证开关状态一致

Summary by Sourcery

Optimize hotspot toggle state synchronization latency between hotspot pages.

Bug Fixes:

  • Ensure hotspot switch state stays consistent and instantly reflected when navigating between secondary and tertiary hotspot pages.
  • Fix potential threading issues by binding NetManagerThreadPrivate parent thread to the application main thread instead of the constructing thread.

Enhancements:

  • Introduce a hotspot status enum and optimistic UI updates so the hotspot toggle reflects user actions immediately while awaiting backend confirmation.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @caixr23, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces 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 updates

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Introduce a local hotspot status state machine to support optimistic UI updates for the hotspot switch.
  • Add a Status enum (Disabling, Enabling, Disabled, Enabled) on PageHotspot and a hotspotStatus property initialized from netItem.isEnabled
  • Drive the switch checked binding from hotspotStatus instead of netItem.isEnabled
  • Disable user interaction on the switch while an enable/disable operation is in-flight based on hotspotStatus
  • On user click, set hotspotStatus to Enabling or Disabling before invoking NetManager connect/disconnect operations
  • Add an onIsEnabledChanged handler to reconcile hotspotStatus with netItem.isEnabled when backend state changes
dcc-network/qml/PageHotspot.qml
Ensure NetManagerThreadPrivate records the correct parent thread and perform minor cleanup.
  • Include QCoreApplication and use qApp->thread() when initializing m_parentThread instead of QThread::currentThread()
  • Remove an extraneous whitespace-only change in the destructor
net-view/operation/private/netmanagerthreadprivate.cpp

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

@caixr23
caixr23 requested a review from mhduiy August 10, 2026 03:51
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-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码通过引入状态机有效解决了热点开关异步操作导致的UI状态闪烁与重复点击问题
逻辑清晰且无安全漏洞,状态机设计合理,仅在异常处理边界上存在轻微优化空间

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

PageHotspot.qml 中引入了 Status 枚举和 hotspotStatus 属性,并在 onClicked 逻辑中根据 checked 状态切换至 EnablingDisabling 中间态,同时在 onIsEnabledChanged 信号中更新最终状态。逻辑闭环完整,有效阻断了异步期间的重复点击。
潜在问题:若底层异步操作失败且未触发 onIsEnabledChanged 信号,开关将永久停留在 EnablingDisabling 状态导致UI死锁。
建议:增加超时机制或错误处理回调,在异步操作失败时重置 hotspotStatus 为实际状态。

  • 2.代码质量(良好)✓

代码结构清晰,状态枚举命名规范,属性绑定表达式简洁明了。通过状态机解耦了UI显示与底层状态,提升了可维护性。
潜在问题:hotspotStatus 的初始值依赖 netItem,若 netItem 为 null 可能导致初始状态计算异常,虽然有三元运算符保护,但缺乏对 netItem 后续动态变化的完整绑定。
建议:确保 netItem 变化时能够重新评估 hotspotStatus 的初始状态,或在 setNetItem 函数中显式重置状态。

  • 3.代码性能(无性能问题)✓

仅使用简单的属性绑定和条件判断,未引入复杂的计算或循环,性能开销极低。
建议:保持现状即可。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
总体风险描述:本次修改未引入任何安全漏洞,代码仅涉及前端UI状态控制,不涉及敏感数据处理或系统权限操作。

  • 建议:无需额外安全修复措施。

■ 【改进建议代码示例】

// 建议在 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"]
                                     })
                    }
                }
            }

@caixr23
caixr23 requested a review from 18202781743 August 11, 2026 08:07
@deepin-ci-robot

Copy link
Copy Markdown

[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.

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

@caixr23
caixr23 merged commit 3328d46 into linuxdeepin:master Aug 11, 2026
17 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