mirror of https://github.com/gorhill/uBlock.git
Code review re. dynamically loaded vapi-client-extra.js
Related commit:
- 87d0e456f1
Ensure that the code which depends on extending
`vapi-client.js` is ready to deal with
`vapi-client-extra.js` failing to load.
This commit is contained in:
parent
e97ab16a54
commit
efa4ff3bcf
|
@ -79,6 +79,7 @@ vAPI.messaging = {
|
|||
port: null,
|
||||
portTimer: null,
|
||||
portTimerDelay: 10000,
|
||||
extended: undefined,
|
||||
extensions: [],
|
||||
msgIdGenerator: 1,
|
||||
pending: new Map(),
|
||||
|
@ -219,6 +220,19 @@ vAPI.messaging = {
|
|||
port.postMessage({ channel, msgId, msg });
|
||||
return promise;
|
||||
},
|
||||
|
||||
// Dynamically extend capabilities.
|
||||
extend: function() {
|
||||
if ( this.extended === undefined ) {
|
||||
this.extended = vAPI.messaging.send('vapi', {
|
||||
what: 'extendClient'
|
||||
}).then(( ) => {
|
||||
return vAPI instanceof Object && this.extensions.length !== 0;
|
||||
}).catch(( ) => {
|
||||
});
|
||||
}
|
||||
return this.extended;
|
||||
},
|
||||
};
|
||||
|
||||
vAPI.shutdown.add(( ) => {
|
||||
|
|
|
@ -303,11 +303,8 @@ const handlers = {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
(async ( ) => {
|
||||
// Dynamically add broadcast listening abilities.
|
||||
if ( vAPI.broadcastListener instanceof Object === false ) {
|
||||
await vAPI.messaging.send('vapi', { what: 'extendClient' });
|
||||
}
|
||||
vAPI.messaging.extend().then(extended => {
|
||||
if ( extended !== true ) { return; }
|
||||
const broadcastListener = msg => {
|
||||
if ( msg.what === 'loggerDisabled' ) {
|
||||
processTimer.clear();
|
||||
|
@ -318,7 +315,7 @@ const handlers = {
|
|||
}
|
||||
};
|
||||
vAPI.broadcastListener.add(broadcastListener);
|
||||
})();
|
||||
});
|
||||
|
||||
vAPI.domWatcher.addListener(handlers);
|
||||
|
||||
|
|
|
@ -884,7 +884,7 @@ const onMessage = function(request) {
|
|||
|
||||
// Install DOM inspector widget
|
||||
|
||||
const bootstrap = async function(ev) {
|
||||
const bootstrap = function(ev) {
|
||||
if ( ev ) {
|
||||
pickerRoot.removeEventListener(ev.type, bootstrap);
|
||||
}
|
||||
|
@ -934,22 +934,22 @@ const bootstrap = async function(ev) {
|
|||
|
||||
// Dynamically add direct connection abilities so that we can establish
|
||||
// a direct, fast messaging connection to the logger.
|
||||
if ( vAPI.MessagingConnection instanceof Function === false ) {
|
||||
await vAPI.messaging.send('vapi', { what: 'extendClient' });
|
||||
}
|
||||
vAPI.MessagingConnection.connectTo('domInspector', 'loggerUI', msg => {
|
||||
switch ( msg.what ) {
|
||||
case 'connectionAccepted':
|
||||
loggerConnectionId = msg.id;
|
||||
start();
|
||||
break;
|
||||
case 'connectionBroken':
|
||||
shutdown();
|
||||
break;
|
||||
case 'connectionMessage':
|
||||
onMessage(msg.payload);
|
||||
break;
|
||||
}
|
||||
vAPI.messaging.extend().then(extended => {
|
||||
if ( extended !== true ) { return; }
|
||||
vAPI.MessagingConnection.connectTo('domInspector', 'loggerUI', msg => {
|
||||
switch ( msg.what ) {
|
||||
case 'connectionAccepted':
|
||||
loggerConnectionId = msg.id;
|
||||
start();
|
||||
break;
|
||||
case 'connectionBroken':
|
||||
shutdown();
|
||||
break;
|
||||
case 'connectionMessage':
|
||||
onMessage(msg.payload);
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue