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);