Skip to content

fix: prevent notifications when user inactive#490

Open
caixr23 wants to merge 1 commit intolinuxdeepin:masterfrom
caixr23:master
Open

fix: prevent notifications when user inactive#490
caixr23 wants to merge 1 commit intolinuxdeepin:masterfrom
caixr23:master

Conversation

@caixr23
Copy link
Contributor

@caixr23 caixr23 commented Feb 4, 2026

Added user activity check to notification system to prevent sending notifications when user is not actively using the system. The new isUserActive() method queries systemd-logind via D-Bus to determine if the current user session is active and not remote.

The change ensures notifications are only shown when the user is present and actively using the system, preventing unnecessary distractions during inactive periods or remote sessions. This improves user experience by reducing notification spam when the user cannot see them.

Log: Network notifications now respect user activity status

Influence:

  1. Test network notifications appear when user is actively using the system
  2. Verify notifications are suppressed when user session is inactive
  3. Test notification behavior during remote desktop sessions
  4. Verify notification suppression when system is locked or user is away
  5. Test different network state changes (connection/disconnection/VPN events)

fix: 防止用户非活动时发送通知

在通知系统中添加用户活动状态检查,防止在用户未主动使用系统时发送通知。新
增的 isUserActive() 方法通过 D-Bus 查询 systemd-logind 来确定当前用户会 话是否活跃且非远程会话。

该变更确保通知仅在用户在场且主动使用系统时显示,避免在用户非活动期间或远
程会话时产生不必要的干扰。通过减少用户无法看到通知时的通知垃圾,提升了用
户体验。

Log: 网络通知现在会尊重用户活动状态

Influence:

  1. 测试用户主动使用系统时网络通知是否正常显示
  2. 验证用户会话非活动时通知是否被抑制
  3. 测试远程桌面会话期间的通知行为
  4. 验证系统锁定或用户离开时通知抑制功能
  5. 测试不同网络状态变化(连接/断开/VPN事件)的通知行为

PMS: BUG-349057

Summary by Sourcery

Bug Fixes:

  • Prevent network notifications from being shown when the user session is inactive or remote by checking user activity status before sending notifications.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 4, 2026

Reviewer's Guide

Adds a user-activity check to the network notification path so that network notifications are suppressed when the current systemd-logind user session is inactive or remote, using D-Bus queries in a new helper method.

Sequence diagram for network notifications with user activity check

sequenceDiagram
    participant NetworkStateHandler
    participant SystemDBus
    participant Login1Manager
    participant Login1User
    participant Login1Session
    participant NotificationDaemon

    NetworkStateHandler->>NetworkStateHandler: notify(icon, summary, body)
    alt notifications_disabled
        NetworkStateHandler-->>NetworkStateHandler: return (m_notifyEnabled is false)
    else notifications_enabled
        NetworkStateHandler->>NetworkStateHandler: isUserActive()

        Note over NetworkStateHandler,SystemDBus: Query login1 for current user
        NetworkStateHandler->>SystemDBus: org.freedesktop.login1.Manager.GetUser(uid)
        SystemDBus->>Login1Manager: GetUser(uid)
        Login1Manager-->>SystemDBus: QDBusObjectPath userPath
        SystemDBus-->>NetworkStateHandler: userPath

        alt get_user_error
            NetworkStateHandler-->>NetworkStateHandler: isUserActive returns false
        else user_path_ok
            NetworkStateHandler->>SystemDBus: org.freedesktop.DBus.Properties.GetAll(User)
            SystemDBus->>Login1User: GetAll(org.freedesktop.login1.User)
            Login1User-->>SystemDBus: QVariantMap userInfo
            SystemDBus-->>NetworkStateHandler: userInfo

            alt user_state_not_active
                NetworkStateHandler-->>NetworkStateHandler: isUserActive returns false
            else user_state_active
                NetworkStateHandler->>NetworkStateHandler: parse Display(id, displayPath)
                alt display_path_empty
                    NetworkStateHandler-->>NetworkStateHandler: isUserActive returns false
                else display_path_valid
                    NetworkStateHandler->>SystemDBus: org.freedesktop.DBus.Properties.GetAll(Session)
                    SystemDBus->>Login1Session: GetAll(org.freedesktop.login1.Session)
                    Login1Session-->>SystemDBus: QVariantMap sessionInfo
                    SystemDBus-->>NetworkStateHandler: sessionInfo

                    alt inactive_or_remote_session
                        NetworkStateHandler-->>NetworkStateHandler: isUserActive returns false
                    else active_local_session
                        NetworkStateHandler-->>NetworkStateHandler: isUserActive returns true
                    end
                end
            end
        end

        alt user_active
            NetworkStateHandler->>NotificationDaemon: show notification(icon, summary, body)
            NotificationDaemon-->>NetworkStateHandler: ack
        else user_inactive
            NetworkStateHandler-->>NetworkStateHandler: skip notification
        end
    end
