Skip to content

Conversation

@caixr23
Copy link
Contributor

@caixr23 caixr23 commented Oct 28, 2025

Add network OSD processing

pms: BUG-338381

Summary by Sourcery

Add on-screen display (OSD) handling for airplane mode and Wi-Fi state changes with configurable delays and throttling to prevent overlapping notifications.

New Features:

  • Display OSD notifications for airplane mode on/off and Wi-Fi connectivity changes

Enhancements:

  • Implement delayed and throttled OSD display using QTimer to avoid overlapping notifications
  • Introduce resetWifiOSDEnableTimeout setting to control the delay before re-enabling Wi-Fi OSD notifications

Chores:

  • Adjust hotspot QML label to use font weight property instead of bold flag

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 28, 2025

Reviewer's Guide

This PR adds on-screen display (OSD) handling for airplane mode and WiFi state changes by introducing timers and new event slots in NetworkStateHandler, extends SettingConfig to configure the OSD reset timeout, and tweaks a QML font weight property.

Sequence diagram for OSD handling on Airplane Mode property change

sequenceDiagram
participant "AirplaneMode DBus Service"
participant "NetworkStateHandler"
participant "OSD DBus Service"
"AirplaneMode DBus Service"->>"NetworkStateHandler": PropertiesChanged (Enabled/WifiEnabled)
alt Enabled changed
    "NetworkStateHandler"->>"NetworkStateHandler": onAirplaneModeEnabledChanged(bool)
    "NetworkStateHandler"->>"OSD DBus Service": showOSD("AirplaneModeOn"/"AirplaneModeOff")
    "NetworkStateHandler"->>"NetworkStateHandler": Start m_resetWifiOSDEnableTimer
else WifiEnabled changed
    "NetworkStateHandler"->>"NetworkStateHandler": onAirplaneModeWifiEnabledChanged(bool)
    "NetworkStateHandler"->>"NetworkStateHandler": Start m_delayShowWifiOSD
end
Loading

ER diagram for SettingConfig OSD timeout property

erDiagram
SETTINGCONFIG {
  int m_resetWifiOSDEnableTimeout
}
Loading

Class diagram for updated NetworkStateHandler and SettingConfig

classDiagram
class NetworkStateHandler {
  +bool m_wifiOSDEnable
  +bool m_wifiEnabled
  +QTimer* m_delayShowWifiOSD
  +QTimer* m_resetWifiOSDEnableTimer
  +void onAirplaneModeWifiEnabledChanged(bool enabled)
  +void onAirplaneModeEnabledChanged(bool enabled)
  +void onAirplaneModePropertiesChanged(const QString &, const QVariantMap &properties, const QStringList &)
  +void showOSD(const QString &signal)
  +void resetWifiOSDEnable()
  +void delayShowWifiOSD()
  +void updateOSDTimer(int interval)
}
class SettingConfig {
  +int m_resetWifiOSDEnableTimeout
  +int resetWifiOSDEnableTimeout() const
  +void resetWifiOSDEnableTimeoutChanged(int)
}
NetworkStateHandler --> SettingConfig : uses
Loading

File-Level Changes

Change Details Files
Add OSD processing for airplane mode and WiFi events in NetworkStateHandler
  • Introduce m_wifiOSDEnable, m_wifiEnabled and two QTimer members to manage OSD delays
  • Connect timers and D-Bus signals (AirplaneMode properties) in the constructor and initialize OSD timer
  • Implement slots: onAirplaneModeEnabledChanged, onAirplaneModeWifiEnabledChanged, onAirplaneModePropertiesChanged
  • Add showOSD, delayShowWifiOSD, resetWifiOSDEnable and updateOSDTimer methods
network-service-plugin/src/session/networkstatehandler.cpp
network-service-plugin/src/session/networkstatehandler.h
Expose and handle resetWifiOSDEnableTimeout in SettingConfig
  • Add resetWifiOSDEnableTimeout getter and corresponding signal in the header
  • Load, default and emit resetWifiOSDEnableTimeout in onValueChanged and constructor
  • Emit resetWifiOSDEnableTimeoutChanged when config value updates
network-service-plugin/src/utils/settingconfig.cpp
network-service-plugin/src/utils/settingconfig.h
Refine font weight usage in QML PageHotspot
  • Replace deprecated 'bold' property with 'weight: 700' in the Label font settings
dcc-network/qml/PageHotspot.qml

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

Copy link

@sourcery-ai sourcery-ai bot left a 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:

  • The resetWifiOSDEnableTimer is currently connected to delayShowWifiOSD(), but it should call resetWifiOSDEnable() to re-enable the WiFi OSD rather than trigger another show call.
  • Consider validating or clamping the configured timeout to ensure updateOSDTimer(interval - 50) can’t result in a negative or zero interval.
  • The magic “–50” offset in updateOSDTimer isn’t documented—extract it into a named constant or add a comment explaining why the delay is interval minus 50 ms.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The resetWifiOSDEnableTimer is currently connected to delayShowWifiOSD(), but it should call resetWifiOSDEnable() to re-enable the WiFi OSD rather than trigger another show call.
