Skip to content

Commit

Permalink
Merge pull request #160 from GustavoKatel/notificationTitleFix
Browse files Browse the repository at this point in the history
Add onNotify event to let recipes update/change notifications before send them.
  • Loading branch information
adlk authored Oct 30, 2017
2 parents e6ed06b + 138feed commit 2e07a02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,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,
});
Expand Down
6 changes: 6 additions & 0 deletions src/webview/lib/RecipeWebview.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class RecipeWebview {
});
}

onNotify(fn) {
if (typeof fn === 'function') {
window.Notification.onNotify = fn;
}
}

initialize(fn) {
if (typeof fn === 'function') {
fn();
Expand Down
8 changes: 5 additions & 3 deletions src/webview/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -42,4 +42,6 @@ Notification.close = () => {
// no implementation yet
};

Notification.onNotify = data => data;

window.Notification = Notification;

0 comments on commit 2e07a02

Please sign in to comment.