From 0cfae1cc2b2704ac56959c13e130f1efb783951c Mon Sep 17 00:00:00 2001 From: Charlie Hess Date: Thu, 17 Aug 2017 00:06:27 -0700 Subject: [PATCH] Plumb in the macOS soundName property for notifications. --- atom/browser/api/atom_api_notification.cc | 14 +++++++++++++- atom/browser/api/atom_api_notification.h | 3 +++ brightray/browser/mac/cocoa_notification.mm | 2 ++ brightray/browser/notification.h | 1 + docs/api/notification.md | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_notification.cc b/atom/browser/api/atom_api_notification.cc index 7496b8389ace..85ede4a3c303 100644 --- a/atom/browser/api/atom_api_notification.cc +++ b/atom/browser/api/atom_api_notification.cc @@ -67,6 +67,7 @@ Notification::Notification(v8::Isolate* isolate, opts.Get("replyPlaceholder", &reply_placeholder_); opts.Get("hasReply", &has_reply_); opts.Get("actions", &actions_); + opts.Get("soundName", &sound_name_); } } @@ -113,6 +114,10 @@ std::vector Notification::GetActions() const { return actions_; } +base::string16 Notification::GetSoundName() const { + return sound_name_; +} + // Setters void Notification::SetTitle(const base::string16& new_title) { title_ = new_title; @@ -143,6 +148,10 @@ void Notification::SetActions( actions_ = actions; } +void Notification::SetSoundName(const base::string16& new_sound_name) { + sound_name_ = new_sound_name; +} + void Notification::NotificationAction(int index) { Emit("action", index); } @@ -181,6 +190,7 @@ void Notification::Show() { options.has_reply = has_reply_; options.reply_placeholder = reply_placeholder_; options.actions = actions_; + options.sound_name = sound_name_; notification_->Show(options); } } @@ -207,7 +217,9 @@ void Notification::BuildPrototype(v8::Isolate* isolate, .SetProperty("hasReply", &Notification::GetHasReply, &Notification::SetHasReply) .SetProperty("actions", &Notification::GetActions, - &Notification::SetActions); + &Notification::SetActions) + .SetProperty("soundName", &Notification::GetSoundName, + &Notification::SetSoundName); } } // namespace api diff --git a/atom/browser/api/atom_api_notification.h b/atom/browser/api/atom_api_notification.h index 9c2dcd4b5107..2960c6777449 100644 --- a/atom/browser/api/atom_api_notification.h +++ b/atom/browser/api/atom_api_notification.h @@ -54,6 +54,7 @@ class Notification : public mate::TrackableObject, base::string16 GetReplyPlaceholder() const; bool GetHasReply() const; std::vector GetActions() const; + base::string16 GetSoundName() const; // Prop Setters void SetTitle(const base::string16& new_title); @@ -63,6 +64,7 @@ class Notification : public mate::TrackableObject, void SetReplyPlaceholder(const base::string16& new_reply_placeholder); void SetHasReply(bool new_has_reply); void SetActions(const std::vector& actions); + void SetSoundName(const base::string16& sound_name); private: base::string16 title_; @@ -75,6 +77,7 @@ class Notification : public mate::TrackableObject, base::string16 reply_placeholder_; bool has_reply_ = false; std::vector actions_; + base::string16 sound_name_; brightray::NotificationPresenter* presenter_; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index a56d2e24c0e7..8b9cbb793def 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -39,6 +39,8 @@ void CocoaNotification::Show(const NotificationOptions& options) { if (options.silent) { [notification_ setSoundName:nil]; + } else if (options.sound_name != nil) { + [notification_ setSoundName:base::SysUTF16ToNSString(options.sound_name)]; } else { [notification_ setSoundName:NSUserNotificationDefaultSoundName]; } diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 017fdd85261d..18db3c119b47 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -33,6 +33,7 @@ struct NotificationOptions { bool silent; bool has_reply; base::string16 reply_placeholder; + base::string16 sound_name; std::vector actions; }; diff --git a/docs/api/notification.md b/docs/api/notification.md index 903610266828..ba89d7aa1336 100644 --- a/docs/api/notification.md +++ b/docs/api/notification.md @@ -37,6 +37,7 @@ Returns `Boolean` - Whether or not desktop notifications are supported on the cu * `icon` [NativeImage](native-image.md) - (optional) An icon to use in the notification * `hasReply` Boolean - (optional) Whether or not to add an inline reply option to the notification. _macOS_ * `replyPlaceholder` String - (optional) The placeholder to write in the inline reply input field. _macOS_ + * `soundName` String - (optional) The name of the sound file to play when the notification is shown. _macOS_ * `actions` [NotificationAction[]](structures/notification-action.md) - (optional) Actions to add to the notification. Please read the available actions and limitations in the `NotificationAction` documentation _macOS_