diff --git a/dist/manifest.json b/dist/manifest.json index 6599e82..2453c01 100644 --- a/dist/manifest.json +++ b/dist/manifest.json @@ -1,6 +1,6 @@ { "name": "inboxy: Inbox Bundles for Gmail", - "version": "1.5.3", + "version": "1.5.4", "description": "Adds Google Inbox bundles to Gmail", "homepage_url": "https://www.inboxymail.com", "background": { diff --git a/src/bundling/Bundler.js b/src/bundling/Bundler.js index 4843d6a..af1cea3 100644 --- a/src/bundling/Bundler.js +++ b/src/bundling/Bundler.js @@ -55,6 +55,8 @@ class Bundler { /** * Bundle together the messages on the current page of messages, if they aren't already bundled, * optionally reopening the most recently open bundle. + * + * Returns an object with info for debug printing. */ bundleMessages(reopenRecentBundle) { const bundledMail = this.bundledMail; @@ -64,14 +66,18 @@ class Bundler { : null; if (!messageList) { - return; + return { + foundMessageList: false, + }; } + let debugInfo = { foundMessageList: true }; + this.messageListWatcher.disconnect(); // Only redraw if message list isn't still bundled if (!messageList.children[0].classList.contains('is-bundled')) { - this._bundleMessages(messageList); + debugInfo = this._bundleMessages(messageList); messageList.children[0].classList.add('is-bundled'); } @@ -84,6 +90,8 @@ class Bundler { } this.messageListWatcher.observe(); + + return debugInfo; } /** @@ -91,6 +99,8 @@ class Bundler { * * Table rows are reordered by using flexbox and the order property, since Gmail's js seems * to require the DOM nodes to remain in their original order. + * + * Returns an object with info for debug printing. */ _bundleMessages(messageList) { const tableBody = messageList.querySelector(Selectors.TABLE_BODY); @@ -116,6 +126,11 @@ class Bundler { this._applyStyles(messageNodes); this._attachHandlers(messageNodes, messageList); + + return { + numMessages: messageNodes.length, + numBundles: Object.keys(bundlesByLabel).length, + }; } /** diff --git a/src/content.js b/src/content.js index cfcd330..46eaf1d 100644 --- a/src/content.js +++ b/src/content.js @@ -38,8 +38,16 @@ import { isStarredPage, } from './util/MessagePageUtils'; +const DEBUG = true; +const logDebugMessage = message => { + if (DEBUG) { + console.log(`inboxy-debug: ${message}`); + } +}; + const html = document.querySelector('html'); if (html) { + logDebugMessage('Applying styles'); html.classList.add(InboxyClasses.INBOXY); } @@ -127,7 +135,9 @@ document.addEventListener('mousedown', e => { // function handleContentLoaded() { + logDebugMessage('Handle content loaded event'); const bundleCurrentPage = supportsBundling(window.location.href); + logDebugMessage(`Url: ${window.location.href}, page supports bundling: ${bundleCurrentPage}`); tryBundling(0, bundleCurrentPage); } @@ -144,6 +154,8 @@ function tryBundling(i, bundleCurrentPage) { setTimeout(() => tryBundling(i + 1, bundleCurrentPage), RETRY_TIMEOUT_MS); } else { + logDebugMessage('Start observers'); + addPinnedToggle(); startObservers(); @@ -163,7 +175,10 @@ function tryBundling(i, bundleCurrentPage) { setTimeout(() => tryBundling(i + 1, bundleCurrentPage), RETRY_TIMEOUT_MS); } else { - bundler.bundleMessages(false); + logDebugMessage('Bundle messages'); + + const debugInfo = bundler.bundleMessages(false); + logDebugMessage(JSON.stringify(debugInfo)); addPinnedToggle(); startObservers(); }