summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/api.js4
-rw-r--r--ext/bg/js/audio.js2
-rw-r--r--ext/bg/js/backend.js12
-rw-r--r--ext/bg/js/settings/audio.js9
4 files changed, 19 insertions, 8 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 93e43a7d..4e5d81db 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -21,10 +21,6 @@ function apiTemplateRender(template, data) {
return _apiInvoke('templateRender', {data, template});
}
-function apiAudioGetUrl(definition, source, optionsContext) {
- return _apiInvoke('audioGetUrl', {definition, source, optionsContext});
-}
-
function _apiInvoke(action, params={}) {
const data = {action, params};
return new Promise((resolve, reject) => {
diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js
index 0732e25e..3bcfc4e7 100644
--- a/ext/bg/js/audio.js
+++ b/ext/bg/js/audio.js
@@ -171,7 +171,7 @@ async function audioInject(definition, fields, sources, optionsContext, audioSys
const expressions = definition.expressions;
const audioSourceDefinition = Array.isArray(expressions) ? expressions[0] : definition;
- const {uri} = await audioSystem.getExpressionAudio(audioSourceDefinition, sources, optionsContext, {tts: false});
+ const {uri} = await audioSystem.getExpressionAudio(audioSourceDefinition, sources, {tts: false, optionsContext});
const filename = audioBuildFilename(audioSourceDefinition);
if (filename !== null) {
definition.audio = {url: uri, filename};
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index abf4c673..60a87916 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -34,7 +34,7 @@ class Backend {
this.options = null;
this.optionsSchema = null;
this.defaultAnkiFieldTemplates = null;
- this.audioSystem = new AudioSystem();
+ this.audioSystem = new AudioSystem({getAudioUri: this._getAudioUri.bind(this)});
this.optionsContext = {
depth: 0,
url: window.location.href
@@ -764,6 +764,16 @@ class Backend {
// Utilities
+ async _getAudioUri(definition, source, details) {
+ let optionsContext = (typeof details === 'object' && details !== null ? details.optionsContext : null);
+ if (!(typeof optionsContext === 'object' && optionsContext !== null)) {
+ optionsContext = this.optionsContext;
+ }
+
+ const options = this.getOptions(optionsContext);
+ return await audioGetUrl(definition, source, options);
+ }
+
async _injectScreenshot(definition, fields, screenshot) {
let usesScreenshot = false;
for (const fieldValue of Object.values(fields)) {
diff --git a/ext/bg/js/settings/audio.js b/ext/bg/js/settings/audio.js
index 87ce1ffb..6f581d9b 100644
--- a/ext/bg/js/settings/audio.js
+++ b/ext/bg/js/settings/audio.js
@@ -16,14 +16,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/*global getOptionsContext, getOptionsMutable, settingsSaveOptions
+/*global getOptionsContext, getOptionsMutable, settingsSaveOptions, apiAudioGetUrl
AudioSystem, AudioSourceUI*/
let audioSourceUI = null;
let audioSystem = null;
async function audioSettingsInitialize() {
- audioSystem = new AudioSystem();
+ audioSystem = new AudioSystem({
+ getAudioUri: async (definition, source) => {
+ const optionsContext = getOptionsContext();
+ return await apiAudioGetUrl(definition, source, optionsContext);
+ }
+ });
const optionsContext = getOptionsContext();
const options = await getOptionsMutable(optionsContext);