- Consider validating or clamping the configured timeout to ensure updateOSDTimer(interval - 50) can’t result in a negative or zero interval.
- The magic “–50” offset in updateOSDTimer isn’t documented—extract it into a named constant or add a comment explaining why the delay is interval minus 50 ms.

## Individual Comments

### Comment 1
<location> `network-service-plugin/src/session/networkstatehandler.cpp:729-738` </location>
<code_context>
+    m_wifiOSDEnable = true;
+}
+
+void NetworkStateHandler::delayShowWifiOSD()
+{
+    // 禁用WIFI网络OSD时退出
+    if (!m_wifiOSDEnable) {
+        return;
+    }
+
+    // if enabled is true, wifi rfkill block is true
+    // so wlan is off
+    if (m_wifiEnabled) {
+        showOSD("WLANOff");
+    } else { // if enabled is false, wifi is off
</code_context>

<issue_to_address>
**issue (bug_risk):** Logic for showing WLANOn/WLANOff OSD may be inverted.

Please verify that the OSD display matches the actual WiFi state, as the current logic appears to contradict the variable naming.
</issue_to_address>

### Comment 2
<location> `network-service-plugin/src/session/networkstatehandler.cpp:745-749` </location>
<code_context>
+    }
+}
+
+void NetworkStateHandler::updateOSDTimer(int interval)
+{
+    m_delayShowWifiOSD->setInterval(interval - 50);
+    m_resetWifiOSDEnableTimer->setInterval(interval);
+}
+
</code_context>

<issue_to_address>
**suggestion:** Subtracting 50ms from interval for m_delayShowWifiOSD may cause negative values.

Add a check to ensure the interval does not fall below a safe minimum before subtracting 50ms.

```suggestion
void NetworkStateHandler::updateOSDTimer(int interval)
{
    const int minDelayOSDInterval = 50; // Minimum safe interval in ms
    int delayOSDInterval = interval - 50;
    if (delayOSDInterval < minDelayOSDInterval) {
        delayOSDInterval = minDelayOSDInterval;
    }
    m_delayShowWifiOSD->setInterval(delayOSDInterval);
    m_resetWifiOSDEnableTimer->setInterval(interval);
}
```
</issue_to_address>

### Comment 3
<location> `network-service-plugin/src/session/networkstatehandler.cpp:63` </location>
<code_context>
     , m_replacesId(0)
