Browse Source

Improved Manual Notifications

Added new property to enable manual desktop notifications for services
that don't have any native notifications.
pull/367/head
Ramiro Saenz 9 years ago
parent
commit
62856aac9e
  1. 4
      app/model/ServiceList.js
  2. 10
      app/store/ServicesList.js
  3. 27
      app/ux/WebView.js

4
app/model/ServiceList.js

@ -31,6 +31,10 @@ Ext.define('Rambox.model.ServiceList', {
name: 'allow_popups' name: 'allow_popups'
,type: 'boolean' ,type: 'boolean'
,defaultValue: false ,defaultValue: false
},{
name: 'manual_notifications'
,type: 'boolean'
,defaultValue: false
},{ },{
name: 'userAgent' name: 'userAgent'
,type: 'string' ,type: 'string'

10
app/store/ServicesList.js

@ -74,6 +74,7 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://hangouts.google.com/' ,url: 'https://hangouts.google.com/'
,type: 'messaging' ,type: 'messaging'
,titleBlink: true ,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);' ,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.' ,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' ,url: 'http://inbox.google.com/?cid=imp'
,type: 'email' ,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' 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.' ,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/' ,url: 'https://mail.live.com/'
,type: 'email' ,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' id: 'outlook365'
@ -195,7 +198,8 @@ Ext.define('Rambox.store.ServicesList', {
,description: 'Outlook for Business' ,description: 'Outlook for Business'
,url: 'https://outlook.office.com/owa/' ,url: 'https://outlook.office.com/owa/'
,type: 'email' ,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' id: 'yahoo'

27
app/ux/WebView.js

@ -44,6 +44,7 @@ Ext.define('Rambox.ux.WebView',{
e.stopEvent(); e.stopEvent();
}); });
} }
,scope: me
} }
,clickEvent: '' ,clickEvent: ''
,style: !me.record.get('enabled') ? '-webkit-filter: grayscale(1)' : '' ,style: !me.record.get('enabled') ? '-webkit-filter: grayscale(1)' : ''
@ -159,6 +160,7 @@ Ext.define('Rambox.ux.WebView',{
} }
,onBadgeTextChange: function( tab, badgeText, oldBadgeText ) { ,onBadgeTextChange: function( tab, badgeText, oldBadgeText ) {
var me = this;
if ( oldBadgeText === null ) oldBadgeText = 0; if ( oldBadgeText === null ) oldBadgeText = 0;
var actualNotifications = Rambox.app.getTotalNotifications(); var actualNotifications = Rambox.app.getTotalNotifications();
@ -166,6 +168,31 @@ Ext.define('Rambox.ux.WebView',{
badgeText = Rambox.util.Format.stripNumber(badgeText); badgeText = Rambox.util.Format.stripNumber(badgeText);
Rambox.app.setTotalNotifications(actualNotifications - oldBadgeText + 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() { ,onAfterRender: function() {

Loading…
Cancel
Save