From 47681c90b0067d8b979f1a88253973fea49741bc Mon Sep 17 00:00:00 2001 From: Gustavo Sampaio Date: Fri, 27 Oct 2017 22:35:44 -0300 Subject: Add onNotify event to let recipes update/change notifications before send them. Add additional checks in ServiceStore. --- src/stores/ServicesStore.js | 5 ++++- src/webview/lib/RecipeWebview.js | 6 ++++++ src/webview/notifications.js | 8 +++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 4510146e0..7e797ce55 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js @@ -295,9 +295,12 @@ export default class ServicesStore extends Store { } if (service.isNotificationEnabled) { + const title = typeof args[0].title === 'string' ? args[0].title : service.name; + options.body = typeof options.body === 'string' ? options.body : ''; + this.actions.app.notify({ notificationId: args[0].notificationId, - title: args[0].title, + title, options, serviceId, }); diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js index 1787f85e2..b8acc1258 100644 --- a/src/webview/lib/RecipeWebview.js +++ b/src/webview/lib/RecipeWebview.js @@ -64,6 +64,12 @@ class RecipeWebview { }); } + onNotify(fn) { + if (typeof fn === 'function') { + window.Notification.onNotify = fn; + } + } + initialize(fn) { if (typeof fn === 'function') { fn(); diff --git a/src/webview/notifications.js b/src/webview/notifications.js index 97ce9d69b..b3397148d 100644 --- a/src/webview/notifications.js +++ b/src/webview/notifications.js @@ -7,13 +7,13 @@ class Notification { this.title = title; this.options = options; this.notificationId = uuidV1(); - this.onclick = () => {}; + this.onclick = () => { }; - ipcRenderer.sendToHost('notification', { + ipcRenderer.sendToHost('notification', Notification.onNotify({ notificationId: this.notificationId, title, options, - }); + })); ipcRenderer.on(`notification-onclick:${this.notificationId}`, () => { this.onclick(); @@ -42,4 +42,6 @@ Notification.close = () => { // no implementation yet }; +Notification.onNotify = data => data; + window.Notification = Notification; -- cgit v1.2.3-70-g09d2