Fix linting errors and add isSupported

This commit is contained in:
Samuel Attard 2017-05-30 20:27:24 +10:00
parent 686b1388b1
commit 3938373ecb
No known key found for this signature in database
GPG key ID: 273DC1869D8F13EF
6 changed files with 21 additions and 6 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -19,6 +19,14 @@ Process: [Main](../glossary.md#main-process)
It creates a new `Notification` with native properties as set by the `options`. 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_ ### `new Notification([options])` _Experimental_
* `options` Object * `options` Object

View file

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