From 3ea07abb0e71d685cef4894ebd7631ac5c98b2d8 Mon Sep 17 00:00:00 2001 From: SirStendec Date: Mon, 25 Apr 2022 13:47:10 -0400 Subject: [PATCH] 4.33.1 * Fixed: Locales failing to load due to missing `day.js` support. * Fixed: Locales failing to load due to capitalization. * Changed: Use a slightly newer API for constructing an audio compressor object for better compatibility. --- package.json | 2 +- src/i18n.js | 24 ++++++++++++++++++++++-- src/sites/shared/player.jsx | 22 +++++++++++++++++++--- src/utilities/translation-core.js | 9 +++++---- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 44bd8259..653568d8 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "frankerfacez", "author": "Dan Salvato LLC", - "version": "4.33.0", + "version": "4.33.1", "description": "FrankerFaceZ is a Twitch enhancement suite.", "private": true, "license": "Apache-2.0", diff --git a/src/i18n.js b/src/i18n.js index 1041ee86..27114c4f 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -451,6 +451,10 @@ export class TranslationManager extends Module { } + get dayjsLocale() { + return this._?._dayjs_locale; + } + get locale() { return this._ && this._.locale; } @@ -661,6 +665,9 @@ export class TranslationManager extends Module { async loadLocale(locale, chunk = null) { + // Normalize the locale. + locale = locale.toLowerCase(); + if ( locale === 'en' ) return {}; @@ -710,12 +717,13 @@ export class TranslationManager extends Module { } async setLocale(new_locale) { + // Normalize the locale. + new_locale = new_locale.toLowerCase(); + const old_locale = this._.locale; if ( new_locale === old_locale ) return []; - await this.loadDayjsLocale(new_locale); - this._.locale = new_locale; this._.clear(); this.log.info(`Changed Locale: ${new_locale} -- Old: ${old_locale}`); @@ -726,15 +734,27 @@ export class TranslationManager extends Module { // All the built-in messages are English. We don't need special // logic to load the translations. this.emit(':loaded', []); + this._._dayjs_locale = 'en'; return []; } const data = this.localeData[new_locale]; const phrases = await this.loadLocale(data?.id || new_locale); + let djs; + try { + djs = data?.dayjs_override || new_locale; + await this.loadDayjsLocale(djs); + } catch (err) { + this.log.warn(`Unable to load DayJS locale for ${new_locale}`); + djs = 'en'; + } + if ( this._.locale !== new_locale ) throw new Error('locale has changed since we started loading'); + this._._dayjs_locale = djs; + const added = this._.extend(phrases); if ( added.length ) { this.log.info(`Loaded Locale: ${new_locale} -- Phrases: ${added.length}`); diff --git a/src/sites/shared/player.jsx b/src/sites/shared/player.jsx index 1e9aad38..d084d52d 100644 --- a/src/sites/shared/player.jsx +++ b/src/sites/shared/player.jsx @@ -1541,14 +1541,30 @@ export default class PlayerBase extends Module { src.connect(ctx.destination); - comp = video._ffz_compressor = ctx.createDynamicsCompressor(); + try { + comp = video._ffz_compressor = new DynamicsCompressorNode(ctx); + } catch (err) { + this.log.info('Unable to uew new DynamicsCompressorNode. Falling back to old method.'); + comp = video._ffz_compressor = ctx.createDynamicsCompressor(); + } if ( this.settings.get('player.gain.enable') ) { - const gain = video._ffz_gain = ctx.createGain(); + let gain; let value = video._ffz_gain_value; if ( value == null ) value = this.settings.get('player.gain.default'); - gain.gain.value = value; + + try { + gain = video._ffz_gain = new GainNode(ctx, { + gain: value + }); + + } catch(err) { + this.log.info('Unable to uew new GainNode. Falling back to old method.'); + gain = video._ffz_gain = ctx.createGain(); + gain.gain.value = value; + } + comp.connect(gain); } diff --git a/src/utilities/translation-core.js b/src/utilities/translation-core.js index ece59830..1e663c98 100644 --- a/src/utilities/translation-core.js +++ b/src/utilities/translation-core.js @@ -204,6 +204,7 @@ export default class TranslationCore { this.warn = options.warn; this._locale = options.locale || 'en'; + this._dayjs_locale = options.dayjsLocale || 'en'; this.defaultLocale = options.defaultLocale || this._locale; this.transformation = null; @@ -250,7 +251,7 @@ export default class TranslationCore { without_suffix = f === 'plain'; try { - return d.locale(this._locale).fromNow(without_suffix); + return d.locale(this._dayjs_locale).fromNow(without_suffix); } catch(err) { return d.fromNow(without_suffix); } @@ -286,7 +287,7 @@ export default class TranslationCore { if ( format && ! this.formats.date[format] ) { const d = dayjs(value); try { - return d.locale(this._locale).format(format); + return d.locale(this._dayjs_locale).format(format); } catch(err) { return d.format(format); } @@ -305,7 +306,7 @@ export default class TranslationCore { if ( format && ! this.formats.time[format] ) { const d = dayjs(value); try { - return d.locale(this._locale).format(format); + return d.locale(this._dayjs_locale).format(format); } catch(err) { return d.format(format); } @@ -324,7 +325,7 @@ export default class TranslationCore { if ( format && ! this.formats.datetime[format] ) { const d = dayjs(value); try { - return d.locale(this._locale).format(format); + return d.locale(this._dayjs_locale).format(format); } catch(err) { return d.format(format); }