diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-09 22:03:56 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-09 22:03:56 -0400 |
commit | 22b218d17238cc003938ef46403596c2183a9c1b (patch) | |
tree | f6c8158b6974ef164df394429c0058e65f8426ca | |
parent | 8be0ddeb26ec5a7bf8d3044852754c4625a27230 (diff) |
Pass optionsContext to audioBuildUrl handlers
-rw-r--r-- | ext/bg/js/api.js | 7 | ||||
-rw-r--r-- | ext/bg/js/audio.js | 8 | ||||
-rw-r--r-- | ext/bg/js/backend.js | 2 | ||||
-rw-r--r-- | ext/fg/js/api.js | 4 | ||||
-rw-r--r-- | ext/mixed/js/display.js | 2 |
5 files changed, 12 insertions, 11 deletions
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'; } |