+    , m_wifiOSDEnable(true)
+    , m_wifiEnabled(true)
+    , m_delayShowWifiOSD(new QTimer(this))
+    , m_resetWifiOSDEnableTimer(new QTimer(this))
 {
</code_context>

<issue_to_address>
**issue (complexity):** Consider replacing the two timers and multiple flags with a single QTimer and an enum to manage delayed OSD actions.

Here’s one way to collapse those two timers and the flag‐juggling into a single `QTimer` plus a small enum to track what action to take when it fires.  It preserves:

- delaying the Wi-Fi OSD  
- resetting the “can-show-Wi-Fi‐OSD” flag  
- immediate AirplaneMode OSD  

```cpp
// in NetworkStateHandler.h
enum class PendingOsd { None, ShowWifiOn, ShowWifiOff, ResetWifiEnable };

QTimer*      m_osdTimer   = new QTimer(this);
PendingOsd   m_pendingOsd = PendingOsd::None;
bool         m_canShowWifiOsd = true;
bool         m_wifiEnabled = true;
int          m_baseInterval;  // from settings
```

```cpp
// in ctor – replace both timers
connect(m_osdTimer, &QTimer::timeout, this, &NetworkStateHandler::onOsdTimer);
m_baseInterval = SettingConfig::instance()->resetWifiOSDEnableTimeout();
m_osdTimer->setInterval(m_baseInterval);
```

```cpp
// shared helper to schedule any delayed OSD task
void NetworkStateHandler::scheduleOsd(PendingOsd what, int ms)
{
    m_pendingOsd = what;
    m_osdTimer->start(ms);
}

void NetworkStateHandler::onAirplaneModeEnabledChanged(bool enabled)
{
    // block Wifi-OSD, show Airplane OSD immediately
    m_canShowWifiOsd = false;
    showOSD(enabled ? "AirplaneModeOn" : "AirplaneModeOff");

    // schedule resetting the Wifi-OSD flag
    scheduleOsd(PendingOsd::ResetWifiEnable, m_baseInterval);
}

void NetworkStateHandler::onAirplaneModeWifiEnabledChanged(bool enabled)
{
    if (!m_canShowWifiOsd)
        return;
    m_wifiEnabled = enabled;
    // wait “m_baseInterval – 50” before showing Wifi OSD
    scheduleOsd(enabled ? PendingOsd::ShowWifiOff
                        : PendingOsd::ShowWifiOn,
                m_baseInterval - 50);
}

void NetworkStateHandler::onOsdTimer()
{
    switch (m_pendingOsd) {
      case PendingOsd::ShowWifiOn:
        showOSD("WLANOn");
        break;
      case PendingOsd::ShowWifiOff:
        showOSD("WLANOff");
        break;
      case PendingOsd::ResetWifiEnable:
        m_canShowWifiOsd = true;
        break;
      case PendingOsd::None: break;
    }
    m_pendingOsd = PendingOsd::None;
    m_osdTimer->stop();
}
```

This removes the second timer and the extra boolean flag, centralizes all delayed work in one place, and keeps exactly the same behavior.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +729 to +738
void NetworkStateHandler::delayShowWifiOSD()
{
// 禁用WIFI网络OSD时退出
if (!m_wifiOSDEnable) {
return;
}

// if enabled is true, wifi rfkill block is true
// so wlan is off
if (m_wifiEnabled) {
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Logic for showing WLANOn/WLANOff OSD may be inverted.

Please verify that the OSD display matches the actual WiFi state, as the current logic appears to contradict the variable naming.

Comment on lines 745 to 752
void NetworkStateHandler::updateOSDTimer(int interval)
{
m_delayShowWifiOSD->setInterval(interval - 50);
m_resetWifiOSDEnableTimer->setInterval(interval);
}
Copy link

Choose a reason for hiding this comment

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

suggestion: Subtracting 50ms from interval for m_delayShowWifiOSD may cause negative values.

Add a check to ensure the interval does not fall below a safe minimum before subtracting 50ms.

Suggested change
void NetworkStateHandler::updateOSDTimer(int interval)
{
m_delayShowWifiOSD->setInterval(interval - 50);
m_resetWifiOSDEnableTimer->setInterval(interval);
}
void NetworkStateHandler::updateOSDTimer(int interval)
{
const int minDelayOSDInterval = 50; // Minimum safe interval in ms
int delayOSDInterval = interval - 50;
if (delayOSDInterval < minDelayOSDInterval) {
delayOSDInterval = minDelayOSDInterval;
}
m_delayShowWifiOSD->setInterval(delayOSDInterval);
m_resetWifiOSDEnableTimer->setInterval(interval);
}

@caixr23 caixr23 requested a review from mhduiy October 28, 2025 07:54
robertkill
robertkill previously approved these changes Oct 28, 2025
Add network OSD processing

pms: BUG-338381
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个diff进行详细的代码审查:

  1. QML部分修改(PageHotspot.qml):
font: DccUtils.copyFont(D.DTK.fontManager.t5, {
-   "bold": true
+   "weight": 700
})

改进建议:

  • 这是一个好的改进,使用具体的数字值(700)替代布尔值(true)来表示字体粗细,更符合现代字体规范
  • 建议在代码中添加注释说明700对应的是Bold字重,提高代码可读性
  1. NetworkStateHandler.cpp修改:
    主要添加了飞行模式相关的OSD显示功能。

改进建议:

a) 构造函数中的定时器初始化:

m_delayShowWifiOSD(new QTimer(this))
m_resetWifiOSDEnableTimer(new QTimer(this))
  • 建议为定时器设置单次触发属性:setSingleShot(true),因为从代码逻辑看这些定时器都是单次使用的

b) updateOSDTimer函数:

if (interval < 60) {
    interval = 60;
}
m_delayShowWifiOSD->setInterval(interval - 50);
m_resetWifiOSDEnableTimer->setInterval(interval);
  • 建议将60这个魔数定义为常量,比如:const int MIN_INTERVAL = 60;
  • interval - 50的计算逻辑应该添加注释说明为什么需要减去50毫秒

c) delayShowWifiOSD函数:

if (m_wifiEnabled) {
    showOSD("WLANOff");
} else {
    showOSD("WLANOn");
}
  • 注释中的逻辑与实际代码相反,应该修正注释说明
  1. SettingConfig相关修改:
    添加了新的配置项resetWifiOSDEnableTimeout。

改进建议:

  • 建议为默认值300添加单位说明(毫秒)
  • 建议在配置项变更时添加范围检查,确保timeout值在合理范围内
  1. 安全性考虑:
  • 所有DBus连接都应该添加错误处理
  • OSD显示的信号字符串应该进行验证,防止注入攻击
  • 定时器的interval值应该有上限限制,防止设置过大的值导致系统问题
  1. 性能优化:
  • 可以考虑将频繁使用的OSD信号字符串定义为常量
  • 定时器的创建和管理可以考虑使用对象池模式
  1. 代码规范:
  • 新增的成员变量应该添加详细的注释说明
  • 建议统一使用m_前缀命名成员变量(当前代码已经遵循了这个规范)
  • 建议为新增的公共接口添加详细的文档注释
  1. 错误处理:
  • 建议在DBus调用中添加错误处理机制
  • 建议在定时器操作中添加异常处理

这些修改主要实现了飞行模式和WiFi状态变化的OSD显示功能,整体设计合理,但在代码细节和错误处理方面还有改进空间。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, robertkill

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 abccb3e into linuxdeepin:master Oct 29, 2025
15 of 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