rename display initialize methods to prepare

This commit is contained in:
siikamiika 2020-02-13 01:59:26 +02:00
parent 93eaee9765
commit df37acd17f
3 changed files with 28 additions and 28 deletions

View File

@ -47,7 +47,7 @@ class DisplaySearch extends Display {
async prepare() { async prepare() {
try { try {
await this.initialize(); await super.prepare();
await this.queryParser.prepare(); await this.queryParser.prepare();

View File

@ -33,6 +33,20 @@ class DisplayFloat extends Display {
window.addEventListener('message', (e) => this.onMessage(e), false); window.addEventListener('message', (e) => this.onMessage(e), false);
} }
async prepare(options, popupInfo, url, childrenSupported, scale) {
await super.prepare(options);
const {id, depth, parentFrameId} = popupInfo;
this.optionsContext.depth = depth;
this.optionsContext.url = url;
if (childrenSupported) {
popupNestedInitialize(id, depth, parentFrameId, url);
}
this.setContentScale(scale);
}
onError(error) { onError(error) {
if (this._orphaned) { if (this._orphaned) {
this.setContent('orphaned'); this.setContent('orphaned');
@ -92,20 +106,6 @@ class DisplayFloat extends Display {
setContentScale(scale) { setContentScale(scale) {
document.body.style.fontSize = `${scale}em`; document.body.style.fontSize = `${scale}em`;
} }
async initialize(options, popupInfo, url, childrenSupported, scale) {
await super.initialize(options);
const {id, depth, parentFrameId} = popupInfo;
this.optionsContext.depth = depth;
this.optionsContext.url = url;
if (childrenSupported) {
popupNestedInitialize(id, depth, parentFrameId, url);
}
this.setContentScale(scale);
}
} }
DisplayFloat._onKeyDownHandlers = new Map([ DisplayFloat._onKeyDownHandlers = new Map([
@ -122,7 +122,7 @@ DisplayFloat._messageHandlers = new Map([
['setContent', (self, {type, details}) => self.setContent(type, details)], ['setContent', (self, {type, details}) => self.setContent(type, details)],
['clearAutoPlayTimer', (self) => self.clearAutoPlayTimer()], ['clearAutoPlayTimer', (self) => self.clearAutoPlayTimer()],
['setCustomCss', (self, {css}) => self.setCustomCss(css)], ['setCustomCss', (self, {css}) => self.setCustomCss(css)],
['initialize', (self, {options, popupInfo, url, childrenSupported, scale}) => self.initialize(options, popupInfo, url, childrenSupported, scale)], ['initialize', (self, {options, popupInfo, url, childrenSupported, scale}) => self.prepare(options, popupInfo, url, childrenSupported, scale)],
['setContentScale', (self, {scale}) => self.setContentScale(scale)] ['setContentScale', (self, {scale}) => self.setContentScale(scale)]
]); ]);

View File

@ -43,6 +43,16 @@ class Display {
this.setInteractive(true); this.setInteractive(true);
} }
async prepare(options=null) {
await this.displayGenerator.prepare();
await this.updateOptions(options);
yomichan.on('optionsUpdate', () => this.updateOptions(null));
}
isPrepared() {
return this.options !== null;
}
onError(_error) { onError(_error) {
throw new Error('Override me'); throw new Error('Override me');
} }
@ -238,16 +248,6 @@ class Display {
throw new Error('Override me'); throw new Error('Override me');
} }
isInitialized() {
return this.options !== null;
}
async initialize(options=null) {
await this.displayGenerator.prepare();
await this.updateOptions(options);
yomichan.on('optionsUpdate', () => this.updateOptions(null));
}
async updateOptions(options) { async updateOptions(options) {
this.options = options ? options : await apiOptionsGet(this.getOptionsContext()); this.options = options ? options : await apiOptionsGet(this.getOptionsContext());
this.updateDocumentOptions(this.options); this.updateDocumentOptions(this.options);
@ -358,7 +358,7 @@ class Display {
async setContentTerms(definitions, context, token) { async setContentTerms(definitions, context, token) {
if (!context) { throw new Error('Context expected'); } if (!context) { throw new Error('Context expected'); }
if (!this.isInitialized()) { return; } if (!this.isPrepared()) { return; }
this.setEventListenersActive(false); this.setEventListenersActive(false);
@ -419,7 +419,7 @@ class Display {
async setContentKanji(definitions, context, token) { async setContentKanji(definitions, context, token) {
if (!context) { throw new Error('Context expected'); } if (!context) { throw new Error('Context expected'); }
if (!this.isInitialized()) { return; } if (!this.isPrepared()) { return; }
this.setEventListenersActive(false); this.setEventListenersActive(false);