From 62856aac9e41f70dc73450e43300f62fadfc62ea Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Wed, 14 Sep 2016 02:06:49 -0300 Subject: [PATCH] Improved Manual Notifications Added new property to enable manual desktop notifications for services that don't have any native notifications. --- app/model/ServiceList.js | 4 ++++ app/store/ServicesList.js | 10 +++++++--- app/ux/WebView.js | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/model/ServiceList.js b/app/model/ServiceList.js index 77e47c4e..9ba4c9ac 100644 --- a/app/model/ServiceList.js +++ b/app/model/ServiceList.js @@ -31,6 +31,10 @@ Ext.define('Rambox.model.ServiceList', { name: 'allow_popups' ,type: 'boolean' ,defaultValue: false + },{ + name: 'manual_notifications' + ,type: 'boolean' + ,defaultValue: false },{ name: 'userAgent' ,type: 'string' diff --git a/app/store/ServicesList.js b/app/store/ServicesList.js index e47b379a..3c5e2c20 100644 --- a/app/store/ServicesList.js +++ b/app/store/ServicesList.js @@ -74,6 +74,7 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://hangouts.google.com/' ,type: 'messaging' ,titleBlink: true + ,manual_notifications: true ,js_unread: 'function checkUnread(){updateBadge(document.getElementById("hangout-landing-chat").lastChild.contentWindow.document.body.getElementsByClassName("ee").length)}function updateBadge(e){e>=1?document.title="("+e+") "+originalTitle:document.title=originalTitle}var originalTitle=document.title;setInterval(checkUnread,3000);' }, { @@ -121,7 +122,8 @@ Ext.define('Rambox.store.ServicesList', { ,description: 'Inbox by Gmail is a new app from the Gmail team. Inbox is an organized place to get things done and get back to what matters. Bundles keep emails organized.' ,url: 'http://inbox.google.com/?cid=imp' ,type: 'email' - ,js_unread: 'function checkUnread(){updateBadge(document.getElementsByClassName("ss").length)}function updateBadge(a){a>=1?document.title="("+a+") "+originalTitle:document.title=originalTitle,checked&&a>oldUnread&&new Notification("Inbox",{body:"You have a new email",icon:"https://raw.githubusercontent.com/saenzramiro/rambox/master/resources/icons/inbox.png"}),checked=!0,oldUnread=a}var checked=!1,oldUnread,originalTitle=document.title;setInterval(checkUnread,3e3);' + ,manual_notifications: true + ,js_unread: 'function checkUnread(){updateBadge(document.getElementsByClassName("ss").length)}function updateBadge(a){a>=1?document.title="("+a+") "+originalTitle:document.title=originalTitle}var originalTitle=document.title;setInterval(checkUnread,3e3);' }, { id: 'chatwork' @@ -186,7 +188,8 @@ Ext.define('Rambox.store.ServicesList', { ,description: 'Take control. Do more. Outlook is the free email and calendar service that helps you stay on top of what matters and get things done.' ,url: 'https://mail.live.com/' ,type: 'email' - ,js_unread: 'function checkUnread(){var a=$(".subfolders [role=treeitem]:first .treeNodeRowElement").siblings().last().text();updateBadge(""===a?0:parseInt(a))}function updateBadge(a){a>=1?document.title="("+a+") "+originalTitle:document.title=originalTitle,checked&&a>oldUnread&&new Notification("Outlook",{body:"You have a new email",icon:"https://raw.githubusercontent.com/saenzramiro/rambox/master/resources/icons/outlook.png"}),checked=!0,oldUnread=a}var checked=!1,oldUnread,originalTitle=document.title;setInterval(checkUnread,3e3);' + ,manual_notifications: true + ,js_unread: 'function checkUnread(){var a=$(".subfolders [role=treeitem]:first .treeNodeRowElement").siblings().last().text();updateBadge(""===a?0:parseInt(a))}function updateBadge(a){a>=1?document.title="("+a+") "+originalTitle:document.title=originalTitle}var originalTitle=document.title;setInterval(checkUnread,3e3);' }, { id: 'outlook365' @@ -195,7 +198,8 @@ Ext.define('Rambox.store.ServicesList', { ,description: 'Outlook for Business' ,url: 'https://outlook.office.com/owa/' ,type: 'email' - ,js_unread: 'function checkUnread(){var a=$(".subfolders [role=treeitem]:first .treeNodeRowElement").siblings().last().text();updateBadge(""===a?0:parseInt(a))}function updateBadge(a){a>=1?document.title="("+a+") "+originalTitle:document.title=originalTitle,checked&&a>oldUnread&&new Notification("Outlook 365",{body:"You have a new email",icon:"https://raw.githubusercontent.com/saenzramiro/rambox/master/resources/icons/outlook365.png"}),checked=!0,oldUnread=a}var checked=!1,oldUnread,originalTitle=document.title;setInterval(checkUnread,3e3);' + ,manual_notifications: true + ,js_unread: 'function checkUnread(){var a=$(".subfolders [role=treeitem]:first .treeNodeRowElement").siblings().last().text();updateBadge(""===a?0:parseInt(a))}function updateBadge(a){a>=1?document.title="("+a+") "+originalTitle:document.title=originalTitle}var originalTitle=document.title;setInterval(checkUnread,3e3);' }, { id: 'yahoo' diff --git a/app/ux/WebView.js b/app/ux/WebView.js index b222c17d..efeab3d7 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -44,6 +44,7 @@ Ext.define('Rambox.ux.WebView',{ e.stopEvent(); }); } + ,scope: me } ,clickEvent: '' ,style: !me.record.get('enabled') ? '-webkit-filter: grayscale(1)' : '' @@ -159,6 +160,7 @@ Ext.define('Rambox.ux.WebView',{ } ,onBadgeTextChange: function( tab, badgeText, oldBadgeText ) { + var me = this; if ( oldBadgeText === null ) oldBadgeText = 0; var actualNotifications = Rambox.app.getTotalNotifications(); @@ -166,6 +168,31 @@ Ext.define('Rambox.ux.WebView',{ badgeText = Rambox.util.Format.stripNumber(badgeText); Rambox.app.setTotalNotifications(actualNotifications - oldBadgeText + badgeText); + + // Some services dont have Desktop Notifications, so we add that functionality =) + if ( Ext.getStore('ServicesList').getById(me.type).get('manual_notifications') && oldBadgeText < badgeText && me.record.get('notifications') && !JSON.parse(localStorage.getItem('dontDisturb')) ) { + var text; + switch ( Ext.getStore('ServicesList').getById(me.type).get('type') ) { + case 'messaging': + text = 'You have ' + Ext.util.Format.plural(badgeText, 'new message', 'new messages') + '.'; + break; + case 'email': + text = 'You have ' + Ext.util.Format.plural(badgeText, 'new email', 'new emails') + '.'; + break; + default: + text = 'You have ' + Ext.util.Format.plural(badgeText, 'new activity', 'new activities') + '.'; + break; + } + var not = new Notification(me.record.get('name'), { + body: text + ,icon: tab.icon + ,silent: me.record.get('muted') + }); + not.onclick = function() { + require('electron').remote.getCurrentWindow().show(); + Ext.cq1('app-main').setActiveTab(me); + }; + } } ,onAfterRender: function() {