Pass optionsContext to audioBuildUrl handlers
This commit is contained in:
parent
8be0ddeb26
commit
22b218d172
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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),
|
||||
|
@ -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) {
|
||||
|
@ -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';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user