Skip to content

Commit 48dbb4c

Browse files
committed
chore: Use dde-lock to obtain session locked state
as title Log: as title
1 parent ff36663 commit 48dbb4c

File tree

6 files changed

+45
-71
lines changed

6 files changed

+45
-71
lines changed

panels/notification/server/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ set(NOTIFICATION_SERVER "notificationserver")
66

77
file (GLOB SERVER_SOURCES *.cpp *.h)
88

9-
set_source_files_properties(
10-
${CMAKE_CURRENT_SOURCE_DIR}/dbus/xml/org.deepin.dde.SessionManager1.xml
11-
PROPERTIES
12-
CLASSNAME
13-
SessionManager1
14-
)
15-
16-
qt6_add_dbus_interfaces(
17-
DBUS_INTERFACES
18-
${CMAKE_CURRENT_SOURCE_DIR}/dbus/xml/org.deepin.dde.SessionManager1.xml
19-
)
20-
219
add_library(${NOTIFICATION_SERVER} SHARED
2210
${DBUS_INTERFACES}
2311
${SERVER_SOURCES}

panels/notification/server/dbus/xml/org.deepin.dde.SessionManager1.xml

Lines changed: 0 additions & 45 deletions
This file was deleted.

panels/notification/server/dbusadaptor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#include "dbusadaptor.h"
66
#include "notificationmanager.h"
77

8+
#include <QDBusConnection>
9+
#include <QDBusMessage>
810
#include <QLoggingCategory>
11+
912
namespace notification {
1013
Q_DECLARE_LOGGING_CATEGORY(notifyLog)
1114
}

panels/notification/server/notificationmanager.cpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
#include "notificationsetting.h"
99
#include "notifyentity.h"
1010

11-
#include <QDateTime>
1211
#include <DDesktopServices>
1312
#include <DSGApplication>
14-
#include <QDBusConnection>
1513
#include <QDBusConnectionInterface>
1614

1715
#include <DConfig>
1816

17+
#include <QAbstractItemModel>
18+
#include <QDBusInterface>
19+
#include <QProcess>
20+
#include <QTimer>
21+
#include <QLoggingCategory>
1922
#include <QJsonArray>
2023
#include <QJsonDocument>
2124
#include <QJsonObject>
@@ -44,7 +47,6 @@ NotificationManager::NotificationManager(QObject *parent)
4447
: QObject(parent)
4548
, m_persistence(DataAccessorProxy::instance())
4649
, m_setting(new NotificationSetting(this))
47-
, m_userSessionManager(new UserSessionManager(SessionDBusService, SessionDaemonDBusPath, QDBusConnection::sessionBus(), this))
4850
, m_pendingTimeout(new QTimer(this))
4951
{
5052
m_pendingTimeout->setSingleShot(true);
@@ -74,6 +76,8 @@ NotificationManager::NotificationManager(QObject *parent)
7476
m_systemApps = config->value("systemApps").toStringList();
7577
// TODO temporary fix for AppNamesMap
7678
m_appNamesMap = config->value("AppNamesMap").toMap();
79+
80+
initScreenLockedState();
7781
}
7882

7983
NotificationManager::~NotificationManager()
@@ -216,8 +220,7 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
216220
bool lockScreenShow = true;
217221
bool dndMode = isDoNotDisturb();
218222
bool systemNotification = m_systemApps.contains(appId);
219-
bool lockScreen = m_userSessionManager->locked();
220-
const bool desktopScreen = !lockScreen;
223+
const bool desktopScreen = !m_screenLocked;
221224

222225
if (!systemNotification) {
223226
lockScreenShow = m_setting->appValue(appId, NotificationSetting::ShowOnLockScreen).toBool();
@@ -232,7 +235,7 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
232235

233236
if (systemNotification) { // 系统通知
234237
entity.setProcessedType(NotifyEntity::NotProcessed);
235-
} else if (lockScreen && !lockScreenShow) { // 锁屏不显示通知
238+
} else if (m_screenLocked && !lockScreenShow) { // 锁屏不显示通知
236239
entity.setProcessedType(NotifyEntity::Processed);
237240
} else if (desktopScreen && !onDesktopShow) { // 桌面不显示通知
238241
entity.setProcessedType(NotifyEntity::Processed);
@@ -351,9 +354,8 @@ bool NotificationManager::isDoNotDisturb() const
351354
return true;
352355
}
353356

354-
bool lockScreen = m_userSessionManager->locked();
355357
// 点击锁屏时 并且 锁屏状态 任何时候都勿扰模式
356-
if (m_setting->systemValue(NotificationSetting::LockScreenOpenDNDMode).toBool() && lockScreen)
358+
if (m_setting->systemValue(NotificationSetting::LockScreenOpenDNDMode).toBool() && m_screenLocked)
357359
return true;
358360

359361
QTime currentTime = QTime::fromString(QDateTime::currentDateTime().toString("hh:mm"));
@@ -550,6 +552,26 @@ bool NotificationManager::invokeShellAction(const QString &data)
550552
return false;
551553
}
552554

555+
void NotificationManager::initScreenLockedState()
556+
{
557+
const QString interfaceAndServiceName = "org.deepin.dde.LockFront1";
558+
const QString path = "/org/deepin/dde/LockFront1";
559+
560+
QDBusInterface interface(interfaceAndServiceName, path,
561+
"org.freedesktop.DBus.Properties", QDBusConnection::sessionBus());
562+
563+
QDBusReply<QDBusVariant> reply = interface.call("Get", "org.deepin.dde.LockFront1", "Visible");
564+
if (reply.isValid()) {
565+
m_screenLocked = reply.value().variant().toBool();
566+
} else {
567+
m_screenLocked = false;
568+
qWarning(notifyLog) << "Failed to get the lock visible property:" << reply.error().message();
569+
}
570+
571+
QDBusConnection::sessionBus().connect(interfaceAndServiceName, path, interfaceAndServiceName,
572+
"Visible", this, SLOT(onScreenLockedChanged(bool)));
573+
}
574+
553575
void NotificationManager::onHandingPendingEntities()
554576
{
555577
QList<NotifyEntity> timeoutEntities;
@@ -600,4 +622,9 @@ void NotificationManager::removePendingEntity(const NotifyEntity &entity)
600622
}
601623
}
602624

