Skip to content

Commit 53ef315

Browse files
committed
chore: Use dde-lock to obtain session locked state
as title Log: as title
1 parent d3c4c44 commit 53ef315

File tree

6 files changed

+31
-71
lines changed

6 files changed

+31
-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: 22 additions & 7 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);
@@ -213,10 +215,10 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
213215
entity.setProcessedType(NotifyEntity::None);
214216
entity.setReplacesId(replacesId);
215217

218+
bool lockScreen = isSessionLocked();
216219
bool lockScreenShow = true;
217-
bool dndMode = isDoNotDisturb();
220+
bool dndMode = isDoNotDisturb(lockScreen);
218221
bool systemNotification = m_systemApps.contains(appId);
219-
bool lockScreen = m_userSessionManager->locked();
220222
const bool desktopScreen = !lockScreen;
221223

222224
if (!systemNotification) {
@@ -340,7 +342,7 @@ QVariant NotificationManager::GetSystemInfo(uint configItem)
340342
return m_setting->systemValue(static_cast<NotificationSetting::SystemConfigItem>(configItem));
341343
}
342344

343-
bool NotificationManager::isDoNotDisturb() const
345+
bool NotificationManager::isDoNotDisturb(bool lockScreen) const
344346
{
345347
if (!m_setting->systemValue(NotificationSetting::DNDMode).toBool())
346348
return false;
@@ -351,7 +353,6 @@ bool NotificationManager::isDoNotDisturb() const
351353
return true;
352354
}
353355

354-
bool lockScreen = m_userSessionManager->locked();
355356
// 点击锁屏时 并且 锁屏状态 任何时候都勿扰模式
356357
if (m_setting->systemValue(NotificationSetting::LockScreenOpenDNDMode).toBool() && lockScreen)
357358
return true;
@@ -550,6 +551,20 @@ bool NotificationManager::invokeShellAction(const QString &data)
550551
return false;
551552
}
552553

554+
bool NotificationManager::isSessionLocked() const
555+
{
556+
QDBusInterface interface("org.deepin.dde.LockFront1", "/org/deepin/dde/LockFront1",
557+
"org.freedesktop.DBus.Properties", QDBusConnection::sessionBus());
558+
559+
QDBusReply<QDBusVariant> reply = interface.call("Get", "org.deepin.dde.LockFront1", "Visible");
560+
if (reply.isValid()) {
561+
return reply.value().variant().toBool();
562+
}
563+
564+
qWarning(notifyLog) << "Failed to get the lock visible property:" << reply.error().message();
565+
return false;
566+
}
567+
553568
void NotificationManager::onHandingPendingEntities()
554569
{
555570
QList<NotifyEntity> timeoutEntities;

panels/notification/server/notificationmanager.h

Lines changed: 3 additions & 7 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;
@@ -68,7 +64,7 @@ public Q_SLOTS:
6864
QVariant GetSystemInfo(uint configItem);
6965

7066
private:
71-
bool isDoNotDisturb() const;
67+
bool isDoNotDisturb(bool lockScreen) const;
7268
void tryPlayNotificationSound(const NotifyEntity &entity, const QString &appId, bool dndMode) const;
7369
void emitRecordCountChanged();
7470

@@ -79,6 +75,7 @@ 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+
bool isSessionLocked() const;
8279

8380
private slots:
8481
void onHandingPendingEntities();
@@ -89,7 +86,6 @@ private slots:
8986

9087
DataAccessor *m_persistence = nullptr;
9188
NotificationSetting *m_setting = nullptr;
92-
UserSessionManager *m_userSessionManager = nullptr;
9389
QTimer *m_pendingTimeout = nullptr;
9490
qint64 m_lastTimeoutPoint = std::numeric_limits<qint64>::max();
9591
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)