Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Audio refactor #401

Merged
merged 5 commits into from
Mar 10, 2020
Merged

Conversation

toasted-nutbread
Copy link
Collaborator

As mentioned in #399, this refactors the other audio.js source.

@@ -18,7 +18,7 @@

/*global docRangeFromPoint, docSentenceExtract
apiKanjiFind, apiTermsFind, apiNoteView, apiOptionsGet, apiDefinitionsAddable, apiDefinitionAdd
apiScreenshotGet, apiForward, apiAudioGetUrl
apiScreenshotGet, apiForward, apiAudioGetUri
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be made one per line, such as

/* global
 * apiScreenshotGet
 * apiForward
 * apiAudioGetUri
 */ 

At the risk of taking up a bit more space, this would reduce the amount of conflicts to resolve.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider that outside of the scope of this change, but that sounds like a good idea. Particularly because, long-term, the number of global definitions should eventually be reduced. For example:

/* global
 * apiScreenshotGet
 * apiForward
 * apiAudioGetUri
 */

Will likely eventually become:

/* global
 * api
 */

@siikamiika
Copy link
Collaborator

The URL --> URI change got me curious, what is tts:?text=%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A in terms of URIs? At least the other default ones are all URLs. I guess you could add a custom sound for failing a lookup using a data URI, though.

@@ -515,7 +515,7 @@ class Backend {

async _onApiAudioGetUrl({definition, source, optionsContext}) {
const options = this.getOptions(optionsContext);
return await audioGetUrl(definition, source, options);
return await this.audioUriBuilder.getUri(source, definition, options);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either AudioUriBuilder.getUri should be changed to the definition, source, options or the other way around, whichever is more desirable, to avoid confusion

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update source to be the first argument consistently, since there's precedent for that in multiple places. There are a few places where this parameter is named either source or mode, and I'll try to settle on only one of those also.

async findTerms(mode, text, details, options) {
switch (mode) {
case 'group':
return await this.findTermsGrouped(text, details, options);
case 'merge':
return await this.findTermsMerged(text, details, options);
case 'split':
return await this.findTermsSplit(text, details, options);
case 'simple':
return await this.findTermsSimple(text, details, options);
default:
return [[], 0];
}
}

async setContent(type, details) {
const token = {}; // Unique identifier token
this.setContentToken = token;
try {
switch (type) {
case 'terms':
await this.setContentTerms(details.definitions, details.context, token);
break;
case 'kanji':
await this.setContentKanji(details.definitions, details.context, token);
break;
case 'orphaned':
this.setContentOrphaned();
break;
}
} catch (e) {
this.onError(e);
} finally {
if (this.setContentToken === token) {
this.setContentToken = null;
}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess it can be done in another PR later too if the amount of changes needed would otherwise explode. The variable names are also becoming more relevant when using object destructuring as I noticed in 0112dba.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take care of it in this PR, just haven't gotten around to it yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's considerably more simple to do the opposite of what I said. So in the interest of minimal changes, and hopefully minimal breakage, I went that route. 0cbf427

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, tested that it still works

@toasted-nutbread
Copy link
Collaborator Author

The URL --> URI change got me curious, what is tts:?text=%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A in terms of URIs? At least the other default ones are all URLs. I guess you could add a custom sound for failing a lookup using a data URI, though.

It's made up, added in order to allow the same API to be used without having to make the return value more complicated than a string.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants