Browse Source

Add the promised blacklist for timer granularity and passive listeners.

Also add our first happy blacklister, 'whatapp' looks to have some
sort of race condition when the timers aren't exactly as fast as it
expects.
pull/3202/head
TheGoddessInari 7 years ago
parent
commit
952d9f36cf
  1. 8
      app/model/ServiceList.js
  2. 1
      app/store/ServicesList.js
  3. 32
      app/ux/WebView.js
  4. 2
      app/view/add/Add.js

8
app/model/ServiceList.js

@ -44,6 +44,14 @@ Ext.define('Rambox.model.ServiceList', {
name: 'manual_notifications' name: 'manual_notifications'
,type: 'boolean' ,type: 'boolean'
,defaultValue: false ,defaultValue: false
},{
name: 'passive_event_listeners'
,type: 'boolean'
,defaultValue: true
},{
name: 'slowed_timers'
,type: 'boolean'
,defaultValue: true
},{ },{
name: 'userAgent' name: 'userAgent'
,type: 'string' ,type: 'string'

1
app/store/ServicesList.js

@ -29,6 +29,7 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.whatsapp.com/' ,url: 'https://web.whatsapp.com/'
,type: 'messaging' ,type: 'messaging'
,js_unread: `let checkUnread=()=>{const elements=document.querySelectorAll(".CxUIE, .unread");let count=0;for(let i of elements)0===i.querySelectorAll('*[data-icon="muted"]').length&&count++;rambox.updateBadge(count)};setInterval(checkUnread,1e3);` ,js_unread: `let checkUnread=()=>{const elements=document.querySelectorAll(".CxUIE, .unread");let count=0;for(let i of elements)0===i.querySelectorAll('*[data-icon="muted"]').length&&count++;rambox.updateBadge(count)};setInterval(checkUnread,1e3);`
,slowed_timers: false
}, },
{ {
id: 'slack' id: 'slack'

32
app/ux/WebView.js

@ -450,6 +450,23 @@ Ext.define('Rambox.ux.WebView',{
css_inject += custom_css; css_inject += custom_css;
} }
} }
// Use passive listeners by default
let passive_event_listeners = Ext.getStore('ServicesList').getById(me.record.get('type')).get('passive_event_listeners');
if (passive_event_listeners && me.record.get('passive_event_listeners'))
{
// 3rdparty: This uses npm 'default-passive-events' 1.0.10 inline. Link to license:
// https://github.com/zzarcon/default-passive-events/blob/master/LICENSE
const passive_event_listeners = `const eventListenerOptionsSupported=()=>{let supported=!1;try{const opts=Object.defineProperty({},"passive",{get(){supported=!0}});window.addEventListener("test",null,opts),window.removeEventListener("test",null,opts)}catch(e){}return supported},defaultOptions={passive:!0,capture:!1},supportedPassiveTypes=["scroll","wheel","touchstart","touchmove","touchenter","touchend","touchleave","mouseout","mouseleave","mouseup","mousedown","mousemove","mouseenter","mousewheel","mouseover"],getDefaultPassiveOption=(passive,eventName)=>void 0!==passive?passive:-1!==supportedPassiveTypes.indexOf(eventName)&&defaultOptions.passive,getWritableOptions=options=>{const passiveDescriptor=Object.getOwnPropertyDescriptor(options,"passive");return passiveDescriptor&&!0!==passiveDescriptor.writable&&void 0===passiveDescriptor.set?Object.assign({},options):options},overwriteAddEvent=superMethod=>{EventTarget.prototype.addEventListener=function(type,listener,options){const usesListenerOptions="object"==typeof options&&null!==options,useCapture=usesListenerOptions?options.capture:options;(options=usesListenerOptions?getWritableOptions(options):{}).passive=getDefaultPassiveOption(options.passive,type),options.capture=void 0===useCapture?defaultOptions.capture:useCapture,superMethod.call(this,type,listener,options)},EventTarget.prototype.addEventListener._original=superMethod},supportsPassive=eventListenerOptionsSupported();if(supportsPassive){const addEvent=EventTarget.prototype.addEventListener;overwriteAddEvent(addEvent)}`;
js_inject += '{' + passive_event_listeners + '}';
}
// Use slowed timers by default
let slowed_timers = Ext.getStore('ServicesList').getById(me.record.get('type')).get('slowed_timers');
if (slowed_timers && me.record.get('slowed_timers'))
{
const slowed_timers = `window.setTimeout=window.setTimeout;const __setTimeout=window.setTimeout;window.setTimeout=function(func,time){let a=time;return a<100&&(a=100),__setTimeout(func,a)};`;
js_inject += '{' + slowed_timers + '}';
}
} }
// Prevent Title blinking (some services have) and only allow when the title have an unread regex match: "(3) Title" // Prevent Title blinking (some services have) and only allow when the title have an unread regex match: "(3) Title"
@ -458,21 +475,6 @@ Ext.define('Rambox.ux.WebView',{
js_inject += js_preventBlink; js_inject += js_preventBlink;
} }
// Use passive listeners by default
if (me.record.get('passive_event_listeners'))
{
// 3rdparty: This uses npm 'default-passive-events' 1.0.10 inline. Link to license:
// https://github.com/zzarcon/default-passive-events/blob/master/LICENSE
const passive_event_listeners = `const eventListenerOptionsSupported=()=>{let supported=!1;try{const opts=Object.defineProperty({},"passive",{get(){supported=!0}});window.addEventListener("test",null,opts),window.removeEventListener("test",null,opts)}catch(e){}return supported},defaultOptions={passive:!0,capture:!1},supportedPassiveTypes=["scroll","wheel","touchstart","touchmove","touchenter","touchend","touchleave","mouseout","mouseleave","mouseup","mousedown","mousemove","mouseenter","mousewheel","mouseover"],getDefaultPassiveOption=(passive,eventName)=>void 0!==passive?passive:-1!==supportedPassiveTypes.indexOf(eventName)&&defaultOptions.passive,getWritableOptions=options=>{const passiveDescriptor=Object.getOwnPropertyDescriptor(options,"passive");return passiveDescriptor&&!0!==passiveDescriptor.writable&&void 0===passiveDescriptor.set?Object.assign({},options):options},overwriteAddEvent=superMethod=>{EventTarget.prototype.addEventListener=function(type,listener,options){const usesListenerOptions="object"==typeof options&&null!==options,useCapture=usesListenerOptions?options.capture:options;(options=usesListenerOptions?getWritableOptions(options):{}).passive=getDefaultPassiveOption(options.passive,type),options.capture=void 0===useCapture?defaultOptions.capture:useCapture,superMethod.call(this,type,listener,options)},EventTarget.prototype.addEventListener._original=superMethod},supportsPassive=eventListenerOptionsSupported();if(supportsPassive){const addEvent=EventTarget.prototype.addEventListener;overwriteAddEvent(addEvent)}`;
js_inject += '{' + passive_event_listeners + '}';
}
// Use slowed timers by default
if (me.record.get('slowed_timers'))
{
const slowed_timers = `window.setTimeout=window.setTimeout;const __setTimeout=window.setTimeout;window.setTimeout=function(func,time){let a=time;return a<100&&(a=100),__setTimeout(func,a)};`;
js_inject += '{' + slowed_timers + '}';
}
// Scroll always to top (bug) // Scroll always to top (bug)
js_inject += 'document.body.scrollTop=0;'; js_inject += 'document.body.scrollTop=0;';

2
app/view/add/Add.js

@ -198,6 +198,7 @@ Ext.define('Rambox.view.add.Add',{
,checked: me.edit ? me.record.get('passive_event_listeners') : true ,checked: me.edit ? me.record.get('passive_event_listeners') : true
,uncheckedValue: false ,uncheckedValue: false
,inputValue: true ,inputValue: true
,hidden: Ext.getStore('ServicesList').getById(me.record.get('type')).get('passive_event_listeners') === false
} }
,{ ,{
xtype: 'checkbox' xtype: 'checkbox'
@ -206,6 +207,7 @@ Ext.define('Rambox.view.add.Add',{
,checked: me.edit ? me.record.get('slowed_timers') : true ,checked: me.edit ? me.record.get('slowed_timers') : true
,uncheckedValue: false ,uncheckedValue: false
,inputValue: true ,inputValue: true
,hidden: Ext.getStore('ServicesList').getById(me.record.get('type')).get('slowed_timers') === false
} }
,{ ,{
xtype: 'checkbox' xtype: 'checkbox'

Loading…
Cancel
Save