1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-24 11:22:44 +01:00

Informal code review to tidy up logger buffer fetching implementation

This commit is contained in:
Raymond Hill 2018-12-23 15:35:32 -05:00
parent ddee2bff13
commit 99cdec5ba6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -505,10 +505,7 @@ var truncateLog = function(size) {
/******************************************************************************/ /******************************************************************************/
const onLogBufferRead = function(response) { const onLogBufferRead = function(response) {
if ( !response || response.unavailable ) { if ( !response || response.unavailable ) { return; }
readLogBufferAsync();
return;
}
// Disable tooltips? // Disable tooltips?
if ( if (
@ -565,45 +562,57 @@ const onLogBufferRead = function(response) {
'disabled', 'disabled',
tbody.querySelector('tr') === null tbody.querySelector('tr') === null
); );
readLogBufferAsync();
}; };
/******************************************************************************/ /******************************************************************************/
// This can be called only once, at init time. After that, this will be called const readLogBuffer = (function() {
// automatically. If called after init time, this will be messy, and this would let timer;
// require a bit more code to ensure no multi time out events.
const readLogBuffer = function() { const readLogBufferNow = function() {
if ( logger.ownerId === undefined ) { return; } if ( logger.ownerId === undefined ) { return; }
const msg = {
what: 'readAll', const msg = {
ownerId: logger.ownerId, what: 'readAll',
tabIdsToken: allTabIdsToken, ownerId: logger.ownerId,
tabIdsToken: allTabIdsToken,
};
// This is to detect changes in the position or size of the logger
// popup window (if in use).
if (
popupLoggerBox instanceof Object &&
(
self.screenX !== popupLoggerBox.x ||
self.screenY !== popupLoggerBox.y ||
self.outerWidth !== popupLoggerBox.w ||
self.outerHeight !== popupLoggerBox.h
)
) {
popupLoggerBox.x = self.screenX;
popupLoggerBox.y = self.screenY;
popupLoggerBox.w = self.outerWidth;
popupLoggerBox.h = self.outerHeight;
msg.popupLoggerBoxChanged = true;
}
vAPI.messaging.send('loggerUI', msg, response => {
timer = undefined;
onLogBufferRead(response);
readLogBufferLater();
});
}; };
if (
popupLoggerBox instanceof Object &&
(
self.screenX !== popupLoggerBox.x ||
self.screenY !== popupLoggerBox.y ||
self.outerWidth !== popupLoggerBox.w ||
self.outerHeight !== popupLoggerBox.h
)
) {
popupLoggerBox.x = self.screenX;
popupLoggerBox.y = self.screenY;
popupLoggerBox.w = self.outerWidth;
popupLoggerBox.h = self.outerHeight;
msg.popupLoggerBoxChanged = true;
}
vAPI.messaging.send('loggerUI', msg, onLogBufferRead);
};
const readLogBufferAsync = function() { const readLogBufferLater = function() {
if ( logger.ownerId === undefined ) { return; } if ( timer !== undefined ) { return; }
vAPI.setTimeout(readLogBuffer, 1200); if ( logger.ownerId === undefined ) { return; }
}; timer = vAPI.setTimeout(readLogBufferNow, 1200);
};
readLogBufferNow();
return readLogBufferLater;
})();
/******************************************************************************/ /******************************************************************************/
@ -1802,7 +1811,7 @@ const grabView = function() {
if ( logger.ownerId === undefined ) { if ( logger.ownerId === undefined ) {
logger.ownerId = Date.now(); logger.ownerId = Date.now();
} }
readLogBufferAsync(); readLogBuffer();
}; };
const releaseView = function() { const releaseView = function() {
@ -1821,8 +1830,6 @@ window.addEventListener('beforeunload', releaseView);
/******************************************************************************/ /******************************************************************************/
readLogBuffer();
uDom('#pageSelector').on('change', pageSelectorChanged); uDom('#pageSelector').on('change', pageSelectorChanged);
uDom('#refresh').on('click', reloadTab); uDom('#refresh').on('click', reloadTab);