| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | // Copyright (c) 2014 GitHub, Inc.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NOTIFICATION_H_
 | 
					
						
							|  |  |  | #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NOTIFICATION_H_
 | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-11 16:07:39 -04:00
										 |  |  | #include "base/memory/raw_ptr.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-24 08:14:35 +10:00
										 |  |  | #include "base/strings/utf_string_conversions.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-31 11:42:32 -07:00
										 |  |  | #include "gin/wrappable.h"
 | 
					
						
							|  |  |  | #include "shell/browser/event_emitter_mixin.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/notifications/notification.h"
 | 
					
						
							|  |  |  | #include "shell/browser/notifications/notification_delegate.h"
 | 
					
						
							|  |  |  | #include "shell/browser/notifications/notification_presenter.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-31 11:42:32 -07:00
										 |  |  | #include "shell/common/gin_helper/cleaned_up_at_exit.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_helper/constructible.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-15 10:15:23 +09:00
										 |  |  | #include "shell/common/gin_helper/error_thrower.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | #include "ui/gfx/image/image.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 09:30:55 +09:00
										 |  |  | namespace gin { | 
					
						
							|  |  |  | class Arguments; | 
					
						
							| 
									
										
										
										
											2020-03-31 11:42:32 -07:00
										 |  |  | template <typename T> | 
					
						
							|  |  |  | class Handle; | 
					
						
							|  |  |  | }  // namespace gin
 | 
					
						
							| 
									
										
										
										
											2019-10-02 09:30:55 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 12:55:47 -07:00
										 |  |  | namespace electron::api { | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-31 11:42:32 -07:00
										 |  |  | class Notification : public gin::Wrappable<Notification>, | 
					
						
							|  |  |  |                      public gin_helper::EventEmitterMixin<Notification>, | 
					
						
							|  |  |  |                      public gin_helper::Constructible<Notification>, | 
					
						
							|  |  |  |                      public gin_helper::CleanedUpAtExit, | 
					
						
							| 
									
										
										
										
											2018-10-17 20:01:11 +02:00
										 |  |  |                      public NotificationDelegate { | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2017-05-30 20:27:24 +10:00
										 |  |  |   static bool IsSupported(); | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-31 11:42:32 -07:00
										 |  |  |   // gin_helper::Constructible
 | 
					
						
							|  |  |  |   static gin::Handle<Notification> New(gin_helper::ErrorThrower thrower, | 
					
						
							|  |  |  |                                        gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2023-02-06 12:59:49 -08:00
										 |  |  |   static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>); | 
					
						
							| 
									
										
										
										
											2023-07-10 11:49:20 +02:00
										 |  |  |   static const char* GetClassName() { return "Notification"; } | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-30 19:06:51 +10:00
										 |  |  |   // NotificationDelegate:
 | 
					
						
							| 
									
										
										
										
											2017-06-23 20:39:42 +10:00
										 |  |  |   void NotificationAction(int index) override; | 
					
						
							| 
									
										
										
										
											2017-05-30 19:06:51 +10:00
										 |  |  |   void NotificationClick() override; | 
					
						
							| 
									
										
										
										
											2017-05-31 16:17:29 +09:00
										 |  |  |   void NotificationReplied(const std::string& reply) override; | 
					
						
							| 
									
										
										
										
											2017-05-30 19:06:51 +10:00
										 |  |  |   void NotificationDisplayed() override; | 
					
						
							|  |  |  |   void NotificationDestroyed() override; | 
					
						
							|  |  |  |   void NotificationClosed() override; | 
					
						
							| 
									
										
										
										
											2020-09-29 12:20:10 -07:00
										 |  |  |   void NotificationFailed(const std::string& error) override; | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-31 11:42:32 -07:00
										 |  |  |   // gin::Wrappable
 | 
					
						
							|  |  |  |   static gin::WrapperInfo kWrapperInfo; | 
					
						
							| 
									
										
										
										
											2023-07-10 11:49:20 +02:00
										 |  |  |   const char* GetTypeName() override; | 
					
						
							| 
									
										
										
										
											2020-03-31 11:42:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-03 12:41:45 +01:00
										 |  |  |   // disable copy
 | 
					
						
							|  |  |  |   Notification(const Notification&) = delete; | 
					
						
							|  |  |  |   Notification& operator=(const Notification&) = delete; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2019-10-15 10:15:23 +09:00
										 |  |  |   explicit Notification(gin::Arguments* args); | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  |   ~Notification() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void Show(); | 
					
						
							| 
									
										
										
										
											2017-10-27 16:27:37 +13:00
										 |  |  |   void Close(); | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Prop Getters
 | 
					
						
							| 
									
										
										
										
											2024-01-29 20:43:28 -06:00
										 |  |  |   const std::u16string& title() const { return title_; } | 
					
						
							|  |  |  |   const std::u16string& subtitle() const { return subtitle_; } | 
					
						
							|  |  |  |   const std::u16string& body() const { return body_; } | 
					
						
							|  |  |  |   bool is_silent() const { return silent_; } | 
					
						
							|  |  |  |   bool has_reply() const { return has_reply_; } | 
					
						
							|  |  |  |   const std::u16string& timeout_type() const { return timeout_type_; } | 
					
						
							|  |  |  |   const std::u16string& reply_placeholder() const { return reply_placeholder_; } | 
					
						
							|  |  |  |   const std::u16string& urgency() const { return urgency_; } | 
					
						
							|  |  |  |   const std::u16string& sound() const { return sound_; } | 
					
						
							|  |  |  |   const std::vector<electron::NotificationAction>& actions() const { | 
					
						
							|  |  |  |     return actions_; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const std::u16string& close_button_text() const { return close_button_text_; } | 
					
						
							|  |  |  |   const std::u16string& toast_xml() const { return toast_xml_; } | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Prop Setters
 | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   void SetTitle(const std::u16string& new_title); | 
					
						
							|  |  |  |   void SetSubtitle(const std::u16string& new_subtitle); | 
					
						
							|  |  |  |   void SetBody(const std::u16string& new_body); | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  |   void SetSilent(bool new_silent); | 
					
						
							|  |  |  |   void SetHasReply(bool new_has_reply); | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   void SetUrgency(const std::u16string& new_urgency); | 
					
						
							|  |  |  |   void SetTimeoutType(const std::u16string& new_timeout_type); | 
					
						
							| 
									
										
										
										
											2021-05-31 18:46:25 -07:00
										 |  |  |   void SetReplyPlaceholder(const std::u16string& new_placeholder); | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   void SetSound(const std::u16string& sound); | 
					
						
							| 
									
										
										
										
											2018-10-17 20:01:11 +02:00
										 |  |  |   void SetActions(const std::vector<electron::NotificationAction>& actions); | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   void SetCloseButtonText(const std::u16string& text); | 
					
						
							|  |  |  |   void SetToastXml(const std::u16string& new_toast_xml); | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   std::u16string title_; | 
					
						
							|  |  |  |   std::u16string subtitle_; | 
					
						
							|  |  |  |   std::u16string body_; | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  |   gfx::Image icon_; | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   std::u16string icon_path_; | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  |   bool has_icon_ = false; | 
					
						
							|  |  |  |   bool silent_ = false; | 
					
						
							|  |  |  |   bool has_reply_ = false; | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   std::u16string timeout_type_; | 
					
						
							|  |  |  |   std::u16string reply_placeholder_; | 
					
						
							|  |  |  |   std::u16string sound_; | 
					
						
							|  |  |  |   std::u16string urgency_; | 
					
						
							| 
									
										
										
										
											2018-10-17 20:01:11 +02:00
										 |  |  |   std::vector<electron::NotificationAction> actions_; | 
					
						
							| 
									
										
										
										
											2021-03-16 12:18:45 -04:00
										 |  |  |   std::u16string close_button_text_; | 
					
						
							|  |  |  |   std::u16string toast_xml_; | 
					
						
							| 
									
										
										
										
											2017-05-31 16:17:29 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-11 16:07:39 -04:00
										 |  |  |   raw_ptr<electron::NotificationPresenter> presenter_; | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 20:01:11 +02:00
										 |  |  |   base::WeakPtr<electron::Notification> notification_; | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 12:55:47 -07:00
										 |  |  | }  // namespace electron::api
 | 
					
						
							| 
									
										
										
										
											2017-04-23 22:16:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #endif  // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NOTIFICATION_H_
 |