Loading

Updated class diagram for NetworkStateHandler with user activity check

classDiagram
    class NetworkStateHandler {
        - bool m_notifyEnabled
        + void notify(QString icon, QString summary, QString body)
        + void notifyVpnFailed(QString id, uint reason)
        + bool isUserActive()
    }

    class SystemDBus {
        + QDBusPendingReply asyncCall(QDBusMessage message)
    }

    class Login1Manager {
        + QDBusObjectPath GetUser(uid_t uid)
    }

    class Login1User {
        + QVariantMap GetAllUserProperties()
    }

    class Login1Session {
        + QVariantMap GetAllSessionProperties()
    }

    NetworkStateHandler ..> SystemDBus : uses
    SystemDBus ..> Login1Manager : forwards_calls
    SystemDBus ..> Login1User : forwards_calls
    SystemDBus ..> Login1Session : forwards_calls
Loading

File-Level Changes

Change Details Files
Gate network notifications on a new D-Bus–based user activity check.
  • Extend the notify() method to early-return when notifications are disabled or the current user is not active
  • Implement isUserActive() to query systemd-logind via D-Bus for the current uid, retrieve the associated User properties, and verify the user State is "active"
  • From the User.Display property, resolve the session object path and query Session properties, returning inactive when the session is not Active, is Remote, or when any D-Bus step fails
  • Add warning logs for D-Bus errors when fetching user or session information
network-service-plugin/src/session/networkstatehandler.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

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

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 - I've found 1 issue, and left some high level feedback:

  • isUserActive() performs multiple synchronous D-Bus round-trips on every notification; consider caching the activity state or listening to logind signals (e.g., Session.New/Removed, PropertiesChanged) to avoid adding latency and load to frequent notify() calls.
  • The new logic returns false (disabling notifications) on any D-Bus error; if logind is unavailable or transiently failing this will silently suppress all notifications, so you may want to fail open (default to active) or distinguish between "inactive" and "unknown" states.
  • When reading the "Display" property, you assume the QVariant contains a valid QDBusArgument structure; adding checks for canConvert() and validating the structure before beginStructure()/operator>> would make this more robust against unexpected logind responses.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- isUserActive() performs multiple synchronous D-Bus round-trips on every notification; consider caching the activity state or listening to logind signals (e.g., Session.New/Removed, PropertiesChanged) to avoid adding latency and load to frequent notify() calls.
- The new logic returns false (disabling notifications) on any D-Bus error; if logind is unavailable or transiently failing this will silently suppress all notifications, so you may want to fail open (default to active) or distinguish between "inactive" and "unknown" states.
- When reading the "Display" property, you assume the QVariant contains a valid QDBusArgument structure; adding checks for canConvert<QDBusArgument>() and validating the structure before beginStructure()/operator>> would make this more robust against unexpected logind responses.

## Individual Comments

### Comment 1
<location> `network-service-plugin/src/session/networkstatehandler.cpp:862` </location>
<code_context>
     notify(notifyIconVpnDisconnected, tr("Disconnected"), m_vpnErrorTable[reason]);
 }

