Browse Source

This should finally fix the passive/timer logic.

Works with extensive testing.

Note to self: The record and service names are effectively backwards.
pull/3202/head
TheGoddessInari 7 years ago
parent
commit
c6b85e94ea
  1. 8
      app/ux/WebView.js
  2. 8
      app/view/add/Add.js

8
app/ux/WebView.js

@ -456,16 +456,16 @@ Ext.define('Rambox.ux.WebView',{
{
// 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 + '}';
const passive_event_listeners_code = `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_code + '}';
}
// 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 + '}';
const slowed_timers_code = `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_code + '}';
}
}

8
app/view/add/Add.js

@ -195,19 +195,19 @@ Ext.define('Rambox.view.add.Add',{
xtype: 'checkbox'
,boxLabel: "Use passive listeners"
,name: 'passive_event_listeners'
,checked: me.edit ? me.service.get('passive_event_listeners') : me.record.get('passive_event_listeners')
,checked: me.record.get('passive_event_listeners') && me.service.get('passive_event_listeners')
,uncheckedValue: false
,inputValue: true
,disabled: me.edit ? !me.service.get('passive_event_listeners') : !me.record.get('passive_event_listeners')
,disabled: !me.service.get('passive_event_listeners')
}
,{
xtype: 'checkbox'
,boxLabel: "100ms timer granularity"
,name: 'slowed_timers'
,checked: me.edit ? me.service.get('slowed_timers') : me.record.get('slowed_timers')
,checked: me.record.get('slowed_timers') && me.service.get('slowed_timers')
,uncheckedValue: false
,inputValue: true
,disabled: me.edit ? !me.service.get('slowed_timers') : !me.record.get('slowed_timers')
,disabled: !me.service.get('slowed_timers')
}
,{
xtype: 'checkbox'

Loading…
Cancel
Save