Reset load button labels and retain last result on a status preset
This commit is contained in:
parent
eb14255759
commit
53af775d5a
|
|
@ -148,13 +148,29 @@ is not proof that the output was silent or that no frames played.
|
|||
5. Only then restore the original mute setting and confirm it. A player that
|
||||
started muted stays muted.
|
||||
|
||||
Each button shows **LOADING**, **LOADED**, or **FAILED**, followed by **NEXT** or
|
||||
**PREV**, following the main player. `load_next_status` / `load_next_detail` and
|
||||
`load_previous_status` / `load_previous_detail` expose their respective results;
|
||||
add `backup_` for the corresponding backup variables. Starting one direction
|
||||
resets the other direction's displayed result to idle to avoid stale success.
|
||||
Each targeted player runs independently. The default target is Both; no backup
|
||||
is required. Main success does not imply backup success—check backup/sync status.
|
||||
Each navigation button shows **LOADING**, then **LOADED** or **FAILED** with
|
||||
**NEXT** or **PREV**. Two seconds after completion it returns to **LOAD NEXT** or
|
||||
**LOAD PREV** (with its arrow icon). This display reset does not send a command
|
||||
or erase the result. Offline still overrides the navigation buttons.
|
||||
|
||||
Add the passive **Last load result** preset from **Experimental** for a retained
|
||||
record. It shows **NO LOAD YET** initially, amber **LOADING**, blue **LAST LOADED**,
|
||||
or red **LAST FAILED**, with the direction. The latest result stays until the
|
||||
next load attempt, even after Play, Stop, a file change, or a disconnect. This is
|
||||
**history, not confirmation that the player is still stopped or connected**.
|
||||
Connection reconfiguration or module restart resets it. Pressing it does nothing.
|
||||
|
||||
`load_result_status`, `load_result_direction`, `load_result_file`, and
|
||||
`load_result_detail` expose the retained result; add `backup_` for the backup.
|
||||
The filename is recorded on success; failure details explain the problem.
|
||||
`load_next_status` / `load_next_detail` and `load_previous_status` /
|
||||
`load_previous_detail` retain their existing operation/current-state behavior.
|
||||
Starting one direction resets the other direction's result to idle. These
|
||||
variables are not subject to the two-second button-display reset.
|
||||
|
||||
The presets follow the main player. Each targeted player runs independently.
|
||||
The default target is Both; no backup is required. Main success does not imply
|
||||
backup success—check backup/sync status and the backup result variables.
|
||||
|
||||
Repeated presses while running, including the opposite direction, are coalesced;
|
||||
they do not queue another navigation. Other module commands are ignored
|
||||
|
|
|
|||
|
|
@ -54,6 +54,18 @@ is based on reported state, not proof of silent or seamless preload.
|
|||
Test on non-live output and read the README's experimental section before use.
|
||||
Re-add existing copied presets to remove the EXP label; linked presets update.
|
||||
|
||||
### Load status display
|
||||
|
||||
Load previous/next show their result for two seconds, then return to their normal
|
||||
labels. Add **Last load result** from **Experimental** to keep the latest result:
|
||||
neutral **NO LOAD YET**, amber **LOADING**, blue **LAST LOADED**, or red **LAST FAILED**,
|
||||
with NEXT/PREV. This passive button keeps the result until the next load attempt,
|
||||
even after playback changes or disconnection. It records history, not current
|
||||
player readiness. Reconfiguration/restart clears it.
|
||||
|
||||
Use `load_result_status`, `load_result_direction`, `load_result_file`, and
|
||||
`load_result_detail` for details; backup equivalents have a `backup_` prefix.
|
||||
|
||||
## Optional backup
|
||||
|
||||
Configure a backup host and port to send commands to both players. Leave the host
|
||||
|
|
|
|||
|
|
@ -78,6 +78,13 @@ export function presets(label = 'MPC_DEV') {
|
|||
steps: [{ down: [], up: [] }],
|
||||
feedbacks: [{ feedbackId: 'redundancy', options: {} }],
|
||||
},
|
||||
transport_load_result: {
|
||||
type: 'simple',
|
||||
name: 'Last load result',
|
||||
style: { text: 'NO LOAD\nYET', size: 12, color: colors.white, bgcolor: colors.dark, show_topbar: true },
|
||||
steps: [{ down: [], up: [] }],
|
||||
feedbacks: [{ feedbackId: 'load_result', options: {} }],
|
||||
},
|
||||
transport_load_next: button(
|
||||
'Load next',
|
||||
'↦\nLOAD\nNEXT',
|
||||
|
|
@ -155,7 +162,11 @@ export function presetSections(buttons) {
|
|||
(id) => id.startsWith('transport_') && !id.startsWith('transport_load_'),
|
||||
),
|
||||
},
|
||||
{ id: 'experimental', name: 'Experimental', definitions: ['transport_load_previous', 'transport_load_next'] },
|
||||
{
|
||||
id: 'experimental',
|
||||
name: 'Experimental',
|
||||
definitions: ['transport_load_previous', 'transport_load_next', 'transport_load_result'],
|
||||
},
|
||||
{ id: 'commands', name: 'All commands', definitions: Object.keys(commands) },
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ export function transportBorder(state, image, control) {
|
|||
}
|
||||
}
|
||||
|
||||
export function feedbacks(getState, getSync = () => null, getLoadStatus = () => 'idle') {
|
||||
export function feedbacks(getState, getSync = () => null, getLoadStatus = () => 'idle', getLoadResult = () => null) {
|
||||
const boolean = (name, callback, color) => ({
|
||||
type: 'boolean',
|
||||
name,
|
||||
|
|
@ -107,6 +107,26 @@ export function feedbacks(getState, getSync = () => null, getLoadStatus = () =>
|
|||
},
|
||||
]),
|
||||
),
|
||||
load_result: {
|
||||
type: 'advanced',
|
||||
name: 'Last load result (retained)',
|
||||
options: [],
|
||||
affectedProperties: ['text', 'bgcolor', 'color'],
|
||||
callback: () => {
|
||||
const result = getLoadResult()
|
||||
const direction = result?.direction === 'previous' ? 'PREV' : 'NEXT'
|
||||
return {
|
||||
text:
|
||||
{
|
||||
loading: `LOADING\n${direction}`,
|
||||
ready: `LAST\nLOADED\n${direction}`,
|
||||
failed: `LAST\nFAILED\n${direction}`,
|
||||
}[result?.status] ?? 'NO LOAD\nYET',
|
||||
bgcolor: { loading: colors.amber, ready: colors.blue, failed: colors.red }[result?.status] ?? colors.dark,
|
||||
color: result?.status === 'loading' ? colors.dark : colors.white,
|
||||
}
|
||||
},
|
||||
},
|
||||
in_sync: boolean('Backup in sync with main', () => getSync()?.status === 'in_sync', colors.green),
|
||||
out_of_sync: boolean('Backup out of sync with main', () => getSync()?.status === 'out_of_sync', colors.red),
|
||||
redundancy: {
|
||||
|
|
|
|||
|
|
@ -21,12 +21,21 @@ export default class MpcInstance extends InstanceBase {
|
|||
feedbacks(
|
||||
() => this.state,
|
||||
() => this.sync,
|
||||
(direction = 'next') => (this.main?.loadDirection === direction ? this.main.loadStatus : 'idle'),
|
||||
(direction = 'next') => (this.main?.loadDirection === direction ? this.main.loadDisplayStatus : 'idle'),
|
||||
() => this.main?.loadResult,
|
||||
),
|
||||
)
|
||||
this.setVariableDefinitions({
|
||||
...variableDefinitions,
|
||||
...redundancyDefinitions,
|
||||
...Object.fromEntries(
|
||||
['', 'backup_'].flatMap((prefix) =>
|
||||
['status', 'direction', 'file', 'detail'].map((field) => [
|
||||
`${prefix}load_result_${field}`,
|
||||
{ name: `${prefix ? 'Backup' : 'Main'} last load result: ${field} (retained until next attempt)` },
|
||||
]),
|
||||
),
|
||||
),
|
||||
load_previous_status: { name: 'Main experimental Load previous: idle, loading, ready, failed' },
|
||||
load_previous_detail: { name: 'Main experimental Load previous result' },
|
||||
backup_load_previous_status: { name: 'Backup experimental Load previous status' },
|
||||
|
|
@ -44,6 +53,17 @@ export default class MpcInstance extends InstanceBase {
|
|||
this.sync = comparePlayers(this.main, this.backup, this.syncOptions)
|
||||
this.setVariableValues({
|
||||
...variables(this.state),
|
||||
...Object.fromEntries(
|
||||
[
|
||||
[this.main, ''],
|
||||
[this.backup, 'backup_'],
|
||||
].flatMap(([player, prefix]) =>
|
||||
['status', 'direction', 'file', 'detail'].map((field) => [
|
||||
`${prefix}load_result_${field}`,
|
||||
player?.loadResult?.[field] ?? (field === 'status' ? 'idle' : ''),
|
||||
]),
|
||||
),
|
||||
),
|
||||
...Object.fromEntries(
|
||||
['next', 'previous'].flatMap((direction) => {
|
||||
const values = (player, prefix, absent) => [
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ export class Player {
|
|||
this.loadDirection = 'next'
|
||||
this.loadStatus = 'idle'
|
||||
this.loadDetail = ''
|
||||
this.loadDisplayStatus = 'idle'
|
||||
this.loadResult = { status: 'idle', direction: '', file: '', detail: '' }
|
||||
}
|
||||
|
||||
refresh() {
|
||||
|
|
@ -67,6 +69,9 @@ export class Player {
|
|||
if (!this.active) return Promise.resolve()
|
||||
if (this.loading) return this.loading
|
||||
this.loading = (async () => {
|
||||
clearTimeout(this.loadDisplayTimer)
|
||||
this.loadDisplayStatus = 'loading'
|
||||
this.loadResult = { status: 'loading', direction, file: '', detail: '' }
|
||||
this.loadDirection = direction
|
||||
this.loadStatus = 'loading'
|
||||
this.loadDetail = `Muting, selecting ${direction} once, and confirming stopped`
|
||||
|
|
@ -83,7 +88,20 @@ export class Player {
|
|||
this.loadDetail = error.message
|
||||
} finally {
|
||||
this.loading = undefined
|
||||
if (this.active) this.changed(this)
|
||||
if (this.active) {
|
||||
this.loadDisplayStatus = this.loadStatus
|
||||
this.loadResult = {
|
||||
status: this.loadStatus,
|
||||
direction,
|
||||
file: this.loadStatus === 'ready' ? this.loadedFile : '',
|
||||
detail: this.loadDetail,
|
||||
}
|
||||
this.loadDisplayTimer = setTimeout(() => {
|
||||
this.loadDisplayStatus = 'idle'
|
||||
if (this.active) this.changed(this)
|
||||
}, 2000)
|
||||
this.changed(this)
|
||||
}
|
||||
}
|
||||
})()
|
||||
return this.loading
|
||||
|
|
@ -110,6 +128,7 @@ export class Player {
|
|||
close() {
|
||||
this.active = false
|
||||
clearTimeout(this.timer)
|
||||
clearTimeout(this.loadDisplayTimer)
|
||||
this.client.close()
|
||||
this.state = null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,5 +188,26 @@ for (const direction of ['next', 'previous']) {
|
|||
state.feedbacks[`load_${direction}_status`].callback().text,
|
||||
direction === 'next' ? '↦\nLOADED\nNEXT' : '↤\nLOADED\nPREV',
|
||||
)
|
||||
assert.deepEqual(state.presets.transport_load_result.steps[0].down, [])
|
||||
await new Promise((resolve) => setTimeout(resolve, 2100))
|
||||
assert.equal(
|
||||
state.feedbacks[`load_${direction}_status`].callback().text,
|
||||
direction === 'next' ? '↦\nLOAD\nNEXT' : '↤\nLOAD\nPREV',
|
||||
)
|
||||
assert.equal(module.backup.loadDisplayStatus, 'idle')
|
||||
assert.equal(state.variables.backup_load_result_status, 'failed')
|
||||
assert.equal(state.variables.load_result_status, 'ready')
|
||||
assert.equal(state.variables.load_result_direction, direction)
|
||||
assert.equal(state.variables.load_result_file, 'Next.mp4')
|
||||
const resultText = direction === 'next' ? 'LAST\nLOADED\nNEXT' : 'LAST\nLOADED\nPREV'
|
||||
assert.equal(state.feedbacks.load_result.callback().text, resultText)
|
||||
data.state = 2
|
||||
await module.refresh()
|
||||
assert.equal(state.variables[`load_${direction}_status`], 'idle')
|
||||
assert.equal(state.feedbacks.load_result.callback().text, resultText)
|
||||
data.volume = null
|
||||
await module.refresh()
|
||||
assert.equal(state.variables.state, 'offline')
|
||||
assert.equal(state.feedbacks.load_result.callback().text, resultText)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue