From 90cb5ea95d3d8039a9d09770f0579983e4c3a557 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Mon, 23 Jan 2017 22:23:51 -0300 Subject: [PATCH] Show Rambox window and activate service tab on notification click Fixes #34 --- app/ux/WebView.js | 9 +++++---- resources/js/rambox-service-api.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/ux/WebView.js b/app/ux/WebView.js index 6cde6705..f5c468e0 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -298,8 +298,8 @@ Ext.define('Rambox.ux.WebView',{ case 'rambox.clearUnreadCount': handleClearUnreadCount(event); break; - case 'rambox.showNotification': - showNotification(event); + case 'rambox.showWindowAndActivateTab': + showWindowAndActivateTab(event); break; } @@ -329,8 +329,9 @@ Ext.define('Rambox.ux.WebView',{ } } - function showNotification(event) { - console.log('showNotification', event); + function showWindowAndActivateTab(event) { + require('electron').remote.getCurrentWindow().show(); + Ext.cq1('app-main').setActiveTab(me); } }); diff --git a/resources/js/rambox-service-api.js b/resources/js/rambox-service-api.js index c37517dd..c09152bf 100644 --- a/resources/js/rambox-service-api.js +++ b/resources/js/rambox-service-api.js @@ -26,3 +26,21 @@ window.rambox.setUnreadCount = function(count) { window.rambox.clearUnreadCount = function() { ipcRenderer.sendToHost('rambox.clearUnreadCount'); } + +/** + * Override to add notification click event to display Rambox window and activate service tab + */ +var NativeNotification = Notification; +Notification = function(title, options) { + var notification = new NativeNotification(title, options); + + notification.addEventListener('click', function() { + ipcRenderer.sendToHost('rambox.showWindowAndActivateTab'); + }); + + return notification; +} + +Notification.prototype = NativeNotification.prototype; +Notification.permission = NativeNotification.permission; +Notification.requestPermission = NativeNotification.requestPermission.bind(Notification);