summaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-09 12:54:59 -0400
committerGitHub <noreply@github.com>2020-09-09 12:54:59 -0400
commite3a767876944467b09086501a8b2ef308716090a (patch)
treeccaca3fac375d975354648d227299e6b162a3db6 /ext/mixed/js
parent2aa86cc5f8cda022076f7fa047f17fdcca4a0f5e (diff)
Anki screenshot refactor (#791)
* Use more consistent style for injectScreenshot * Move screenshot generation into AnkiNoteBuilder/Backend * Get optionsContext before await
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/api.js4
-rw-r--r--ext/mixed/js/display.js44
2 files changed, 5 insertions, 43 deletions
diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js
index 63b3a3c0..701caba8 100644
--- a/ext/mixed/js/api.js
+++ b/ext/mixed/js/api.js
@@ -77,8 +77,8 @@ const api = (() => {
return this._invoke('kanjiFind', {text, optionsContext});
}
- definitionAdd(definition, mode, context, details, optionsContext) {
- return this._invoke('definitionAdd', {definition, mode, context, details, optionsContext});
+ definitionAdd(definition, mode, context, ownerFrameId, optionsContext) {
+ return this._invoke('definitionAdd', {definition, mode, context, ownerFrameId, optionsContext});
}
definitionsAddable(definitions, modes, context, optionsContext) {
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 2bb85f1f..70b3895a 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -1047,18 +1047,10 @@ class Display extends EventDispatcher {
try {
this.setSpinnerVisible(true);
- const details = {};
- if (this._noteUsesScreenshot(mode)) {
- try {
- const screenshot = await this._getScreenshot();
- details.screenshot = screenshot;
- } catch (e) {
- // NOP
- }
- }
-
+ const ownerFrameId = this._ownerFrameId;
+ const optionsContext = this.getOptionsContext();
const noteContext = await this._getNoteContext();
- const noteId = await api.definitionAdd(definition, mode, noteContext, details, this.getOptionsContext());
+ const noteId = await api.definitionAdd(definition, mode, noteContext, ownerFrameId, optionsContext);
if (noteId) {
const index = this._definitions.indexOf(definition);
const adderButton = this._adderButtonFind(index, mode);
@@ -1136,36 +1128,6 @@ class Display extends EventDispatcher {
}
}
- _noteUsesScreenshot(mode) {
- const optionsAnki = this._options.anki;
- const fields = (mode === 'kanji' ? optionsAnki.kanji : optionsAnki.terms).fields;
- for (const fieldValue of Object.values(fields)) {
- if (fieldValue.includes('{screenshot}')) {
- return true;
- }
- }
- return false;
- }
-
- async _getScreenshot() {
- const ownerFrameId = this._ownerFrameId;
- let token = null;
- try {
- if (ownerFrameId !== null) {
- token = await api.crossFrame.invoke(ownerFrameId, 'setAllVisibleOverride', {value: false, priority: 0, awaitFrame: true});
- }
-
- const {format, quality} = this._options.anki.screenshot;
- const dataUrl = await api.screenshotGet({format, quality});
-
- return {dataUrl, format};
- } finally {
- if (token !== null) {
- await api.crossFrame.invoke(ownerFrameId, 'clearAllVisibleOverride', {token});
- }
- }
- }
-
_getFirstExpressionIndex() {
return this._options.general.resultOutputMode === 'merge' ? 0 : -1;
}