aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-12 14:41:24 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-12 15:31:29 -0400
commita5b208fb895d46793223910451d177dc53d9463a (patch)
treed67f7b3191d46b2ddd49531f69f8d9b19316ba9e /ext
parent8a1637f6b31719969473f1b393d46721a2398f11 (diff)
Check if objects are properly initialized before showing content
Diffstat (limited to 'ext')
-rw-r--r--ext/fg/js/popup.js7
-rw-r--r--ext/mixed/js/display.js8
2 files changed, 15 insertions, 0 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 396a5be9..a9fde7b6 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -79,6 +79,10 @@ class Popup {
});
}
+ isInitialized() {
+ return this.options !== null;
+ }
+
async setOptions(options) {
this.options = options;
}
@@ -212,6 +216,7 @@ class Popup {
}
async showOrphaned(elementRect, writingMode, options) {
+ if (!this.isInitialized()) { return; }
await this.show(elementRect, writingMode, options);
this.invokeApi('orphaned');
}
@@ -275,11 +280,13 @@ class Popup {
}
async termsShow(elementRect, writingMode, definitions, options, context) {
+ if (!this.isInitialized()) { return; }
await this.show(elementRect, writingMode, options);
this.invokeApi('termsShow', {definitions, options, context});
}
async kanjiShow(elementRect, writingMode, definitions, options, context) {
+ if (!this.isInitialized()) { return; }
await this.show(elementRect, writingMode, options);
this.invokeApi('kanjiShow', {definitions, options, context});
}
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 0d7be355..d5d055e0 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -187,6 +187,10 @@ class Display {
throw new Error('Override me');
}
+ isInitialized() {
+ return this.options !== null;
+ }
+
async initialize(options=null) {
await this.updateOptions(options);
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
@@ -236,6 +240,8 @@ class Display {
}
async termsShow(definitions, options, context) {
+ if (!this.isInitialized()) { return; }
+
try {
this.setEventListenersActive(false);
@@ -287,6 +293,8 @@ class Display {
}
async kanjiShow(definitions, options, context) {
+ if (!this.isInitialized()) { return; }
+
try {
this.setEventListenersActive(false);