Browse Source

Merge branch 'pr/1759'

pull/1636/merge
Ramiro Saenz 7 years ago
parent
commit
c5e86f8c10
  1. 36
      app/model/README.md
  2. 4
      app/model/ServiceList.js
  3. 16
      app/store/ServicesList.js
  4. 8
      app/ux/WebView.js

36
app/model/README.md

@ -1,28 +1,24 @@
# Adding a service ## Adding a service
The available services are stored in the [ServicesList.js](../store/ServicesList.js).
The available services are stored in the [ServiceList.js](app/store/ServicesList.js).
Structure of a service entry: Structure of a service entry:
| Name | Description | Required | |Name|Description|Required|
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------- | |---|---|---|
| id | Unique identifier for the service, e.g. "**slack**" | yes | |id|Unique identifier for the service, e.g. "slack"|yes|
| logo | File name of the service logo located in `/resources/icons/`, e.g. "**slack.png**" | yes | |logo|File name of the service logo located in "/resources/icons/", e.g. "slack.png"|yes|
| name | Visible name for the service, e.g. "**Slack**" | yes | |name|Visible name for the service, e.g. "Slack"|yes|
| description | A short description of the service, e.g. "**Slack brings all your communication together...**" | yes | |description|A short description of the service, e.g. "Slack brings all your communication together..."|yes|
| url | URL of the service, e.g. "<https://\_\_\_.slack.com/>". "\_\_\_" may be used as a placeholder, that can be configured when adding a service. | yes | |url|URL of the service, e.g. "https://\_\_\_.slack.com/". "\_\_\_" may be used as a placeholder, that can be configured when adding a service.|yes|
| type | Defines the type of the service. Must be one of `email` or `messaging`. | yes | |type|Defines the type of the service. Must be one of `email` or `messaging`.|yes|
| allow_popups | Set to `true` to allow popup windows for the service. | no | |allow_popups|Set to `true` to allow popup windows for the service.|no|
| note | Additional info to display when adding the service. | no | |note|Additional info to display when adding the service.|no|
| manual_notifications | Set to `true` to let Rambox trigger notifications. Can be used for services that doesn't support browser notifications. | no | |manual_notifications|Set to `true` to let Rambox trigger notifications. Can be used for services that doesn't support browser notifications.|no|
| js_unread | JavaScript code for setting the unread count (see below). | no | |js_unread|JavaScript code for setting the unread count (see below).|no|
| dont_update_unread_from_title | Set to `true` to prevent updating the unread count from the window title (see below). | no |
## Setting the unread count
While there is also a way to set the unread count by adding `(COUNT)` to the window title, this describes the preferred way of doing it: ### Setting the unread count
First set `dont_update_unread_from_title` in the service config to `true`. While by default the unread count is determined by looking for ` (COUNT)` to the window title, this describes the preferred way of doing it:
Code provided by `js_unread` will be injected into the service website. Code provided by `js_unread` will be injected into the service website.
You can retrieve the unread count in this JavaScript code e.g. by parsing elements. You can retrieve the unread count in this JavaScript code e.g. by parsing elements.

4
app/model/ServiceList.js

@ -48,9 +48,5 @@ Ext.define('Rambox.model.ServiceList', {
name: 'custom_domain' name: 'custom_domain'
,type: 'boolean' ,type: 'boolean'
,defaultValue: false ,defaultValue: false
},{
name: 'dont_update_unread_from_title'
,type: 'boolean'
,defaultValue: false
}] }]
}); });

16
app/store/ServicesList.js

