33// SPDX-License-Identifier: GPL-3.0-or-later
44
55#include " sessionbasemodel.h"
6+ #include " dconfig_helper.h"
7+ #include " dbus/dbusdisplaymanager.h"
68
79#include < DSysInfo>
8-
910#include < QDebug>
1011
1112#include " dbusconstant.h"
12- #include " dconfig_helper.h"
1313
1414DCORE_USE_NAMESPACE
1515
@@ -462,6 +462,22 @@ void SessionBaseModel::updateUserList(const QStringList &list)
462462void SessionBaseModel::updateLoginedUserList (const QString &list)
463463{
464464 qCDebug (DDE_SHELL) << " Logined user list: " << list;
465+ // kwin崩溃时systemd中的sessions不会被remove掉,这里通过DisplayManager的session信息过滤一遍(临时解决方案)
466+ QStringList loggedUserNameList;
467+ DBusDisplayManager displayManager (" org.freedesktop.DisplayManager" , " /org/freedesktop/DisplayManager" , QDBusConnection::systemBus ());
468+ const auto &sessions = displayManager.sessions ();
469+ for (const auto &session : sessions) {
470+ const QString &sessionPath = session.path ();
471+ if (sessionPath.isEmpty ())
472+ continue ;
473+ QDBusInterface interface (" org.freedesktop.DisplayManager" , sessionPath, " org.freedesktop.DisplayManager.Session" , QDBusConnection::systemBus ());
474+ if (interface.isValid ()) {
475+ const QString &userName = interface.property (" UserName" ).toString ();
476+ if (!userName.isEmpty ())
477+ loggedUserNameList.append (userName);
478+ }
479+ }
480+ qInfo (DDE_SHELL) << " Logined users from display manager: " << loggedUserNameList;
465481
466482 QList<QString> loginedUsersTmp = m_loginedUsers->keys ();
467483 QJsonParseError jsonParseError;
@@ -486,8 +502,11 @@ void SessionBaseModel::updateLoginedUserList(const QString &list)
486502 // 对于通过自定义窗口输入的账户(域账户), 此时账户还没添加进来,导致下面m_users->value(path)为空指针,调用会导致程序奔溃
487503 // 因此在登录时,对于新增的账户,调用addUser先将账户添加进来,然后再去更新对应账户的登录状态
488504 addUser (path);
489- m_loginedUsers->insert (path, m_users->value (path));
490- m_users->value (path)->updateLoginState (true );
505+ auto user = m_users->value (path);
506+ if (user->name ().isEmpty () || loggedUserNameList.contains (user->name ())) {
507+ m_loginedUsers->insert (path, user);
508+ user->updateLoginState (true );
509+ }
491510 } else {
492511 loginedUsersTmp.removeAll (path);
493512 }
0 commit comments