Skip to content

Commit

Permalink
feat: support switching new and old notification
Browse files Browse the repository at this point in the history
  • Loading branch information
18202781743 committed Oct 14, 2024
1 parent 348f612 commit cdaa230
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/dde-dock/notification/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ add_library(${PLUGIN_NAME} SHARED
../widgets/tipswidget.cpp
)
target_compile_definitions(${PLUGIN_NAME} PRIVATE QT_PLUGIN)
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../dde-dock)
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../)

target_include_directories(${PLUGIN_NAME} PRIVATE
"../../../interfaces"
Expand Down
33 changes: 32 additions & 1 deletion plugins/dde-dock/notification/notificationplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ Q_LOGGING_CATEGORY(qLcPluginNotification, "dock.plugin.notification")
DGUI_USE_NAMESPACE
using namespace Dock;

static QDBusInterface notificationInterface()
{
return QDBusInterface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications");
}

static bool newNotifications()
{
static int OptionBool = -1;
if (OptionBool < 0) {
OptionBool = 0;
const QDBusMessage message = notificationInterface().call("GetServerInformation");
if (message.type() == QDBusMessage::ErrorMessage) {
qWarning() << "Failed to get server information" << message.errorMessage();
return false;
}
const auto values = message.arguments();
Q_ASSERT(values.size() == 4);

const auto version = values.at(2);
if (version.toDouble() >= 3.0) {
OptionBool = 1;
}
}
return static_cast<bool>(OptionBool);
}

NotificationPlugin::NotificationPlugin(QObject *parent)
: QObject(parent)
, m_pluginLoaded(false)
Expand Down Expand Up @@ -66,7 +94,10 @@ bool NotificationPlugin::pluginIsDisable()
const QString NotificationPlugin::itemCommand(const QString &itemKey)
{
Q_UNUSED(itemKey);
return QString("dbus-send --session --print-reply --dest=org.deepin.dde.Widgets1 /org/deepin/dde/Widgets1 org.deepin.dde.Widgets1.Toggle");
if (!newNotifications()) {
return QString("dbus-send --session --print-reply --dest=org.deepin.dde.Widgets1 /org/deepin/dde/Widgets1 org.deepin.dde.Widgets1.Toggle");
}
return QString("dbus-send --session --print-reply --dest=org.deepin.dde.shell /org/deepin/dde/shell/notification/center org.deepin.dde.shell.notification.center.Toggle");
}

const QString NotificationPlugin::itemContextMenu(const QString &itemKey)
Expand Down

0 comments on commit cdaa230

Please sign in to comment.