Skip to content
Snippets Groups Projects

Add ability to respond to notifications on macOS

Merged Joe Donofry requested to merge macos_notification_actions into master
4 unresolved threads

Implement the UNTextInputNotificationAction and UNNotificationCategory stuff so that messages can actually be sent from the notification banner.

This requires adding a UNUserNotificationCenterDelegate object to respond to notification actions. This needs to be registered when the app launches (rather than when we receive a notification), so I have updated main.cpp to incorporate this. If there's a better way... let me know.

I also now properly check for permission access before trying to send a notification. I'm pretty sure it ends up as a no-op if you don't have permission, rather than a hard error, but I'd rather not waste cycles constructing a notification that will never see the light of day if it's not necessary!

See: https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types?language=objc

Edited by Joe Donofry

Merge request reports

Merge request pipeline #3888 passed

Merge request pipeline passed for 9c67f05d

Approval is optional

Merged by Joe DonofryJoe Donofry 2 years ago (Nov 4, 2022 4:42pm UTC)

Merge details

  • Changes merged into master with a6f53699 (commits were squashed).
  • Deleted the source branch.

Pipeline #3912 passed

Pipeline passed for a6f53699 on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1 // SPDX-FileCopyrightText: 2021 Nheko Contributors
  • 1 // SPDX-FileCopyrightText: 2021 Nheko Contributors
  • 166 void NotificationsManager::attachToMacNotifCenter()
    96 167 {
    97 }
    168 UNUserNotificationCenter* center =
    169 [UNUserNotificationCenter currentNotificationCenter];
    98 170
    99 void
    100 NotificationsManager::notificationReplied(uint, QString)
    101 {
    102 }
    171 std::unique_ptr<NotificationManagerProxy> proxy = std::make_unique<NotificationManagerProxy>();
    103 172
    104 void
    105 NotificationsManager::notificationClosed(uint, uint)
    106 {
    173 connect(proxy.get(), &NotificationManagerProxy::notificationReplied, ChatPage::instance(), &ChatPage::sendNotificationReply);
  • 105 NotificationsManager::notificationClosed(uint, uint)
    106 {
    173 connect(proxy.get(), &NotificationManagerProxy::notificationReplied, ChatPage::instance(), &ChatPage::sendNotificationReply);
    174
    175 MacNotificationDelegate* notifDelegate = [[MacNotificationDelegate alloc] initWithProxy:std::move(proxy)];
    176
    177 center.delegate = notifDelegate;
    107 178 }
    108 179
    109 void
    110 NotificationsManager::removeNotification(const QString &, const QString &)
    111 {}
    180 // unused
    181 void NotificationsManager::actionInvoked(uint, QString) { }
    182
    183 void NotificationsManager::notificationReplied(uint, QString) { }
    • I feel like these needed to be defined or you ended up with symbol errors. I don't remember though, it's been a while since these bits were first added. The functions in question are only relevant for dbus, but your comment in the other file says that signals can't be in ifdefs. so here we are.

    • Well, maybe we can make the slots generic, so they work the same on macOS and Linux. But if that is a hassle, then maybe not :D

    • Please register or sign in to reply
  • merged

  • Joe Donofry mentioned in commit a6f53699

    mentioned in commit a6f53699

  • Please register or sign in to reply
    Loading