625+
void NotificationManager::onScreenLockedChanged(bool screenLocked)
626+
{
627+
m_screenLocked = screenLocked;
628+
}
629+
603630
} // notification

panels/notification/server/notificationmanager.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44

55
#pragma once
66

7-
#include <QObject>
87
#include <QDBusContext>
98
#include <QDBusVariant>
109

11-
#include "sessionmanager1interface.h"
12-
13-
using UserSessionManager = org::deepin::dde::SessionManager1;
14-
10+
class QTimer;
1511
namespace notification {
1612

1713
class NotifyEntity;
@@ -79,17 +75,19 @@ public Q_SLOTS:
7975
QString appIdByAppName(const QString &appName) const;
8076
void doActionInvoked(const NotifyEntity &entity, const QString &actionId);
8177
bool invokeShellAction(const QString &data);
78+
void initScreenLockedState();
8279

8380
private slots:
8481
void onHandingPendingEntities();
8582
void removePendingEntity(const NotifyEntity &entity);
83+
void onScreenLockedChanged(bool);
8684

8785
private:
8886
uint m_replacesCount = 0;
87+
bool m_screenLocked = false;
8988

9089
DataAccessor *m_persistence = nullptr;
9190
NotificationSetting *m_setting = nullptr;
92-
UserSessionManager *m_userSessionManager = nullptr;
9391
QTimer *m_pendingTimeout = nullptr;
9492
qint64 m_lastTimeoutPoint = std::numeric_limits<qint64>::max();
9593
QMultiHash<qint64, NotifyEntity> m_pendingTimeoutEntities;

panels/notification/server/notifyserverapplet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "dbusadaptor.h"
88
#include "pluginfactory.h"
99

10+
#include <QThread>
11+
#include <QLoggingCategory>
12+
1013
namespace notification {
1114
Q_DECLARE_LOGGING_CATEGORY(notifyLog)
1215
}

0 commit comments

Comments
 (0)