fix: make Laya status consistent between Settings and ChannelList (#12)
The model was reported as ready while the AI runtime was actually unreachable, and the Download action stayed visible afterwards. Distinguish model-downloaded from runtime-available in layaStatusPresentation, derive the Download action from the real combined state, and align Settings and ChannelList rendering on that single source of truth. Cover the combined status cases with tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -33,6 +33,7 @@ class ChannelList {
|
||||
this.channelLanguagePreferences = this.loadChannelLanguagePreferences();
|
||||
this.layaLanguageResults = new Map();
|
||||
this.languageDetectionNotice = '';
|
||||
this.languageDetectionFallback = false;
|
||||
this._languageDetectionRequest = 0;
|
||||
|
||||
this.loadCollapsedState();
|
||||
@ -335,6 +336,7 @@ class ChannelList {
|
||||
const safeMode = ['algo', 'laya', 'hybrid'].includes(mode) ? mode : 'algo';
|
||||
this.layaLanguageResults.clear();
|
||||
this.languageDetectionNotice = '';
|
||||
this.languageDetectionFallback = false;
|
||||
if (this.channels.length > 0) {
|
||||
this.render();
|
||||
void this.refreshLayaLanguages(safeMode);
|
||||
@ -346,6 +348,7 @@ class ChannelList {
|
||||
if (mode === 'algo') {
|
||||
this.layaLanguageResults.clear();
|
||||
this.languageDetectionNotice = '';
|
||||
this.languageDetectionFallback = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -359,6 +362,15 @@ class ChannelList {
|
||||
});
|
||||
const results = new Map();
|
||||
try {
|
||||
const status = await API.laya.getStatus();
|
||||
if (!status?.modelPresent || !status?.runtimeAvailable) {
|
||||
if (requestId !== this._languageDetectionRequest) return;
|
||||
this.layaLanguageResults.clear();
|
||||
this.languageDetectionFallback = true;
|
||||
this.languageDetectionNotice = 'Local AI service is unavailable. Standard channel matching is being used.';
|
||||
this.render();
|
||||
return;
|
||||
}
|
||||
for (let index = 0; index < descriptors.length; index += 64) {
|
||||
const response = await API.laya.detectLanguages(descriptors.slice(index, index + 64));
|
||||
(response.results || []).forEach(result => results.set(String(result.id), result));
|
||||
@ -366,12 +378,12 @@ class ChannelList {
|
||||
if (requestId !== this._languageDetectionRequest) return;
|
||||
this.layaLanguageResults = results;
|
||||
this.languageDetectionNotice = '';
|
||||
this.languageDetectionFallback = false;
|
||||
} catch (err) {
|
||||
if (requestId !== this._languageDetectionRequest) return;
|
||||
this.layaLanguageResults.clear();
|
||||
this.languageDetectionNotice = mode === 'hybrid'
|
||||
? 'Local AI is unavailable; using standard channel matching.'
|
||||
: 'Local AI is unavailable. Download or start the model in Settings.';
|
||||
this.languageDetectionFallback = true;
|
||||
this.languageDetectionNotice = 'Local AI service is unavailable. Standard channel matching is being used.';
|
||||
console.warn('[ChannelList] Local AI language detection unavailable:', err.message);
|
||||
}
|
||||
this.render();
|
||||
@ -405,7 +417,9 @@ class ChannelList {
|
||||
selectedVariants: this.selectedVariants,
|
||||
preferredLanguage: this.preferredLanguage,
|
||||
languagePreferences: this.channelLanguagePreferences,
|
||||
languageMode: window.app?.player?.settings?.languageDetectionMode || 'algo',
|
||||
languageMode: this.languageDetectionFallback
|
||||
? 'algo'
|
||||
: (window.app?.player?.settings?.languageDetectionMode || 'algo'),
|
||||
languageResults: this.layaLanguageResults,
|
||||
isFavorite: channel => this.isFavorite(channel.sourceId, channel.id),
|
||||
isHidden: channel => this.isHidden('channel', channel.sourceId, channel.streamId || channel.id)
|
||||
@ -420,6 +434,15 @@ class ChannelList {
|
||||
notice.className = 'laya-language-notice';
|
||||
notice.setAttribute('role', 'status');
|
||||
notice.textContent = this.languageDetectionNotice;
|
||||
const settingsButton = document.createElement('button');
|
||||
settingsButton.type = 'button';
|
||||
settingsButton.className = 'btn btn-ghost laya-notice-action';
|
||||
settingsButton.textContent = 'Open settings';
|
||||
settingsButton.addEventListener('click', () => {
|
||||
window.app?.navigateTo?.('settings');
|
||||
window.app?.pages?.settings?.switchTab?.('player');
|
||||
});
|
||||
notice.appendChild(settingsButton);
|
||||
this.container.appendChild(notice);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user