aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/yomichan.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js/yomichan.js')
-rw-r--r--ext/mixed/js/yomichan.js35
1 files changed, 30 insertions, 5 deletions
diff --git a/ext/mixed/js/yomichan.js b/ext/mixed/js/yomichan.js
index 00335eba..d921a5a2 100644
--- a/ext/mixed/js/yomichan.js
+++ b/ext/mixed/js/yomichan.js
@@ -47,6 +47,8 @@ const yomichan = (() => {
// NOP
}
+ this._isExtensionUnloaded = false;
+
const {promise, resolve} = deferPromise();
this._isBackendPreparedPromise = promise;
this._isBackendPreparedPromiseResolve = resolve;
@@ -61,12 +63,16 @@ const yomichan = (() => {
// Public
+ get isExtensionUnloaded() {
+ return this._isExtensionUnloaded;
+ }
+
prepare() {
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
}
ready() {
- chrome.runtime.sendMessage({action: 'yomichanCoreReady'});
+ this.sendMessage({action: 'yomichanCoreReady'});
return this._isBackendPreparedPromise;
}
@@ -80,10 +86,6 @@ const yomichan = (() => {
return id;
}
- triggerOrphaned(error) {
- this.trigger('orphaned', {error});
- }
-
isExtensionUrl(url) {
try {
return url.startsWith(chrome.runtime.getURL('/'));
@@ -190,8 +192,31 @@ const yomichan = (() => {
this.trigger('log', {error, level, context});
}
+ sendMessage(...args) {
+ try {
+ return chrome.runtime.sendMessage(...args);
+ } catch (e) {
+ this._onExtensionUnloaded(e);
+ throw e;
+ }
+ }
+
+ connect(...args) {
+ try {
+ return chrome.runtime.connect(...args);
+ } catch (e) {
+ this._onExtensionUnloaded(e);
+ throw e;
+ }
+ }
+
// Private
+ _onExtensionUnloaded(error) {
+ this._isExtensionUnloaded = true;
+ this.trigger('extensionUnloaded', {error});
+ }
+
_getUrl() {
return (typeof window === 'object' && window !== null ? window.location.href : '');
}