Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
push_notifications.hpp
Go to the documentation of this file.
1#pragma once
2
3// pulp::events::PushNotifications — cross-platform local notification surface.
4//
5// Supported operations:
6// * Local notifications: `post_local_notification(title, body, category)`
7// posts a notification immediately through the host platform's user-
8// notification surface.
9// * Authorization: `request_authorization(callback)` asks the OS for
10// permission to post notifications and reports the user's decision.
11// * Tap handler: `set_handler(callback)` registers a callback that fires
12// when the user activates a delivered notification.
13//
14// Not currently implemented by the built-in backends:
15// * Remote / push notifications via APNs (Apple) and FCM (Android).
16// * Notification categories with custom action buttons.
17// * Scheduled / time-triggered notifications.
18// * Per-notification badge / sound / attachment customization.
19//
20// Backends (runtime-detected; build never hard-fails on a missing SDK):
21// * macOS / iOS: `UNUserNotificationCenter` from `UserNotifications.framework`.
22// * Linux: `libnotify.so.4` via runtime-dlopen.
23// * Windows: scaffold-only `winrt-toast-scaffold` backend that probes WinRT
24// availability via runtime-LoadLibrary `combase.dll`, but reports
25// unavailable until full toast activator / AUMID integration ships.
26// * Other platforms / build configurations: `is_available()` returns false
27// and `post_local_notification` reports a posted notification id of 0.
28
29#include <cstdint>
30#include <functional>
31#include <memory>
32#include <string>
33#include <string_view>
34
35namespace pulp::events {
36
44
47 std::string title;
48 std::string body;
49 std::string category;
50 std::string id;
51};
52
55 std::string id;
56 std::string category;
57 std::string action_id;
58};
59
61using NotificationHandler = std::function<void(const NotificationActivation&)>;
62
70public:
72
73 virtual ~PushNotifications() = default;
74
78 virtual bool is_available() const = 0;
79
82 virtual std::string backend_id() const = 0;
83
87 virtual void request_authorization(AuthorizationCallback callback) = 0;
88
91
95 virtual uint64_t post_local_notification(const LocalNotification& notification) = 0;
96
99 virtual void set_handler(NotificationHandler handler) = 0;
100
103 virtual bool cancel_notification(const std::string& id) = 0;
104
106 virtual void cancel_all() = 0;
107
108protected:
109 PushNotifications() = default;
112};
113
114} // namespace pulp::events
static PushNotifications & instance()
virtual NotificationAuthorization current_authorization() const =0
Synchronous query for the current authorization state.
PushNotifications(const PushNotifications &)=delete
virtual ~PushNotifications()=default
virtual uint64_t post_local_notification(const LocalNotification &notification)=0
Post a notification.
virtual void set_handler(NotificationHandler handler)=0
Register a callback that fires when the user activates a posted notification.
virtual void request_authorization(AuthorizationCallback callback)=0
Ask the OS for permission to post notifications.
virtual void cancel_all()=0
Cancel every notification this process has posted.
virtual bool cancel_notification(const std::string &id)=0
Cancel a previously-posted notification by id (no-op if already dismissed).
virtual std::string backend_id() const =0
Short identifier of the active backend ("user-notifications", "libnotify", "winrt-toast-scaffold",...
PushNotifications & operator=(const PushNotifications &)=delete
virtual bool is_available() const =0
Returns true when a real notification backend is wired up on this build.
Definition child_process_manager.hpp:18
NotificationAuthorization
Outcome of request_authorization().
Definition push_notifications.hpp:38
@ Denied
The user (or policy) declined.
Definition push_notifications.hpp:40
@ NotDetermined
The OS has never been asked.
Definition push_notifications.hpp:39
@ Granted
The app may post notifications.
Definition push_notifications.hpp:41
@ Unsupported
This platform has no bounded pump implementation.
Definition message_loop_integration.hpp:74
std::function< void(NotificationAuthorization)> AuthorizationCallback
Definition push_notifications.hpp:60
std::function< void(const NotificationActivation &)> NotificationHandler
Definition push_notifications.hpp:61
Posted notification descriptor.
Definition push_notifications.hpp:46
std::string body
Optional secondary message.
Definition push_notifications.hpp:48
std::string title
Bold first line.
Definition push_notifications.hpp:47
std::string category
Optional grouping / action category id.
Definition push_notifications.hpp:49
std::string id
Optional caller-supplied id; auto-assigned when empty.
Definition push_notifications.hpp:50
Delivered to set_handler() when the user activates a notification.
Definition push_notifications.hpp:54
std::string id
Matches LocalNotification::id.
Definition push_notifications.hpp:55
std::string action_id
Empty for default activation.
Definition push_notifications.hpp:57
std::string category
Matches LocalNotification::category.
Definition push_notifications.hpp:56