Browse Source

Fix linting errors and add isSupported

Samuel Attard 8 years ago
parent
commit
3938373ecb

+ 6 - 0
atom/browser/api/atom_api_notification.cc

@@ -132,6 +132,10 @@ void Notification::OnInitialProps() {
   }
 }
 
+bool Notification::IsSupported() {
+  return !!brightray::BrowserClient::Get()->GetNotificationPresenter();
+}
+
 // static
 void Notification::BuildPrototype(v8::Isolate* isolate,
                                   v8::Local<v8::FunctionTemplate> prototype) {
@@ -166,6 +170,8 @@ void Initialize(v8::Local<v8::Object> exports,
   mate::Dictionary dict(isolate, exports);
   dict.Set("Notification",
            Notification::GetConstructor(isolate)->GetFunction());
+
+  dict.SetMethod("isSupported", &Notification::IsSupported);
 }
 
 }  // namespace

+ 1 - 2
atom/browser/api/atom_api_notification.h

@@ -25,8 +25,7 @@ class Notification : public mate::TrackableObject<Notification>,
                      public brightray::NotificationDelegate {
  public:
   static mate::WrappableBase* New(mate::Arguments* args);
-  static bool HasID(int id);
-  static Notification* FromID(int id);
+  static bool IsSupported();
 
   static void BuildPrototype(v8::Isolate* isolate,
                              v8::Local<v8::FunctionTemplate> prototype);

+ 2 - 2
brightray/browser/mac/cocoa_notification.h

@@ -27,8 +27,8 @@ class CocoaNotification : public Notification {
             const GURL& icon_url,
             const SkBitmap& icon,
             bool silent,
-            const bool hasReply,
-            const base::string16 replyPlaceholder) override;
+            const bool has_reply,
+            const base::string16 reply_placeholder) override;
   void Dismiss() override;
 
   void NotificationDisplayed();

+ 1 - 1
brightray/browser/notification.h

@@ -27,7 +27,7 @@ class Notification {
                     const GURL& icon_url,
                     const SkBitmap& icon,
                     bool silent,
-                    bool hasReply,
+                    bool has_reply,
                     const base::string16& reply_placeholder) = 0;
   // Closes the notification, this instance will be destroyed after the
   // notification gets closed.

+ 8 - 0
docs/api/notification.md

@@ -19,6 +19,14 @@ Process: [Main](../glossary.md#main-process)
 
 It creates a new `Notification` with native properties as set by the `options`.
 
+### Static Methods
+
+The `Notification` class has the following static methods:
+
+#### `BrowserWindow.isSupported()`
+
+Returns `Boolean` - Whether or not desktop notifications are supported on the current system
+
 ### `new Notification([options])` _Experimental_
 
 * `options` Object

+ 3 - 1
lib/browser/api/notification.js

@@ -1,6 +1,8 @@
 const {EventEmitter} = require('events')
-const {Notification} = process.atomBinding('notification')
+const {Notification, isSupported} = process.atomBinding('notification')
 
 Object.setPrototypeOf(Notification.prototype, EventEmitter.prototype)
 
+Notification.isSupported = isSupported
+
 module.exports = Notification