Merge origin/main into fix/hal-722-radio-next-no-autoplay

main moved the Radio markup into Vue views and rebuilt the UI tests on
stores. Resolved:
- src/ui/templates/context.html: deleted in main; the new privacy note now
  lives in src/ui/views/panels/RadioPanel.vue.
- src/ui/radioControls.test.mjs: main's store fixture; the Next/Previous
  autoplay test drives store.act('cycleRadio').
- src/voice/gevRealtime.test.mjs: main's createTestVoiceUi; the stop and
  select handoff cases stay one table-driven test.
- src/data/radioNextState.test.mjs reads the published gev-radio view.
- src/i18n/locales/ar.json: the new note translated for the Arabic locale.
This commit is contained in:
German Khokhlov committed 2026-11-02 12:36:31 +04:00
commit a2be947aba
679 files changed
+45369 -19625

No files matched your search

+198 -170
View File
@@ -1,4 +1,9 @@
/** Render Radio state without making playback or Context decisions. */
/**
* Present Radio state without making playback or Context decisions: the
* panel view renders the directory row, station card, transport, volume and
* playback line, the Cockpit's compact radio controls and the directory
* tuner from what this publishes (`gev-radio` store).
*/
import { t } from '../i18n/index.js';
export function renderRadioState(state) {
@@ -26,22 +31,17 @@ export function renderRadioState(state) {
document
.getElementById('title-bar')
?.classList.toggle('radio-broadcasting', state.audioState === 'playing');
this._radioPanel.classList.toggle('radio-enabled', enabled);
this._radioPanel.classList.toggle('lifecycle-uncertain', uncertain);
this._radioLayerState?.classList.toggle('active', enabled);
const lifecycleLabel =
lifecycleState === 'enabling' ? t('ENABLING') : t('DISABLING');
if (this._radioLayerState) {
this._radioLayerState.textContent = transitioning
? lifecycleLabel
: uncertain
? t('UNCERTAIN')
: state.loading
? t('SYNC')
: enabled
? `${state.filteredCount}/${state.stationCount}`
: t('OFF');
}
const layerStateText = transitioning
? lifecycleLabel
: uncertain
? t('UNCERTAIN')
: state.loading
? t('SYNC')
: enabled
? `${state.filteredCount}/${state.stationCount}`
: t('OFF');
const enableLabel = uncertain
? t('RECONCILE')
: enabled
@@ -52,89 +52,53 @@ export function renderRadioState(state) {
: enabled
? t('Disable Radio')
: t('Enable Radio');
if (this._radioEnableBtn) {
this._radioEnableBtn.classList.toggle('active', enabled);
this._radioEnableBtn.setAttribute('aria-pressed', String(enabled));
this._radioEnableBtn.textContent = transitioning
? lifecycleLabel
: enableLabel;
this._radioEnableBtn.setAttribute('aria-label', enableAria);
this._radioEnableBtn.disabled = false;
this._radioEnableBtn.setAttribute('aria-disabled', String(transitioning));
this._radioEnableBtn.setAttribute('aria-busy', String(transitioning));
}
if (this._cockpitRadioEnableBtn) {
this._cockpitRadioEnableBtn.classList.toggle('active', enabled);
this._cockpitRadioEnableBtn.setAttribute('aria-pressed', String(enabled));
this._cockpitRadioEnableBtn.textContent = transitioning
? lifecycleLabel
: enableLabel;
this._cockpitRadioEnableBtn.setAttribute('aria-label', enableAria);
this._cockpitRadioEnableBtn.disabled = false;
this._cockpitRadioEnableBtn.setAttribute(
'aria-disabled',
String(transitioning),
);
this._cockpitRadioEnableBtn.setAttribute(
'aria-busy',
String(transitioning),
);
}
if (this._radioFilter) {
const prior = state.filter || 'all';
const categorySignature = state.categories
.map((category) => `${category.id}:${category.count}:${category.color}`)
.join('|');
if (categorySignature !== this._radioCategorySignature) {
this._radioFilter.replaceChildren(
...state.categories.map((category) => {
const option = document.createElement('option');
option.value = category.id;
const label = t('{category} ({count})', {
category: category.label,
count: category.count,
});
option.textContent = `● ${label}`;
option.dataset.radioColor = category.color;
option.style.color = category.color;
option.setAttribute('aria-label', label);
return option;
}),
);
this._radioCategorySignature = categorySignature;
}
this._radioFilter.value = prior;
const activeCategory = state.categories.find(
(category) => category.id === prior,
);
this._radioFilter.style.color = activeCategory?.color || '';
this._radioFilter.disabled = !interactive || !state.stationCount;
const filter = state.filter || 'all';
const categories = state.categories || [];
// The options change only with the categories; until they first do, the
// markup's own option stands.
const categorySignature = categories
.map(
(category) =>
`${category.id}:${category.label}:${category.count}:${category.color}`,
)
.join('|');
if (categorySignature !== (this._radioCategorySignature ?? '')) {
this._radioCategorySignature = categorySignature;
this._radioFilterOptions = categories.map((category) => ({
id: category.id,
color: category.color,
label: t('{category} ({count})', {
category: category.label,
count: category.count,
}),
}));
}
const filterColor =
categories.find((category) => category.id === filter)?.color || '';
const tunerAvailable = interactive && state.filteredCount > 0;
if (this._radioTuner) this._radioTuner.hidden = !tunerAvailable;
if (this._radioTunerSlider) this._radioTunerSlider.disabled = !tunerAvailable;
if (this._radioTunerBandLabel) {
const activeCategory = state.categories.find(
(category) => category.id === state.filter,
);
this._radioTunerBandLabel.textContent =
const activeCategory = categories.find(
(category) => category.id === state.filter,
);
showRadioTuner.call(this, {
available: tunerAvailable,
band:
state.filter === 'all'
? t('DIRECTORY BAND')
: t('{category} BAND', {
category: String(
activeCategory?.label || state.filter,
).toUpperCase(),
});
}
this._radioTuner?.classList.toggle('is-static', Boolean(state.tuningStatic));
}),
static: Boolean(state.tuningStatic),
});
if (tunerAvailable) this._refreshRadioTunerBand?.();
if (!tunerAvailable && this._radioTunerDragging) {
this._radioTunerDragging = false;
this._radioTunerDragSnapshot = null;
this._radioTunerStations = [];
this._radioTuner?.classList.remove('is-static', 'is-dragging');
showRadioTuner.call(this, { static: false, dragging: false });
}
if (!tunerAvailable) {
this._radioTunerStations = [];
@@ -143,46 +107,22 @@ export function renderRadioState(state) {
this._radioTunerSelectedId = null;
}
if (this._radioStationName)
this._radioStationName.textContent =
selected?.name || t('NO STATION SELECTED');
if (this._radioStationMeta) {
const place = selected
? [selected.state, selected.countryCode].filter(Boolean).join(' · ')
: '';
const signal = selected
? [selected.codec, selected.bitrate ? `${selected.bitrate} kbps` : '']
.filter(Boolean)
.join(' · ')
: '';
this._radioStationMeta.textContent = selected
? [place, signal].filter(Boolean).join(' / ') ||
t('Directory metadata only')
: state.loading
? t('Loading station directory…')
: t('Choose a globe marker or use next.');
}
if (this._radioStationTags) {
const tags = Array.isArray(selected?.tags) ? selected.tags.slice(0, 8) : [];
this._radioStationTags.textContent = tags.length
? t('TAGS · {tags}', { tags: tags.join(' · ') })
: '';
}
if (this._radioStationHomepage) {
const homepage = selected?.homepage || '';
this._radioStationHomepage.hidden = !homepage;
if (homepage) this._radioStationHomepage.href = homepage;
else this._radioStationHomepage.removeAttribute('href');
}
const place = selected
? [selected.state, selected.countryCode].filter(Boolean).join(' · ')
: '';
const signal = selected
? [selected.codec, selected.bitrate ? `${selected.bitrate} kbps` : '']
.filter(Boolean)
.join(' · ')
: '';
const stationMeta = selected
? [place, signal].filter(Boolean).join(' / ') ||
t('Directory metadata only')
: state.loading
? t('Loading station directory…')
: t('Choose a globe marker or use next.');
const tags = Array.isArray(selected?.tags) ? selected.tags.slice(0, 8) : [];
if (this._radioPrevBtn)
this._radioPrevBtn.disabled = !interactive || !hasStations;
if (this._radioNextBtn)
this._radioNextBtn.disabled = !interactive || !hasStations;
if (this._cockpitRadioPrevBtn)
this._cockpitRadioPrevBtn.disabled = !interactive || !hasStations;
if (this._cockpitRadioNextBtn)
this._cockpitRadioNextBtn.disabled = !interactive || !hasStations;
const playbackAction = activePlayback
? t('Pause')
: state.audioState === 'paused'
@@ -199,45 +139,14 @@ export function renderRadioState(state) {
action: playbackAction,
target: playTargetWord,
});
if (this._radioPlayBtn) {
this._radioPlayBtn.disabled = !interactive || !hasStations;
this._radioPlayBtn.classList.toggle('active', activePlayback);
this._radioPlayBtn.textContent = playbackButtonLabel;
this._radioPlayBtn.setAttribute('aria-label', playAria);
}
if (this._cockpitRadioPlayBtn) {
this._cockpitRadioPlayBtn.disabled = !interactive || !hasStations;
this._cockpitRadioPlayBtn.classList.toggle('active', activePlayback);
this._cockpitRadioPlayBtn.textContent = activePlayback ? 'Ⅱ' : '▶';
this._cockpitRadioPlayBtn.setAttribute('aria-label', playAria);
this._cockpitRadioPlayBtn.title = playbackAction;
}
if (this._radioStopBtn)
this._radioStopBtn.disabled =
!interactive || state.audioState === 'stopped';
if (this._radioVolume) this._radioVolume.disabled = !interactive;
if (this._radioVolume && document.activeElement !== this._radioVolume) {
this._radioVolume.value = String(Math.round(state.volume * 100));
if (this._radioVolumeValue)
this._radioVolumeValue.textContent = `${Math.round(state.volume * 100)}%`;
}
if (
this._cockpitRadioVolume &&
document.activeElement !== this._cockpitRadioVolume
) {
this._cockpitRadioVolume.value = String(Math.round(state.volume * 100));
}
if (this._cockpitRadioVolume)
this._cockpitRadioVolume.disabled = !interactive;
if (this._cockpitRadioVolumeValue) {
this._cockpitRadioVolumeValue.textContent = `${Math.round(state.volume * 100)}%`;
}
if (this._cockpitRadioStation) {
this._cockpitRadioStation.textContent = uncertain
? t('UNCERTAIN')
: selected?.name || (state.loading ? t('SYNCING') : t('READY'));
}
if (this._radioPlaybackState) {
// A slider the person is dragging keeps the value they are setting.
this._radioVolumeShown =
this._radioVolume && document.activeElement === this._radioVolume
? Number(this._radioVolume.value)
: Math.round(state.volume * 100);
let playbackText = '';
let playbackError = false;
{
const stationName = selected?.name || t('station');
const catalogSuffix = state.degraded
? state.stale
@@ -286,17 +195,65 @@ export function renderRadioState(state) {
: null;
// Directory errors are msg() literals from the radio layer's ingestion.
const directoryError = state.error ? t(state.error) : null;
this._radioPlaybackState.textContent = `${uncertainMessage || unavailable || lifecycleMessage || directoryError || messages[state.audioState] || t('Ready')}${tuningSuffix}${voiceSuffix}${catalogSuffix}${outsideFilter}`;
this._radioPlaybackState.classList.toggle(
'error',
Boolean(
uncertainMessage ||
unavailable ||
state.error ||
state.audioState === 'error',
),
playbackText = `${uncertainMessage || unavailable || lifecycleMessage || directoryError || messages[state.audioState] || t('Ready')}${tuningSuffix}${voiceSuffix}${catalogSuffix}${outsideFilter}`;
playbackError = Boolean(
uncertainMessage ||
unavailable ||
state.error ||
state.audioState === 'error',
);
}
const enable = {
active: enabled,
text: transitioning ? lifecycleLabel : enableLabel,
label: enableAria,
busy: transitioning,
};
this._radioView = {
enabled,
uncertain,
layerState: { active: enabled, text: layerStateText },
enable,
filter: {
options: this._radioFilterOptions ?? null,
value: filter,
color: filterColor,
disabled: !interactive || !state.stationCount,
},
station: {
name: selected?.name || t('NO STATION SELECTED'),
meta: stationMeta,
tags: tags.length ? t('TAGS · {tags}', { tags: tags.join(' · ') }) : '',
homepage: selected?.homepage || '',
},
transport: {
stepDisabled: !interactive || !hasStations,
play: {
disabled: !interactive || !hasStations,
active: activePlayback,
text: playbackButtonLabel,
label: playAria,
},
stopDisabled: !interactive || state.audioState === 'stopped',
},
volume: { disabled: !interactive, value: this._radioVolumeShown },
playback: { text: playbackText, error: playbackError },
// The Cockpit's compact controls: a glyph transport and the layer's own
// volume, which only a focused slider holds back.
cockpit: {
station: uncertain
? t('UNCERTAIN')
: selected?.name || (state.loading ? t('SYNCING') : t('READY')),
enable: { ...enable },
// The rest of the transport is the panel's; the glyphs are the Cockpit's.
play: { glyph: activePlayback ? 'Ⅱ' : '▶', title: playbackAction },
volume: {
disabled: !interactive,
value: Math.round(state.volume * 100),
},
},
};
this.store?.publish(this._radioView);
if (
!enabled &&
!transitioning &&
@@ -307,3 +264,74 @@ export function renderRadioState(state) {
}
this.actions.scheduleLayout();
}
/**
* Show the volume the person is setting, on either slider, before the layer
* reports it.
* @param {number} value Percent, as the slider holds it.
*/
export function showRadioVolume(value) {
this._radioVolumeShown = value;
if (!this._radioView) return;
const { volume, cockpit } = this._radioView;
this._radioView = {
...this._radioView,
volume: { ...volume, value },
cockpit: { ...cockpit, volume: { ...cockpit.volume, value } },
};
this.store?.publish(this._radioView);
}
/** The tuner before RadioControls presents it; null texts keep the markup's. */
export function createRadioTunerState() {
return {
available: false,
band: null,
value: null,
station: null,
valuetext: null,
// The slider's range and value.
max: 0,
slot: 0,
// The needle's place across the dial, 0–1; null before the first preview.
ratio: null,
// The tick tape: the fractional station under the needle, and how many.
coordinate: 0,
count: 0,
static: false,
dragging: false,
};
}
/**
* Change what the tuner shows and publish it.
* @param {Partial<ReturnType<typeof createRadioTunerState>>} changes
*/
export function showRadioTuner(changes) {
this._radioTunerView = { ...this._radioTunerView, ...changes };
this.store?.publishTuner({ ...this._radioTunerView });
}
/**
* Mark an Enable button busy while its own toggle runs, as a render would
* until the next one reports the lifecycle.
* @param {boolean} busy
* @param {'panel'|'cockpit'} [where] The panel's button or the Cockpit's.
* @returns {boolean} False before the first render, when nothing is shown yet.
*/
export function showRadioEnableBusy(busy, where = 'panel') {
if (!this._radioView) return false;
const view = this._radioView;
this._radioView =
where === 'cockpit'
? {
...view,
cockpit: {
...view.cockpit,
enable: { ...view.cockpit.enable, busy },
},
}
: { ...view, enable: { ...view.enable, busy } };
this.store?.publish(this._radioView);
return true;
}