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:
@ -126,6 +126,8 @@ class SettingsPage {
|
||||
}
|
||||
});
|
||||
document.getElementById('laya-use-standard')?.addEventListener('click', () => this.useStandardLanguageDetection());
|
||||
document.getElementById('laya-check-again')?.addEventListener('click', () => void this.loadLayaStatus());
|
||||
document.getElementById('laya-copy-command')?.addEventListener('click', () => void this.copyLayaStartCommand());
|
||||
document.getElementById('laya-show-details')?.addEventListener('click', () => {
|
||||
const details = document.getElementById('laya-error-details');
|
||||
const button = document.getElementById('laya-show-details');
|
||||
@ -149,11 +151,16 @@ class SettingsPage {
|
||||
|
||||
renderLayaStatus(status = {}) {
|
||||
const statusElement = document.getElementById('laya-model-status');
|
||||
const modelStateElement = document.getElementById('laya-model-state');
|
||||
const serviceStateElement = document.getElementById('laya-service-state');
|
||||
const sizeElement = document.getElementById('laya-model-size');
|
||||
const messageElement = document.getElementById('laya-model-message');
|
||||
const downloadButton = document.getElementById('laya-download-model');
|
||||
const removeButton = document.getElementById('laya-remove-model');
|
||||
const useStandardButton = document.getElementById('laya-use-standard');
|
||||
const checkAgainButton = document.getElementById('laya-check-again');
|
||||
const copyCommandButton = document.getElementById('laya-copy-command');
|
||||
const startCommand = document.getElementById('laya-start-command');
|
||||
const progress = document.getElementById('laya-download-progress');
|
||||
const progressTrack = document.getElementById('laya-progress-track');
|
||||
const progressBar = document.getElementById('laya-progress-bar');
|
||||
@ -165,12 +172,17 @@ class SettingsPage {
|
||||
const mode = this.app.player?.settings?.languageDetectionMode || 'algo';
|
||||
const presentation = LayaStatusPresentation.presentLayaStatus(status, mode);
|
||||
statusElement.textContent = presentation.statusLabel;
|
||||
modelStateElement.textContent = presentation.modelLabel;
|
||||
serviceStateElement.textContent = presentation.serviceLabel;
|
||||
const size = status.sizeBytes || status.runtime?.modelSizeBytes;
|
||||
sizeElement.textContent = size ? this.formatBytes(size) : '';
|
||||
sizeElement.textContent = size ? `· ${this.formatBytes(size)}` : '';
|
||||
downloadButton.hidden = !presentation.showDownload;
|
||||
downloadButton.textContent = presentation.downloadLabel;
|
||||
removeButton.hidden = !presentation.showRemove;
|
||||
useStandardButton.hidden = !presentation.showUseStandard;
|
||||
checkAgainButton.hidden = !presentation.showCheckAgain;
|
||||
copyCommandButton.hidden = !presentation.showStartCommand;
|
||||
startCommand.hidden = !presentation.showStartCommand;
|
||||
downloadButton.disabled = presentation.busy || Boolean(this.layaOperationPending);
|
||||
removeButton.disabled = presentation.busy || Boolean(this.layaOperationPending);
|
||||
|
||||
@ -199,6 +211,7 @@ class SettingsPage {
|
||||
details.hidden = true;
|
||||
details.textContent = presentation.errorDetail;
|
||||
if (presentation.errorMessage) messageElement.textContent = presentation.errorMessage;
|
||||
else if (presentation.availabilityMessage) messageElement.textContent = presentation.availabilityMessage;
|
||||
else if (this.layaOperationPending) messageElement.textContent = this.layaOperationPending;
|
||||
else if (mode !== 'algo' && (!status.modelPresent || !status.runtimeAvailable)) {
|
||||
messageElement.textContent = 'Local AI is not ready. Download the model and ensure the runtime is running. Live TV will remain available.';
|
||||
@ -266,6 +279,24 @@ class SettingsPage {
|
||||
this.renderLayaStatus(this.layaStatus);
|
||||
}
|
||||
|
||||
async copyLayaStartCommand() {
|
||||
const command = 'docker compose --profile laya up -d';
|
||||
const button = document.getElementById('laya-copy-command');
|
||||
try {
|
||||
await navigator.clipboard.writeText(command);
|
||||
button.textContent = 'Copied';
|
||||
} catch {
|
||||
const code = document.querySelector('#laya-start-command code');
|
||||
const selection = window.getSelection();
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(code);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
button.textContent = 'Command selected';
|
||||
}
|
||||
setTimeout(() => { button.textContent = 'Copy start command'; }, 2000);
|
||||
}
|
||||
|
||||
async initTranscodingSettings() {
|
||||
// Encoder settings
|
||||
const hwEncoderSelect = document.getElementById('setting-hw-encoder');
|
||||
|
||||
Reference in New Issue
Block a user