aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-11 20:53:18 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-18 21:12:54 -0400
commit5c5c70326d797b819cff33390e04dde93c63669c (patch)
treecf47a37b4b1b14bed5c64f40db084c0a3524b831 /ext/bg
parentc9704b5c5e3b8f78888adaa2dcd4fa54f28c9db1 (diff)
Add a delay before showing the loading state
Intended to prevent flickering when startup is quick
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/backend.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 1589524b..9cfa621a 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -77,6 +77,7 @@ class Backend {
this._defaultBrowserActionTitle = null;
this._isPrepared = false;
+ this._badgePrepareDelayTimer = null;
this._messageHandlers = new Map([
['yomichanCoreReady', {handler: this._onApiYomichanCoreReady.bind(this), async: false}],
@@ -123,6 +124,10 @@ class Backend {
async prepare() {
this._defaultBrowserActionTitle = await this._getBrowserIconTitle();
+ this._badgePrepareDelayTimer = setTimeout(() => {
+ this._badgePrepareDelayTimer = null;
+ this._updateBadge();
+ }, 1000);
this._updateBadge();
await this.database.prepare();
await this.translator.prepare();
@@ -158,6 +163,11 @@ class Backend {
const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.runtime.sendMessage({action: 'backendPrepared'}, callback);
+ if (this._badgePrepareDelayTimer !== null) {
+ clearTimeout(this._badgePrepareDelayTimer);
+ this._badgePrepareDelayTimer = null;
+ }
+
this._isPrepared = true;
this._updateBadge();
}
@@ -878,9 +888,11 @@ class Backend {
let status = null;
if (!this._isPrepared) {
- text = '...';
- color = '#f0ad4e';
- status = 'Loading';
+ if (this._badgePrepareDelayTimer === null) {
+ text = '...';
+ color = '#f0ad4e';
+ status = 'Loading';
+ }
} else if (!this._anyOptionsMatches((options) => options.general.enable)) {
text = 'off';
color = '#555555';