mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-20 04:30:54 +02:00
bring over relevant desktop settings
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
DEFAULT_LYRICS_DISPLAY_SETTINGS,
|
||||
normalizeLyricsDisplaySettings,
|
||||
normalizeLyricsLanguagePriority,
|
||||
} from './displaySettings.ts';
|
||||
|
||||
test('lyrics display settings default safely for upgraded installs', () => {
|
||||
assert.deepEqual(normalizeLyricsDisplaySettings(null), DEFAULT_LYRICS_DISPLAY_SETTINGS);
|
||||
assert.deepEqual(normalizeLyricsDisplaySettings({}), DEFAULT_LYRICS_DISPLAY_SETTINGS);
|
||||
});
|
||||
|
||||
test('lyrics display settings preserve explicit disabled layers and voice labels', () => {
|
||||
assert.deepEqual(normalizeLyricsDisplaySettings({
|
||||
wordTimingEnabled: false,
|
||||
furiganaEnabled: false,
|
||||
translationsEnabled: false,
|
||||
translationPriority: ['fr'],
|
||||
voiceLabelsEnabled: true,
|
||||
}), {
|
||||
wordTimingEnabled: false,
|
||||
furiganaEnabled: false,
|
||||
translationsEnabled: false,
|
||||
translationPriority: ['fr'],
|
||||
voiceLabelsEnabled: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('language priority trims, deduplicates case-insensitively, and restores defaults when empty', () => {
|
||||
assert.deepEqual(normalizeLyricsLanguagePriority(' en, ja-Latn, EN, fr , '), ['en', 'ja-Latn', 'fr']);
|
||||
assert.deepEqual(normalizeLyricsLanguagePriority(' , '), ['en', 'ja-Latn']);
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
export const DEFAULT_LYRICS_LANGUAGE_PRIORITY = ['en', 'ja-Latn'] as const;
|
||||
|
||||
export interface LyricsDisplaySettings {
|
||||
wordTimingEnabled: boolean;
|
||||
furiganaEnabled: boolean;
|
||||
translationsEnabled: boolean;
|
||||
translationPriority: string[];
|
||||
voiceLabelsEnabled: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_LYRICS_DISPLAY_SETTINGS: LyricsDisplaySettings = {
|
||||
wordTimingEnabled: true,
|
||||
furiganaEnabled: true,
|
||||
translationsEnabled: true,
|
||||
translationPriority: [...DEFAULT_LYRICS_LANGUAGE_PRIORITY],
|
||||
voiceLabelsEnabled: false,
|
||||
};
|
||||
|
||||
export function normalizeLyricsLanguagePriority(value: unknown): string[] {
|
||||
const entries = Array.isArray(value)
|
||||
? value
|
||||
: typeof value === 'string'
|
||||
? value.split(',')
|
||||
: [];
|
||||
const seen = new Set<string>();
|
||||
const normalized: string[] = [];
|
||||
for (const entry of entries) {
|
||||
if (typeof entry !== 'string') continue;
|
||||
const trimmed = entry.trim();
|
||||
if (!trimmed) continue;
|
||||
const key = trimmed.toLocaleLowerCase();
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
normalized.push(trimmed);
|
||||
}
|
||||
return normalized.length > 0 ? normalized : [...DEFAULT_LYRICS_LANGUAGE_PRIORITY];
|
||||
}
|
||||
|
||||
export function normalizeLyricsDisplaySettings(value: unknown): LyricsDisplaySettings {
|
||||
const candidate = value && typeof value === 'object' && !Array.isArray(value)
|
||||
? value as Partial<LyricsDisplaySettings>
|
||||
: {};
|
||||
return {
|
||||
wordTimingEnabled: candidate.wordTimingEnabled !== false,
|
||||
furiganaEnabled: candidate.furiganaEnabled !== false,
|
||||
translationsEnabled: candidate.translationsEnabled !== false,
|
||||
translationPriority: normalizeLyricsLanguagePriority(candidate.translationPriority),
|
||||
voiceLabelsEnabled: candidate.voiceLabelsEnabled === true,
|
||||
};
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user