+bool NetworkStateHandler::isUserActive()
+{
+    uid_t uid = getuid();
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring `isUserActive()` into smaller helpers with centralized D-Bus constants and blocking calls to simplify the control flow and encapsulate low-level details.

You can keep the same behavior but significantly reduce complexity in `isUserActive()` by:

1. **Splitting D-Bus orchestration into small helpers**
2. **Hiding `QDBusArgument` unpacking behind a dedicated helper**
3. **Using synchronous calls for these status checks**
4. **Centralizing repeated D-Bus strings**

Example refactor sketch:

```c++
// 1) Centralize constants (top of .cpp or in anonymous namespace)
namespace {
constexpr auto LOGIN1_SERVICE        = "org.freedesktop.login1";
constexpr auto LOGIN1_MANAGER_PATH   = "/org/freedesktop/login1";
constexpr auto LOGIN1_MANAGER_IFACE  = "org.freedesktop.login1.Manager";
constexpr auto DBUS_PROPERTIES_IFACE = "org.freedesktop.DBus.Properties";
constexpr auto LOGIN1_USER_IFACE     = "org.freedesktop.login1.User";
constexpr auto LOGIN1_SESSION_IFACE  = "org.freedesktop.login1.Session";
}

// 2) Small helpers for D-Bus calls
static QDBusObjectPath getLogin1UserPath(uid_t uid)
{
    QDBusMessage msg = QDBusMessage::createMethodCall(
        LOGIN1_SERVICE, LOGIN1_MANAGER_PATH, LOGIN1_MANAGER_IFACE, "GetUser");
    msg << uid;

    const auto reply = QDBusConnection::systemBus().call(msg);
    if (reply.type() == QDBusMessage::ErrorMessage) {
        qCWarning(DSM()) << "get User error:" << reply.errorMessage();
        return {};
    }
    return reply.arguments().value(0).value<QDBusObjectPath>();
}

static QVariantMap getAllProperties(const QDBusObjectPath &path, const char *iface)
{
    QDBusMessage msg = QDBusMessage::createMethodCall(
        LOGIN1_SERVICE, path.path(), DBUS_PROPERTIES_IFACE, "GetAll");
    msg << QString::fromLatin1(iface);

    const auto reply = QDBusConnection::systemBus().call(msg);
    if (reply.type() == QDBusMessage::ErrorMessage) {
        qCWarning(DSM()) << "get" << iface << "info error:" << reply.errorMessage();
        return {};
    }
    return reply.arguments().value(0).toMap();
}
```

Hide the low‑level `Display` unpacking:

```c++
static QDBusObjectPath extractDisplayPath(const QVariant &displayVariant)
{
    const QDBusArgument arg = displayVariant.value<QDBusArgument>();
    QString id;
    QDBusObjectPath path;

    arg.beginStructure();
    arg >> id;
    arg >> path;
    arg.endStructure();

    return path;
}
```

Then `isUserActive()` itself becomes mainly high‑level checks:

```c++
bool NetworkStateHandler::isUserActive()
{
    const uid_t uid = getuid();
    const QDBusObjectPath userPath = getLogin1UserPath(uid);
    if (userPath.path().isEmpty()) {
        return false;
    }

    const QVariantMap userInfo = getAllProperties(userPath, LOGIN1_USER_IFACE);
    if (userInfo.isEmpty() || userInfo.value("State") != "active") {
        return false;
    }

    const QDBusObjectPath displayPath = extractDisplayPath(userInfo.value("Display"));
    if (displayPath.path().isEmpty()) {
        return false;
    }

    const QVariantMap sessionInfo = getAllProperties(displayPath, LOGIN1_SESSION_IFACE);
    if (sessionInfo.isEmpty()) {
        return false;
    }

    if (!sessionInfo.value("Active").toBool() ||
        sessionInfo.value("Remote").toBool()) {
        return false;
    }

    return true;
}
```

This keeps all behavior (same interfaces, properties, checks) but:

- Removes deep inline D-Bus orchestration
- Encapsulates `QDBusArgument` handling
- Uses straightforward blocking `call()` for a simple boolean check
- Reduces magic strings and repeated error handling code
</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.

@caixr23 caixr23 force-pushed the master branch 3 times, most recently from 95af48e to 8527d80 Compare February 4, 2026 08:17
@caixr23 caixr23 requested a review from mhduiy February 4, 2026 08:26
@caixr23 caixr23 force-pushed the master branch 4 times, most recently from dd783f0 to 62e60e2 Compare February 5, 2026 03:01
Added user activity check to notification system to prevent sending
notifications when user is not actively using the system. The new
isUserActive() method queries systemd-logind via D-Bus to determine if
the current user session is active and not remote.

The change ensures notifications are only shown when the user is present
and actively using the system, preventing unnecessary distractions
during inactive periods or remote sessions. This improves user
experience by reducing notification spam when the user cannot see them.

Log: Network notifications now respect user activity status

Influence:
1. Test network notifications appear when user is actively using the
system
2. Verify notifications are suppressed when user session is inactive
3. Test notification behavior during remote desktop sessions
4. Verify notification suppression when system is locked or user is away
5. Test different network state changes (connection/disconnection/VPN
events)

fix: 防止用户非活动时发送通知

在通知系统中添加用户活动状态检查,防止在用户未主动使用系统时发送通知。新
增的 isUserActive() 方法通过 D-Bus 查询 systemd-logind 来确定当前用户会
话是否活跃且非远程会话。

该变更确保通知仅在用户在场且主动使用系统时显示,避免在用户非活动期间或远
程会话时产生不必要的干扰。通过减少用户无法看到通知时的通知垃圾,提升了用
户体验。

Log: 网络通知现在会尊重用户活动状态

Influence:
1. 测试用户主动使用系统时网络通知是否正常显示
2. 验证用户会话非活动时通知是否被抑制
3. 测试远程桌面会话期间的通知行为
4. 验证系统锁定或用户离开时通知抑制功能
5. 测试不同网络状态变化(连接/断开/VPN事件)的通知行为

PMS: BUG-349057
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要实现了通过 D-Bus 监听 org.freedesktop.login1 服务,以获取当前会话的 Active(活动状态)和 Remote(远程状态)属性,并根据这些状态控制网络通知的显示。以下是对代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑与正确性

  • 潜在崩溃风险
    initUserDisplay 中,使用了 callWithCallback 来调用 GetAll 方法。这是一个异步调用。如果在 callWithCallback 发出后,NetworkStateHandler 对象被销毁,而回调 updateLogin1Properties 尚未执行,将会导致程序崩溃。

    • 改进建议:确保在对象析构时断开所有可能的异步回调,或者在析构函数中处理未完成的 D-Bus 调用。Qt 的 QDBusPendingCallWatcher 配合 QObject::connectQt::UniqueConnection 或者使用 QPointer 在槽函数中进行保护是常见的做法。考虑到这里使用了 SLOT 宏,最简单的做法是在析构函数中注销 D-Bus 信号连接(虽然注销连接不一定会取消正在进行的异步回调,但能防止后续信号触发)。更稳健的做法是使用 QDBusPendingCall::waitForFinished() 改为同步调用(如果初始化阻塞不是大问题),或者确保对象生命周期长于异步操作。
  • 路径拼接逻辑
    QString("/org/freedesktop/login1/user/_%1").arg(uid) 这行代码假设了 login1 的对象路径格式。虽然这是 systemd 的标准路径格式,但缺乏错误处理。

    • 改进建议:如果 D-Bus 调用失败(例如服务不存在或路径错误),initUserDisplay 中的 callWithCallback 可能不会触发回调,导致 m_sessionActivem_sessionRemote 保持初始值(false)。这可能会导致通知被错误地屏蔽。建议增加错误处理槽(例如使用 QDBusConnection::callWithCallback 的重载版本,包含错误回调),或者在初始化失败时设置默认的安全状态。

2. 代码质量

  • 初始化列表顺序
    在 C++ 中,成员变量初始化列表的顺序应与它们在类中声明的顺序一致。在 networkstatehandler.h 中,m_sessionActivem_sessionRemote 声明在最后,但在构造函数中它们被初始化在中间。这虽然通常不会导致运行时错误(只要类型不依赖),但会引发编译器警告,且属于不良风格。

    • 改进建议:调整构造函数初始化列表的顺序,使其与头文件中的声明顺序一致。
  • 代码复用
    onLogin1PropertiesChanged 函数仅仅是调用了 updateLogin1Properties,这种单一委托的函数虽然清晰,但略显冗余。

    • 改进建议:可以直接将 D-Bus 信号连接到 updateLogin1Properties 槽函数,前提是参数匹配。不过,考虑到 PropertiesChanged 信号有三个参数(interface, properties, invalidated_props),而 updateLogin1Properties 只接受一个 QVariantMap,保留 onLogin1PropertiesChanged 作为适配器是合理的。目前的写法是可接受的。
  • 魔法字符串
    代码中使用了 "org.freedesktop.login1.Session""Active" 等字符串字面量。

    • 改进建议:虽然已经定义了 DBUS_PROPERTIES_IFACELOGIN1_SERVICE,但建议将接口名和属性名也定义为 static constexpr 常量,以提高可读性和减少拼写错误。

3. 代码性能

  • D-Bus 调用
    代码在构造函数中发起了 D-Bus 调用。这是异步的,不会阻塞构造,这是好的。
    • 观察initUserDisplay 中首先获取 Display 属性,解析出 sessionPath,然后再调用 GetAll 获取会话属性。这涉及了两轮 D-Bus 通信。
    • 改进建议:如果 org.freedesktop.login1.User 对象本身也提供了 ActiveRemote 属性,或者有更直接的路径获取会话状态,可以减少一次 IPC(进程间通信)开销。不过,鉴于 login1 的结构,目前的流程(User -> Display -> Session)通常是必须的。性能影响主要在启动瞬间,可以接受。

4. 代码安全

  • 输入验证
    initUserDisplay 中,对 msg.arguments() 进行了非空检查,这是好的。但对 arg >> id >> displayPath 的解包操作没有进行进一步的验证。如果 D-Bus 返回的数据结构不符合预期(例如虽然类型是 Structure 但内部元素数量不对),可能会导致未定义行为或读取到垃圾值。

    • 改进建议:虽然 Qt 的 QDBusArgument 流操作通常比较稳健,但在生产环境中,最好确保解包后的数据有效性。例如检查 displayPath.path() 是否非空(代码中已做)。
  • 信号连接安全
    QDBusConnection::systemBus().connect(...) 返回 bool 表示连接是否成功。代码中忽略了返回值。

    • 改进建议:应该检查连接返回值,如果连接失败(例如系统总线未连接或服务不存在),应记录日志,防止静默失败导致功能不可用。

5. 详细代码修改建议

以下是基于上述意见的具体修改建议示例:

头文件:

// 添加常量定义
constexpr auto LOGIN1_SESSION_IFACE = "org.freedesktop.login1.Session";
constexpr auto LOGIN1_USER_IFACE = "org.freedesktop.login1.User";
constexpr auto PROPERTY_ACTIVE = "Active";
constexpr auto PROPERTY_REMOTE = "Remote";
constexpr auto PROPERTY_DISPLAY = "Display";

// ... 在类定义中 ...
private slots:
    // ... 
    // 修改错误处理槽声明(如果决定添加错误处理)
    void onDbusError(const QDBusError &error);

源文件:

// 构造函数初始化列表顺序修正(假设头文件声明顺序为 m_notifyEnabled, m_wifiEnabled, m_delayShowWifiOSD, m_resetWifiOSDEnableTimer, m_sessionActive, m_sessionRemote)
NetworkStateHandler::NetworkStateHandler(QObject *parent)
    : QObject(parent)
    , m_notifyEnabled(true)
    , m_wifiEnabled(true)
    , m_delayShowWifiOSD(new QTimer(this))
    , m_resetWifiOSDEnableTimer(new QTimer(this))
    , m_sessionActive(false)      // 移动到对应位置
    , m_sessionRemote(false)      // 移动到对应位置
{
    // ... 原有代码 ...
    
    // 检查 D-Bus 连接结果
    if (!QDBusConnection::systemBus().connect(LOGIN1_SERVICE, sessionPath, DBUS_PROPERTIES_IFACE, "PropertiesChanged", 
                                              this, SLOT(onLogin1PropertiesChanged(QString, QVariantMap, QStringList)))) {
        qCWarning(DSM()) << "Failed to connect to login1 PropertiesChanged signal";
    }
}

void NetworkStateHandler::initUserDisplay(const QDBusMessage &msg)
{
    if (msg.arguments().isEmpty()) {
        qCWarning(DSM()) << "initUserDisplay: Empty arguments";
        return;
    }
    
    // 使用常量
    QDBusVariant display = msg.arguments().first().value<QDBusVariant>();
    const QDBusArgument arg = display.variant().value<QDBusArgument>();
    
    if (arg.currentType() != QDBusArgument::StructureType) {
        qCWarning(DSM()) << "Invalid argument type, expected StructureType";
        return;
    }

    QString id;
    QDBusObjectPath displayPath;
    arg.beginStructure();
    arg >> id >> displayPath;
    arg.endStructure();
    
    QString sessionPath = displayPath.path();
    if (sessionPath.isEmpty()) {
        qCWarning(DSM()) << "Empty session path";
        return;
    }

    // 使用常量
    QDBusMessage sessionMsg = QDBusMessage::createMethodCall(LOGIN1_SERVICE, sessionPath, DBUS_PROPERTIES_IFACE, "GetAll");
    sessionMsg << LOGIN1_SESSION_IFACE;

    // 添加错误处理回调
    QDBusPendingCall async = QDBusConnection::systemBus().asyncCall(sessionMsg);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
    
    connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
        QDBusPendingReply<QVariantMap> reply = *watcher;
        if (reply.isError()) {
            qCWarning(DSM()) << "Failed to get login1 session properties:" << reply.error().message();
            // 可以在这里设置默认状态或重试逻辑
        } else {
            updateLogin1Properties(reply.value());
        }
        watcher->deleteLater();
    });
    
    // 注意:原代码中的 connect 依赖于 sessionPath,如果 sessionPath 无效,connect 也会失败。
    // 这里的逻辑保持原样,但建议检查返回值。
    if (!QDBusConnection::systemBus().connect(LOGIN1_SERVICE, sessionPath, DBUS_PROPERTIES_IFACE, "PropertiesChanged", 
                                              this, SLOT(onLogin1PropertiesChanged(QString, QVariantMap, QStringList)))) {
        qCWarning(DSM()) << "Failed to connect to session" << sessionPath << "PropertiesChanged";
    }
}

void NetworkStateHandler::updateLogin1Properties(const QVariantMap &properties)
{
    // 使用常量
    if (properties.contains(PROPERTY_ACTIVE)) {
        m_sessionActive = properties.value(PROPERTY_ACTIVE).toBool();
        qCDebug(DSM()) << "Session Active changed to:" << m_sessionActive;
    }
    if (properties.contains(PROPERTY_REMOTE)) {
        m_sessionRemote = properties.value(PROPERTY_REMOTE).toBool();
        qCDebug(DSM()) << "Session Remote changed to:" << m_sessionRemote;
    }
}

总结:
这段代码整体逻辑是正确的,能够实现功能。主要的改进点在于异步调用的生命周期管理错误处理以及代码风格的规范性。通过增加错误回调和日志记录,可以显著提高代码的健壮性和可维护性。

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Feb 5, 2026

TAG Bot

New tag: 2.0.81
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #497

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.

2 participants