diff --git a/include/services/dbus/messages.hpp b/include/services/dbus/messages.hpp index 654c80b..330b35b 100644 --- a/include/services/dbus/messages.hpp +++ b/include/services/dbus/messages.hpp @@ -2,8 +2,9 @@ #include #include -#include #include +#include +#include #include #include #include "gdkmm/pixbuf.h" @@ -39,6 +40,8 @@ struct NotifyMessage { int32_t expire_timeout; // Callback to invoke when an action is triggered std::function on_action; + // Guard to prevent multiple action invocations across mirrors + std::shared_ptr actionInvoked; // image data (if any) from dbus std::optional> imageData; }; \ No newline at end of file diff --git a/include/widgets/notification/baseNotification.hpp b/include/widgets/notification/baseNotification.hpp index 19a399c..bf7d16b 100644 --- a/include/widgets/notification/baseNotification.hpp +++ b/include/widgets/notification/baseNotification.hpp @@ -9,7 +9,7 @@ #include "gdkmm/monitor.h" #include "gtkmm/window.h" -#define DEFAULT_NOTIFICATION_TIMEOUT 7000 +#define DEFAULT_NOTIFICATION_TIMEOUT 5000 class BaseNotification : public Gtk::Window { @@ -35,7 +35,6 @@ class BaseNotification : public Gtk::Window { void pause_auto_close(); void resume_auto_close(); - // onClose signal can be added here if needed protected: uint64_t notificationId; diff --git a/src/services/dbus/notification.cpp b/src/services/dbus/notification.cpp index fb410cf..3fd1cb4 100644 --- a/src/services/dbus/notification.cpp +++ b/src/services/dbus/notification.cpp @@ -84,6 +84,7 @@ void NotificationService::handle_notify(const Glib::VariantContainerBase ¶me notify.app_icon = app_icon; notify.summary = static_cast(summary); notify.body = static_cast(body); + notify.actionInvoked = std::make_shared(false); std::vector actions_converted; actions_converted.reserve(actions.size()); diff --git a/src/services/notificationController.cpp b/src/services/notificationController.cpp index 52bed82..f58b464 100644 --- a/src/services/notificationController.cpp +++ b/src/services/notificationController.cpp @@ -93,7 +93,7 @@ void NotificationController::showSpotifyNotification(MprisPlayer2Message mpris) }); - notification->startAutoClose(10000); + notification->startAutoClose(DEFAULT_NOTIFICATION_TIMEOUT); } this->activeNotifications[id] = notifications; diff --git a/src/widgets/notification/notificationWindow.cpp b/src/widgets/notification/notificationWindow.cpp index ec1ad2a..99e8c08 100644 --- a/src/widgets/notification/notificationWindow.cpp +++ b/src/widgets/notification/notificationWindow.cpp @@ -88,8 +88,9 @@ NotificationWindow::NotificationWindow(uint64_t notificationId, std::shared_ptr< break; } - btn->signal_clicked().connect([this, action_id, cb = notify.on_action]() { - if (cb) { + btn->signal_clicked().connect([this, action_id, cb = notify.on_action, guard = notify.actionInvoked]() { + if (cb && guard && !*guard) { + *guard = true; cb(action_id); this->signal_close.emit(this->notificationId); }