fix: clear persistent Laya warning and apply language selection immediately (#12)

Two fixes: the ChannelList local-AI warning kept showing after the
runtime became available because status changes were not re-evaluated
on refresh; and selecting a language in the player did not switch the
stream variant immediately. Refresh warning visibility from the
latest laya status and apply the chosen variant/language on
selection, with tests for both behaviors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
blomios
2026-10-02 15:15:06 +02:00
parent cb4939daae
commit 4d662369c9
7 changed files with 63 additions and 8 deletions

View File

@ -170,6 +170,24 @@
return listMode === 'grouped';
}
function selectVariantByLanguage(logicalChannel, languageCode, options = {}) {
const isFavorite = options.isFavorite || (() => false);
const isHidden = options.isHidden || (() => false);
const visible = (logicalChannel?.variants || []).filter(variant => !isHidden(variant));
if (!visible.length) return null;
const preferredVisible = visible.find(variant => getVariantKey(variant) === getVariantKey(logicalChannel.preferredVariant));
if (!languageCode || languageCode === 'auto') return preferredVisible || visible[0];
const matching = languageCode && languageCode !== 'auto'
? visible.filter(variant => variant.language?.code === languageCode)
: visible;
const candidates = matching.length ? matching : (preferredVisible ? [preferredVisible] : visible);
return candidates.map((variant, index) => ({ variant, index })).sort((a, b) =>
Number(isFavorite(b.variant)) - Number(isFavorite(a.variant)) ||
qualityScore(b.variant) - qualityScore(a.variant) ||
a.index - b.index
)[0].variant;
}
return {
normalizeChannelName,
displayNameForFingerprint,
@ -177,6 +195,7 @@
getQuality,
groupChannels,
orderFlatChannels,
selectVariantByLanguage,
shouldUseFavoritesGroup
};
});

View File

@ -79,7 +79,10 @@
function channelListWarning(mode, status = {}, batchFailed = false) {
if (mode === 'algo') return '';
if (batchFailed || status.modelPresent !== true || status.runtimeAvailable !== true) {
if (batchFailed) {
return 'Local AI language matching failed. Standard channel matching is being used.';
}
if (status.modelPresent !== true || status.runtimeAvailable !== true) {
return 'Local AI service is unavailable. Standard channel matching is being used.';
}
return '';