@ -29,7 +29,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.whatsapp.com/' ,url: 'https://web.whatsapp.com/'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){const elements = document.querySelectorAll(\'.CxUIE, .unread\');let count = 0;for (let i = 0; i < elements.length; i++) {if (elements[i].querySelectorAll(\'*[data-icon="muted"]\').length === 0) {count++;}}updateBadge(count);}function updateBadge(count){if(count && count>=1){rambox.setUnreadCount(count);}else{rambox.clearUnreadCount();}}setInterval(checkUnread, 1e3);' ,js_unread: 'function checkUnread(){const elements = document.querySelectorAll(\'.CxUIE, .unread\');let count = 0;for (let i = 0; i < elements.length; i++) {if (elements[i].querySelectorAll(\'*[data-icon="muted"]\').length === 0) {count++;}}updateBadge(count);}function updateBadge(count){if(count && count>=1){rambox.setUnreadCount(count);}else{rambox.clearUnreadCount();}}setInterval(checkUnread, 1e3);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'slack' id: 'slack'
@ -38,7 +37,7 @@ Ext.define('Rambox.store.ServicesList', {
,description: locale['services[1]'] ,description: locale['services[1]']
,url: 'https://___.slack.com/' ,url: 'https://___.slack.com/'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){var e=$(".p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)").length,a=0;$(".p-channel_sidebar__badge").each(function(){a+=isNaN(parseInt($(this).html()))?0:parseInt($(this).html())}),updateBadge(e,a)}function updateBadge(e,a){var n=a>0?"("+a+") ":e>0?"(•) ":"";document.title=n+originalTitle}var originalTitle=document.title;setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){var e=$(".p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)").length,n=0;$(".p-channel_sidebar__badge").each(function(){n+=isNaN(parseInt($(this).html()))?0:parseInt($(this).html())}),count=0<n?n:0<e?"•":0,updateBadge(count)}function updateBadge(e){1<=e||"•"===e?rambox.setUnreadCount(e):rambox.clearUnreadCount();}setInterval(checkUnread,3e3);'
}, },
{ {
id: 'noysi' id: 'noysi'
@ -77,7 +76,6 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'messaging' ,type: 'messaging'
,titleBlink: true ,titleBlink: true
,manual_notifications: true ,manual_notifications: true
,dont_update_unread_from_title: true
,js_unread: 'function checkUnread(){updateBadge(document.getElementById("hangout-landing-chat").lastChild.contentWindow.document.body.getElementsByClassName("ee").length)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}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?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
}, },
{ {
@ -98,7 +96,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.telegram.org/' ,url: 'https://web.telegram.org/'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){var e=document.getElementsByClassName("im_dialog_badge badge"),t=0;for(i=0;i<e.length;i++)if(!e[i].classList.contains("im_dialog_badge_muted")){t+=parseInt(e[i].innerHTML.trim())}updateBadge(t)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);' ,js_unread: 'function checkUnread(){var e=document.getElementsByClassName("im_dialog_badge badge"),t=0;for(i=0;i<e.length;i++)if(!e[i].classList.contains("im_dialog_badge_muted")){t+=parseInt(e[i].innerHTML.trim())}updateBadge(t)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'wechat' id: 'wechat'
@ -118,7 +115,6 @@ Ext.define('Rambox.store.ServicesList', {
,allow_popups: true ,allow_popups: true
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("aim")[0];updateBadge(-1!=a.textContent.indexOf("(")&&(t=parseInt(a.textContent.replace(/[^0-9]/g,""))))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("aim")[0];updateBadge(-1!=a.textContent.indexOf("(")&&(t=parseInt(a.textContent.replace(/[^0-9]/g,""))))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,note: 'To enable desktop notifications, you have to go to Settings inside Gmail. <a href="https://support.google.com/mail/answer/1075549?ref_topic=3394466" target="_blank">Read more...</a>' ,note: 'To enable desktop notifications, you have to go to Settings inside Gmail. <a href="https://support.google.com/mail/answer/1075549?ref_topic=3394466" target="_blank">Read more...</a>'
,dont_update_unread_from_title: true
}, },
{ {
id: 'inbox' id: 'inbox'
@ -149,7 +145,6 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'messaging' ,type: 'messaging'
,note: 'To enable desktop notifications, you have to go to Options inside GroupMe. To count unread messages, be sure to be in Chats.' ,note: 'To enable desktop notifications, you have to go to Options inside GroupMe. To count unread messages, be sure to be in Chats.'
,js_unread: 'function checkUnread(){var a=document.querySelectorAll(".badge-count:not(.ng-hide)"),b=0;for(i=0;i<a.length;i++)b+=parseInt(a[i].innerHTML.trim());updateBadge(b)}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){var a=document.querySelectorAll(".badge-count:not(.ng-hide)"),b=0;for(i=0;i<a.length;i++)b+=parseInt(a[i].innerHTML.trim());updateBadge(b)}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'grape' id: 'grape'
@ -514,7 +509,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://www.icloud.com/#mail' ,url: 'https://www.icloud.com/#mail'
,type: 'email' ,type: 'email'
,js_unread: 'function checkUnread(){updateBadge(document.querySelector(".current-app").querySelector(".sb-badge").style.display==="none"?0:parseInt(document.querySelector(".current-app").querySelector(".text").innerHTML.trim()))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){updateBadge(document.querySelector(".current-app").querySelector(".sb-badge").style.display==="none"?0:parseInt(document.querySelector(".current-app").querySelector(".text").innerHTML.trim()))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'rainloop' id: 'rainloop'
@ -644,7 +638,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.flock.co/' ,url: 'https://web.flock.co/'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unreadMessages no-unread-mentions has-unread"),b=0;for(i=0;i<a.length;i++)b+=parseInt(a[i].innerHTML.trim());updateBadge(b)}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unreadMessages no-unread-mentions has-unread"),b=0;for(i=0;i<a.length;i++)b+=parseInt(a[i].innerHTML.trim());updateBadge(b)}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,dont_update_unread_from_title: true
}, },
{ {
@ -671,7 +664,6 @@ Ext.define('Rambox.store.ServicesList', {
url: 'https://www.xing.com/messages/conversations', url: 'https://www.xing.com/messages/conversations',
type: 'messaging', type: 'messaging',
js_unread: '(function() { let originalTitle = document.title; function checkUnread() { let count = null; let notificationElement = document.querySelector(\'[data-update="unread_conversations"]\'); if (notificationElement && notificationElement.style.display !== \'none\') { count = parseInt(notificationElement.textContent.trim(), 10); } updateBadge(count); } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();', js_unread: '(function() { let originalTitle = document.title; function checkUnread() { let count = null; let notificationElement = document.querySelector(\'[data-update="unread_conversations"]\'); if (notificationElement && notificationElement.style.display !== \'none\') { count = parseInt(notificationElement.textContent.trim(), 10); } updateBadge(count); } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();',
dont_update_unread_from_title: true
}, },
{ {
id: 'threema', id: 'threema',
@ -681,7 +673,6 @@ Ext.define('Rambox.store.ServicesList', {
url: 'https://web.threema.ch/', url: 'https://web.threema.ch/',
type: 'messaging', type: 'messaging',
js_unread: '(function () { let unreadCount = 0; function checkUnread() { let newUnread = 0; try { let webClientService = angular.element(document.documentElement).injector().get(\'WebClientService\'); let conversations = webClientService.conversations.conversations; conversations.forEach(function(conversation) { newUnread += conversation.unreadCount; }); } catch (e) { } if (newUnread !== unreadCount) { unreadCount = newUnread; updateBadge(unreadCount); } } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();', js_unread: '(function () { let unreadCount = 0; function checkUnread() { let newUnread = 0; try { let webClientService = angular.element(document.documentElement).injector().get(\'WebClientService\'); let conversations = webClientService.conversations.conversations; conversations.forEach(function(conversation) { newUnread += conversation.unreadCount; }); } catch (e) { } if (newUnread !== unreadCount) { unreadCount = newUnread; updateBadge(unreadCount); } } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();',
dont_update_unread_from_title: true
}, },
{ {
id: 'workplace' id: 'workplace'
@ -733,7 +724,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://app.zyptonite.com/' ,url: 'https://app.zyptonite.com/'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("z-messages"),b=0;for(i=0;i<a.length;i++)b+=parseInt(a[i].innerHTML.trim());updateBadge(b)}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("z-messages"),b=0;for(i=0;i<a.length;i++)b+=parseInt(a[i].innerHTML.trim());updateBadge(b)}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'fastmail' id: 'fastmail'
@ -806,7 +796,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://___/chat' ,url: 'https://___/chat'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){updateBadge(parseInt(document.getElementsByClassName("sidebar-notification-indicator").length > 0 ? document.getElementsByClassName("sidebar-notification-indicator")[0].innerHTML : 0))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){updateBadge(parseInt(document.getElementsByClassName("sidebar-notification-indicator").length > 0 ? document.getElementsByClassName("sidebar-notification-indicator")[0].innerHTML : 0))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'clocktweets' id: 'clocktweets'
@ -824,7 +813,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://app.intercom.io' ,url: 'https://app.intercom.io'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unread")[0];updateBadge(t=a===undefined?0:parseInt(a.textContent.replace(/[^0-9]/g,"")))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3000);' ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unread")[0];updateBadge(t=a===undefined?0:parseInt(a.textContent.replace(/[^0-9]/g,"")))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'allo' id: 'allo'
@ -834,7 +822,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://allo.google.com/web' ,url: 'https://allo.google.com/web'
,type: 'messaging' ,type: 'messaging'
,js_unread: 'function checkUnread(){var e=document.querySelectorAll(".hasUnread.conversation_item"),n=0;for(i=0;i<e.length;i++){var m=e[i].querySelector("#muted"),u=e[i].querySelector(".unreadCount"),c=parseInt(u.innerHTML.trim()),r=(m===null||m.style.display==="none")?c:0;n+=isNaN(r)?0:r}updateBadge(n)}function updateBadge(e){e&&e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,js_unread: 'function checkUnread(){var e=document.querySelectorAll(".hasUnread.conversation_item"),n=0;for(i=0;i<e.length;i++){var m=e[i].querySelector("#muted"),u=e[i].querySelector(".unreadCount"),c=parseInt(u.innerHTML.trim()),r=(m===null||m.style.display==="none")?c:0;n+=isNaN(r)?0:r}updateBadge(n)}function updateBadge(e){e&&e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,dont_update_unread_from_title: true
}, },
{ {
id: 'Kune' id: 'Kune'
@ -906,7 +893,6 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'messaging' ,type: 'messaging'
,titleBlink: true ,titleBlink: true
,manual_notifications: true ,manual_notifications: true
,dont_update_unread_from_title: true
,js_unread: 'function checkUnread(){updateBadge(document.querySelectorAll(".SSPGKf.EyyDtb.Q6oXP:not(.oCHqfe) .eM5l9e.FVKzAb").length)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);' ,js_unread: 'function checkUnread(){updateBadge(document.querySelectorAll(".SSPGKf.EyyDtb.Q6oXP:not(.oCHqfe) .eM5l9e.FVKzAb").length)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
}, },
{ {

8
app/ux/WebView.js

@ -477,14 +477,14 @@ Ext.define('Rambox.ux.WebView',{
/** /**
* Handles 'rambox.setUnreadCount' messages. * Handles 'rambox.setUnreadCount' messages.
* Sets the badge text if the event contains an integer as first argument. * Sets the badge text if the event contains an integer or a '•' (indicating non-zero but unknown number of unreads) as first argument.
* *
* @param event * @param event
*/ */
function handleSetUnreadCount(event) { function handleSetUnreadCount(event) {
if (Array.isArray(event.args) === true && event.args.length > 0) { if (Array.isArray(event.args) === true && event.args.length > 0) {
var count = event.args[0]; var count = event.args[0];
if (count === parseInt(count, 10)) { if (count === parseInt(count, 10) || "•" === count) {
me.setUnreadCount(count); me.setUnreadCount(count);
} }
} }
@ -497,9 +497,9 @@ Ext.define('Rambox.ux.WebView',{
}); });
/** /**
* Register page title update event listener only for services that don't prevent it by setting 'dont_update_unread_from_title' to true. * Register page title update event listener only for services that don't specify a js_unread
*/ */
if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('dont_update_unread_from_title') !== true) { if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('js_unread') === '' && me.record.get('js_unread') === '') {
webview.addEventListener("page-title-updated", function(e) { webview.addEventListener("page-title-updated", function(e) {
var count = e.title.match(/\(([^)]+)\)/); // Get text between (...) var count = e.title.match(/\(([^)]+)\)/); // Get text between (...)
count = count ? count[1] : '0'; count = count ? count[1] : '0';

Loading…
Cancel
Save