1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-01 16:49:39 +02:00

#1443: code review

This commit is contained in:
gorhill 2016-03-15 11:17:56 -04:00
parent ce23420a05
commit 2ac643b520

View File

@ -211,18 +211,20 @@ vAPI.messaging = {
this.disconnectListenerCallback = this.disconnectListener.bind(this); this.disconnectListenerCallback = this.disconnectListener.bind(this);
this.portPollerCallback = this.portPoller.bind(this); this.portPollerCallback = this.portPoller.bind(this);
} }
var port = null;
try { try {
port = this.port = chrome.runtime.connect({name: vAPI.sessionId}); this.port = chrome.runtime.connect({name: vAPI.sessionId}) || null;
port.onMessage.addListener(this.messageListenerCallback);
port.onDisconnect.addListener(this.disconnectListenerCallback);
} catch (ex) { } catch (ex) {
this.port = null;
}
if ( this.port !== null ) {
this.port.onMessage.addListener(this.messageListenerCallback);
this.port.onDisconnect.addListener(this.disconnectListenerCallback);
} }
this.portTimerDelay = 10000; this.portTimerDelay = 10000;
if ( this.portTimer === null ) { if ( this.portTimer === null ) {
this.portTimer = vAPI.setTimeout(this.portPollerCallback, this.portTimerDelay); this.portTimer = vAPI.setTimeout(this.portPollerCallback, this.portTimerDelay);
} }
return port; return this.port;
}, },
connect: function() { connect: function() {
@ -330,7 +332,7 @@ vAPI.messaging = {
vAPI.shutdown.add(function() { vAPI.shutdown.add(function() {
vAPI.messaging.shutdown(); vAPI.messaging.shutdown();
window.vAPI = null; delete window.vAPI;
}); });
// https://www.youtube.com/watch?v=rT5zCHn0tsg // https://www.youtube.com/watch?v=rT5zCHn0tsg