From 5cba421201b596f4430dd45f3715ad515661b109 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 13 Jun 2020 10:20:12 -0400 Subject: [PATCH] Update the badge icon if the backend experiences an error (#602) --- ext/bg/js/backend.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index faba6c42..0c7a0301 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -168,6 +168,8 @@ class Backend { }, 1000); this._updateBadge(); + yomichan.on('log', this._onLog.bind(this)); + await this.environment.prepare(); await this.database.prepare(); await this.translator.prepare(); @@ -316,6 +318,14 @@ class Backend { chrome.tabs.sendMessage(tabId, {action: 'zoomChanged', params: {oldZoomFactor, newZoomFactor}}, callback); } + _onLog({level}) { + const levelValue = this._getErrorLevelValue(level); + if (levelValue <= this._getErrorLevelValue(this._logErrorLevel)) { return; } + + this._logErrorLevel = level; + this._updateBadge(); + } + applyOptions() { const options = this.getOptions(this.optionsContext); this._updateBadge(); @@ -809,12 +819,6 @@ class Backend { _onApiLog({error, level, context}) { yomichan.log(jsonToError(error), level, context); - - const levelValue = this._getErrorLevelValue(level); - if (levelValue <= this._getErrorLevelValue(this._logErrorLevel)) { return; } - - this._logErrorLevel = level; - this._updateBadge(); } _onApiLogIndicatorClear() {