Pass anki reference to AnkiNoteBuilder constructor

This commit is contained in:
toasted-nutbread 2020-04-12 12:46:32 -04:00
parent 37c374fb63
commit ebfc7ca945
2 changed files with 6 additions and 5 deletions

View File

@ -16,7 +16,8 @@
*/
class AnkiNoteBuilder {
constructor({audioSystem, renderTemplate}) {
constructor({anki, audioSystem, renderTemplate}) {
this._anki = anki;
this._audioSystem = audioSystem;
this._renderTemplate = renderTemplate;
}
@ -101,7 +102,7 @@ class AnkiNoteBuilder {
}
}
async injectScreenshot(definition, fields, screenshot, anki) {
async injectScreenshot(definition, fields, screenshot) {
if (!this._containsMarker(fields, 'screenshot')) { return; }
const now = new Date(Date.now());
@ -109,7 +110,7 @@ class AnkiNoteBuilder {
const data = screenshot.dataUrl.replace(/^data:[\w\W]*?,/, '');
try {
await anki.storeMediaFile(filename, data);
await this._anki.storeMediaFile(filename, data);
} catch (e) {
return;
}

View File

@ -56,6 +56,7 @@ class Backend {
this.audioSystem = new AudioSystem({getAudioUri: this._getAudioUri.bind(this)});
this.audioUriBuilder = new AudioUriBuilder();
this.ankiNoteBuilder = new AnkiNoteBuilder({
anki: this.anki,
audioSystem: this.audioSystem,
renderTemplate: this._renderTemplate.bind(this)
});
@ -482,8 +483,7 @@ class Backend {
await this.ankiNoteBuilder.injectScreenshot(
definition,
options.anki.terms.fields,
details.screenshot,
this.anki
details.screenshot
);
}