Update initialization

This commit is contained in:
toasted-nutbread 2019-12-21 13:19:31 -05:00
parent 35216332bf
commit 7ae0584077
3 changed files with 15 additions and 23 deletions

View File

@ -47,14 +47,15 @@ class SettingsPopupPreview {
window.apiOptionsGet = (...args) => this.apiOptionsGet(...args); window.apiOptionsGet = (...args) => this.apiOptionsGet(...args);
// Overwrite frontend // Overwrite frontend
this.frontend = Frontend.create(); const popup = PopupProxyHost.instance.createPopup(null, 0);
popup.setChildrenSupported(false);
this.frontend = new Frontend(popup);
this.frontend.setEnabled = function () {}; this.frontend.setEnabled = function () {};
this.frontend.searchClear = function () {}; this.frontend.searchClear = function () {};
this.frontend.popup.setChildrenSupported(false); await this.frontend.prepare();
await this.frontend.isPrepared();
// Overwrite popup // Overwrite popup
Popup.injectOuterStylesheet = (...args) => this.popupInjectOuterStylesheet(...args); Popup.injectOuterStylesheet = (...args) => this.popupInjectOuterStylesheet(...args);

View File

@ -17,4 +17,13 @@
*/ */
Frontend.create(); async function main() {
const data = window.frontendInitializationData || {};
const {id, depth=0, parentFrameId, ignoreNodes, url, proxy=false} = data;
const popup = proxy ? new PopupProxy(depth + 1, id, parentFrameId, url) : PopupProxyHost.instance.createPopup(null, depth);
const frontend = new Frontend(popup, ignoreNodes);
await frontend.prepare();
}
main();

View File

@ -34,23 +34,10 @@ class Frontend extends TextScanner {
url: popup.url url: popup.url
}; };
this.isPreparedPromiseResolve = null;
this.isPreparedPromise = new Promise((resolve) => { this.isPreparedPromiseResolve = resolve; });
this._orphaned = true; this._orphaned = true;
this._lastShowPromise = Promise.resolve(); this._lastShowPromise = Promise.resolve();
} }
static create() {
const data = window.frontendInitializationData || {};
const {id, depth=0, parentFrameId, ignoreNodes, url, proxy=false} = data;
const popup = proxy ? new PopupProxy(depth + 1, id, parentFrameId, url) : PopupProxyHost.instance.createPopup(null, depth);
const frontend = new Frontend(popup, ignoreNodes);
frontend.prepare();
return frontend;
}
async prepare() { async prepare() {
try { try {
await this.updateOptions(); await this.updateOptions();
@ -58,16 +45,11 @@ class Frontend extends TextScanner {
yomichan.on('orphaned', () => this.onOrphaned()); 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();
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} }
} }
isPrepared() {
return this.isPreparedPromise;
}
async onResize() { async onResize() {
const textSource = this.textSourceCurrent; const textSource = this.textSourceCurrent;
if (textSource !== null && await this.popup.isVisible()) { if (textSource !== null && await this.popup.isVisible()) {