Update how orphan state is observed
This commit is contained in:
parent
2a95f1420f
commit
2519f99f54
@ -27,17 +27,24 @@ class DisplayFloat extends Display {
|
|||||||
url: window.location.href
|
url: window.location.href
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._orphaned = false;
|
||||||
|
|
||||||
|
yomichan.on('orphaned', () => this.onOrphaned());
|
||||||
window.addEventListener('message', (e) => this.onMessage(e), false);
|
window.addEventListener('message', (e) => this.onMessage(e), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
onError(error) {
|
onError(error) {
|
||||||
if (window.yomichan_orphaned) {
|
if (this._orphaned) {
|
||||||
this.setContentOrphaned();
|
this.setContentOrphaned();
|
||||||
} else {
|
} else {
|
||||||
logError(error, true);
|
logError(error, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onOrphaned() {
|
||||||
|
this._orphaned = true;
|
||||||
|
}
|
||||||
|
|
||||||
onSearchClear() {
|
onSearchClear() {
|
||||||
window.parent.postMessage('popupClose', '*');
|
window.parent.postMessage('popupClose', '*');
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ class Frontend extends TextScanner {
|
|||||||
this.isPreparedPromiseResolve = null;
|
this.isPreparedPromiseResolve = null;
|
||||||
this.isPreparedPromise = new Promise((resolve) => { this.isPreparedPromiseResolve = resolve; });
|
this.isPreparedPromise = new Promise((resolve) => { this.isPreparedPromiseResolve = resolve; });
|
||||||
|
|
||||||
|
this._orphaned = true;
|
||||||
this._lastShowPromise = Promise.resolve();
|
this._lastShowPromise = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ class Frontend extends TextScanner {
|
|||||||
try {
|
try {
|
||||||
await this.updateOptions();
|
await this.updateOptions();
|
||||||
|
|
||||||
|
yomichan.on('orphaned', () => this.onOrphaned());
|
||||||
yomichan.on('optionsUpdate', () => this.updateOptions());
|
yomichan.on('optionsUpdate', () => this.updateOptions());
|
||||||
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
|
||||||
this.isPreparedPromiseResolve();
|
this.isPreparedPromiseResolve();
|
||||||
@ -93,6 +95,10 @@ class Frontend extends TextScanner {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onOrphaned() {
|
||||||
|
this._orphaned = true;
|
||||||
|
}
|
||||||
|
|
||||||
getMouseEventListeners() {
|
getMouseEventListeners() {
|
||||||
return [
|
return [
|
||||||
...super.getMouseEventListeners(),
|
...super.getMouseEventListeners(),
|
||||||
@ -122,7 +128,7 @@ class Frontend extends TextScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (window.yomichan_orphaned) {
|
if (this._orphaned) {
|
||||||
if (textSource !== null && this.options.scanning.modifier !== 'none') {
|
if (textSource !== null && this.options.scanning.modifier !== 'none') {
|
||||||
this._lastShowPromise = this.popup.showContent(
|
this._lastShowPromise = this.popup.showContent(
|
||||||
textSource.getRect(),
|
textSource.getRect(),
|
||||||
|
@ -115,8 +115,8 @@ function _apiInvoke(action, params={}) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.yomichan_orphaned = true;
|
|
||||||
reject(e);
|
reject(e);
|
||||||
|
yomichan.triggerOrphaned(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -244,6 +244,14 @@ const yomichan = (() => {
|
|||||||
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Public
|
||||||
|
|
||||||
|
triggerOrphaned(error) {
|
||||||
|
this.trigger('orphaned', {error});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private
|
||||||
|
|
||||||
_onMessage({action, params}, sender, callback) {
|
_onMessage({action, params}, sender, callback) {
|
||||||
const handler = this._messageHandlers.get(action);
|
const handler = this._messageHandlers.get(action);
|
||||||
if (typeof handler !== 'function') { return false; }
|
if (typeof handler !== 'function') { return false; }
|
||||||
|
Loading…
Reference in New Issue
Block a user