Browse Source

Badge bug fixed

Bug when badge in title is like (2.300)
Fixes #91
Fixes #92
pull/116/head
Ramiro Saenz 9 years ago
parent
commit
57220c5676
  1. 2
      app/Application.js
  2. 14
      app/util/Format.js
  3. 22
      app/ux/WebView.js
  4. 6
      app/ux/mixin/Badge.js

2
app/Application.js

@ -149,7 +149,7 @@ Ext.define('Rambox.Application', {
,updateTotalNotifications: function( newValue, oldValue ) {
newValue = parseInt(newValue);
if ( newValue > 0 ) {
document.title = 'Rambox (' + newValue + ')';
document.title = 'Rambox (' + Rambox.util.Format.formatNumber(newValue) + ')';
} else {
document.title = 'Rambox';
}

14
app/util/Format.js

@ -0,0 +1,14 @@
/**
* Created by vsxed on 7/11/2016.
*/
Ext.define('Rambox.util.Format', {
singleton: true
,formatNumber: function(n) {
return n.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}
,stripNumber: function(n) {
return (typeof n == "number") ? n : parseInt(n.match(/\d+/g).join(""));
}
});

22
app/ux/WebView.js

@ -5,6 +5,10 @@ Ext.define('Rambox.ux.WebView',{
extend: 'Ext.panel.Panel'
,xtype: 'webview'
,requires: [
'Rambox.util.Format'
]
// private
,notifications: 0
,zoomLevel: 0
@ -74,7 +78,11 @@ Ext.define('Rambox.ux.WebView',{
,onBadgeTextChange: function( tab, badgeText, oldBadgeText ) {
if ( oldBadgeText === null ) oldBadgeText = 0;
var actualNotifications = Rambox.app.getTotalNotifications();
Rambox.app.setTotalNotifications(actualNotifications - parseInt(oldBadgeText) + parseInt(badgeText));
oldBadgeText = Rambox.util.Format.stripNumber(oldBadgeText);
badgeText = Rambox.util.Format.stripNumber(badgeText);
Rambox.app.setTotalNotifications(actualNotifications - oldBadgeText + badgeText);
}
,onAfterRender: function() {
@ -131,8 +139,10 @@ Ext.define('Rambox.ux.WebView',{
webview.addEventListener("page-title-updated", function(e) {
var count = e.title.match(/\(([^)]+)\)/); // Get text between (...)
count = count ? count[1] : '0';
count = count.match(/\d+/g); // Some services have special characters. Example: (•)
count = count ? parseInt(count[0]) : 0;
count = count.match(/\d+/g).join(""); // Some services have special characters. Example: (•)
count = count ? parseInt(count) : 0;
var formattedCount = Rambox.util.Format.formatNumber(count);
switch ( me.type ) {
case 'messenger':
@ -140,7 +150,7 @@ Ext.define('Rambox.ux.WebView',{
me.notifications = count;
}
if ( count || e.title === 'Messenger' ) {
me.tab.setBadgeText(count);
me.tab.setBadgeText(formattedCount);
}
if ( e.title === 'Messenger' ) me.notifications = 0;
break;
@ -149,12 +159,12 @@ Ext.define('Rambox.ux.WebView',{
me.notifications = count;
}
if ( count || e.title === 'Google Hangouts' ) {
me.tab.setBadgeText(count);
me.tab.setBadgeText(formattedCount);
}
if ( e.title === 'Google Hangouts' ) me.notifications = 0;
break;
default:
me.tab.setBadgeText(count);
me.tab.setBadgeText(formattedCount);
me.notifications = count;
break;
}

6
app/ux/mixin/Badge.js

@ -1,6 +1,6 @@
/**
* Created by whiskeredwonder on 7/30/2015.
*/
* Created by whiskeredwonder on 7/30/2015.
*/
Ext.define('Rambox.ux.mixin.Badge', {
extend: 'Ext.Mixin',
@ -32,7 +32,7 @@ Ext.define('Rambox.ux.mixin.Badge', {
var me = this,
el = me.el;
if (me.rendered) {
if (me.rendered && badgeText !== '0') {
el.set({
'data-badge-text': badgeText
});

Loading…
Cancel
Save