diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index ed7171b5..d12104bf 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -68,7 +68,8 @@ async function apiDefinitionAdd(definition, mode, context, optionsContext) { await audioInject( definition, options.anki.terms.fields, - options.general.audioSource + options.general.audioSource, + optionsContext ); } @@ -174,8 +175,8 @@ apiCommandExec.handlers = { } }; -async function apiAudioGetUrl(definition, source) { - return audioBuildUrl(definition, source); +async function apiAudioGetUrl(definition, source, optionsContext) { + return audioBuildUrl(definition, source, optionsContext); } async function apiInjectScreenshot(definition, fields, screenshot) { diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index de4e80f3..36ce03cf 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -88,7 +88,7 @@ const audioUrlBuilders = { } }; -async function audioBuildUrl(definition, mode, cache={}) { +async function audioBuildUrl(definition, mode, optionsContext, cache={}) { const cacheKey = `${mode}:${definition.expression}`; if (cache.hasOwnProperty(cacheKey)) { return Promise.resolve(cache[cacheKey]); @@ -96,7 +96,7 @@ async function audioBuildUrl(definition, mode, cache={}) { if (audioUrlBuilders.hasOwnProperty(mode)) { const handler = audioUrlBuilders[mode]; - return handler(definition).then( + return handler(definition, optionsContext).then( (url) => { cache[cacheKey] = url; return url; @@ -138,7 +138,7 @@ function audioBuildFilename(definition) { } } -async function audioInject(definition, fields, mode) { +async function audioInject(definition, fields, mode, optionsContext) { let usesAudio = false; for (const name in fields) { if (fields[name].includes('{audio}')) { @@ -157,7 +157,7 @@ async function audioInject(definition, fields, mode) { audioSourceDefinition = definition.expressions[0]; } - const url = await audioBuildUrl(audioSourceDefinition, mode); + const url = await audioBuildUrl(audioSourceDefinition, mode, optionsContext); const filename = audioBuildFilename(audioSourceDefinition); if (url && filename) { diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index fb77b71e..453f4282 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -181,7 +181,7 @@ Backend.messageHandlers = { noteView: ({noteId}) => apiNoteView(noteId), templateRender: ({template, data, dynamic}) => apiTemplateRender(template, data, dynamic), commandExec: ({command}) => apiCommandExec(command), - audioGetUrl: ({definition, source}) => apiAudioGetUrl(definition, source), + audioGetUrl: ({definition, source, optionsContext}) => apiAudioGetUrl(definition, source, optionsContext), screenshotGet: ({options}, sender) => apiScreenshotGet(options, sender), forward: ({action, params}, sender) => apiForward(action, params, sender), frameInformationGet: (params, sender) => apiFrameInformationGet(sender), diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index d0ac649a..a553e514 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -45,8 +45,8 @@ function apiTemplateRender(template, data, dynamic) { return utilInvoke('templateRender', {data, template, dynamic}); } -function apiAudioGetUrl(definition, source) { - return utilInvoke('audioGetUrl', {definition, source}); +function apiAudioGetUrl(definition, source, optionsContext) { + return utilInvoke('audioGetUrl', {definition, source, optionsContext}); } function apiCommandExec(command) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 17370654..78e6d8e3 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -404,7 +404,7 @@ class Display { this.setSpinnerVisible(true); const expression = expressionIndex === -1 ? definition : definition.expressions[expressionIndex]; - let url = await apiAudioGetUrl(expression, this.options.general.audioSource); + let url = await apiAudioGetUrl(expression, this.options.general.audioSource, this.optionsContext); if (!url) { url = '/mixed/mp3/button.mp3'; }