diff --git a/web/src/sections/dashboard.test.ts b/web/src/sections/dashboard.test.ts index 8203764..e152d31 100644 --- a/web/src/sections/dashboard.test.ts +++ b/web/src/sections/dashboard.test.ts @@ -41,7 +41,8 @@ const show = (over: Record = {}) => { mount(PAGE) return mock } -const fact = (label: string) => screen.getByText(label, { selector: 'dt' }).nextElementSibling as HTMLElement +// A fact's term is a glyph whose label is spoken (sr-only). +const fact = (label: string) => screen.getByText(label, { selector: 'dt .sr-only' }).closest('dt')?.nextElementSibling as HTMLElement const box = (name: string) => screen.getByRole('region', { name }) describe('Dashboard', () => { @@ -101,7 +102,8 @@ describe('Dashboard', () => { vi.setSystemTime(Date.parse('2026-10-23T11:07:58Z')) expect(fact('Total block')).toHaveTextContent('1h 8m left') vi.advanceTimersByTime(1000) - const first = Number(/^(\d)s left$/.exec(fact('Total block').textContent)?.[1]) + // Painted โณ + number; "left" is spoken (sr-only). + const first = Number(/^(\d)s left$/.exec(fact('Total block').querySelector('.sr-only')?.textContent ?? '')?.[1]) expect([3, 4]).toContain(first) vi.advanceTimersByTime(1000) expect(fact('Total block')).toHaveTextContent(`${first - 1}s left`) @@ -152,7 +154,7 @@ describe('Dashboard', () => { it('keeps a failed daemon run on screen with its reason', async () => { const failed = { ...bg3, phase: 'failed', percent: null, elapsed_seconds: 0, error: 'Refusing to mark it as installed' } show({ 'GET /api/daemon': daemon([failed]) }) - expect(await screen.findByText("Fast install of Baldur's Gate 3 failed: Refusing to mark it as installed")).toHaveClass('text-danger') + expect((await screen.findByText("Fast install of Baldur's Gate 3 failed: Refusing to mark it as installed")).closest('p')).toHaveClass('text-danger') expect(screen.getByText("Steam's own download took over.")).toBeInTheDocument() expect(screen.queryByRole('progressbar', { name: "Baldur's Gate 3 download" })).not.toBeInTheDocument() }) diff --git a/web/src/sections/dashboard.ts b/web/src/sections/dashboard.ts index 44596b1..331ba6c 100644 --- a/web/src/sections/dashboard.ts +++ b/web/src/sections/dashboard.ts @@ -1,17 +1,26 @@ // Dashboard sections (was screens/Dashboard.tsx): what the enforcer is doing -// right now, at a glance. +// right now, at a glance. Textgate: glyphs and numbers are painted, every +// sentence is spoken only (sr-only), game names stay visible as content. import type { FastInstallRun, StatusPayload } from '../api/contract' import { q } from '../api/queries' -import { commandLabel } from '../commands/catalog' +import { COMMAND_ICON, commandLabel } from '../commands/catalog' import '../commands/commandButton' import { fmtDuration, fmtRemaining } from '../format' import { progressBar, stateBadge, type BarTone } from '../jobs/progress' import { define, h, hx } from '../lib/dom' import { LiveElement } from '../lib/element' import { jobHref } from '../lib/runner' -import { card, empty, errorNotice, facts, link, loading } from '../ui/build' +import { card, empty, errorNotice, facts, glyph, link, loading } from '../ui/build' import { ago } from '../ui/format' +import { said } from './spoken' + +/** "5 min ago" painted as ๐Ÿ•“ 5 min (the word "ago" spoken only). */ +export function since(iso: string | null): HTMLSpanElement { + const spoken = ago(iso) + const short = spoken === 'just now' ? '<1 min' : spoken.replace(/ ago$/, '') + return said(spoken, '๐Ÿ•“ ', short) +} /** Seconds left on the total block: from `until` when known, else the * server's `days_remaining` (rounded to 0.1 d). */ @@ -29,18 +38,29 @@ export class BlockCountdownElement extends LiveElement { protected update(): void { const block = q.status.state.data?.total_block - this.replaceChildren(...(block ? [h('span', { class: 'text-danger' }, `${fmtRemaining(blockSecondsLeft(block))} left`)] : [])) + if (!block) { + this.replaceChildren() + return + } + const left = fmtRemaining(blockSecondsLeft(block)) + this.replaceChildren(h('span', { class: 'text-danger' }, said(`${left} left`, 'โณ ', left))) } } function statusFacts(s: StatusPayload): HTMLDListElement { return facts([ - ['Installed', s.assigned_game_installed ? 'Yes' : h('span', { class: 'text-warning' }, 'No โ€” install it from Library')], - ['Games finished', s.finished_count], - ['Store', s.store_blocked ? 'Blocked' : h('span', { class: 'text-warning' }, 'Unblocked')], - ['Installed games', s.installed_count], - ['Total block', s.total_block.active ? hx('block-countdown') : 'Off'], - ['Manual picks', s.manual_picks.length ? s.manual_picks.map((p) => `${p.name} (${p.age_days} d)`).join(', ') : 'None'], + [ + glyph('๐Ÿ’พ', 'Installed'), + s.assigned_game_installed ? glyph('โœ…', 'Yes') : h('span', { class: 'text-warning' }, glyph('โš ๏ธ', 'No โ€” install it from Library')), + ], + [glyph('๐Ÿ†', 'Games finished'), s.finished_count], + [glyph('๐Ÿ›’', 'Store'), s.store_blocked ? glyph('๐Ÿ”’', 'Blocked') : h('span', { class: 'text-warning' }, glyph('๐Ÿ”“', 'Unblocked'))], + [glyph('๐Ÿ—‚๏ธ', 'Installed games'), s.installed_count], + [glyph('โ›”', 'Total block'), s.total_block.active ? hx('block-countdown') : glyph('โž–', 'Off')], + [ + glyph('๐Ÿ“Œ', 'Manual picks'), + s.manual_picks.length ? s.manual_picks.map((p) => `${p.name} (${p.age_days} d)`).join(', ') : glyph('โž–', 'None'), + ], ]) } @@ -51,13 +71,16 @@ export class DashboardStatusElement extends LiveElement { protected update(): void { const { data, error } = q.status.state + const icon = '๐ŸŽฏ' if (error) { - this.replaceChildren(card('Assignment', errorNotice(error))) + this.replaceChildren(card('Assignment', errorNotice(error), { icon })) } else if (!data) { - this.replaceChildren(card('Assignment', loading('status'))) + this.replaceChildren(card('Assignment', loading('status'), { icon })) } else { + const game = data.current_game_name ?? glyph('๐Ÿ“ญ', 'Nothing assigned') this.replaceChildren( - card('Assignment', [h('p', { class: 'hero-game' }, data.current_game_name ?? 'Nothing assigned'), statusFacts(data)], { + card('Assignment', [h('p', { class: 'hero-game' }, game), statusFacts(data)], { + icon, // Its own element, so it follows the command catalog by itself. aside: hx('command-button', { name: 'check', label: 'Check now' }), }), @@ -71,6 +94,12 @@ function budgetTone(blocked: boolean, used: number): BarTone { return used > 0.8 ? 'warning' : 'accent' } +function billingLine(blocked: boolean, label: string): HTMLParagraphElement { + if (blocked) return h('p', { class: 'field-help' }, glyph('โ›”', 'Blocked for today.')) + if (!label) return h('p', { class: 'field-help' }, said('Now: nothing billing', 'โธ๏ธ')) + return h('p', { class: 'field-help' }, said(`Now: ${label}`, 'โ–ถ๏ธ ', label)) +} + export class BudgetGlanceElement extends LiveElement { protected override setup(): void { this.watch(q.budget) @@ -78,12 +107,13 @@ export class BudgetGlanceElement extends LiveElement { protected update(): void { const { data, error } = q.budget.state + const icon = 'โฑ๏ธ' if (error) { - this.replaceChildren(card('Gaming today', errorNotice(error))) + this.replaceChildren(card('Gaming today', errorNotice(error), { icon })) return } if (!data) { - this.replaceChildren(card('Gaming today', loading('budget'))) + this.replaceChildren(card('Gaming today', loading('budget'), { icon })) return } const t = data.today @@ -93,37 +123,35 @@ export class BudgetGlanceElement extends LiveElement { 'p', { class: 'hero-num' }, `${fmtDuration(t.seconds_remaining)} `, - h('span', { class: 'muted' }, `left of ${fmtDuration(t.budget_seconds)}`), + h('span', { class: 'muted' }, said(`left of ${fmtDuration(t.budget_seconds)}`, `/ ${fmtDuration(t.budget_seconds)}`)), ), progressBar(t.fraction_used, 'Budget used', budgetTone(t.blocked, t.fraction_used)), - h('p', { class: 'field-help' }, t.blocked ? 'Blocked for today.' : `Now: ${data.session.billing_label || 'nothing billing'}`), + billingLine(t.blocked, data.session.billing_label), ] - : h('p', { class: 'text-danger' }, data.error ?? 'Budget state unavailable.') - this.replaceChildren(card('Gaming today', body, { aside: link('/gaming/', 'Details') })) + : h('p', { class: 'text-danger' }, data.error ?? glyph('โš ๏ธ', 'Budget state unavailable.')) + this.replaceChildren(card('Gaming today', body, { icon, aside: link('/gaming/', glyph('โžก๏ธ', 'Details')) })) } } -function fastInstallLine(r: FastInstallRun): string { - const where = r.percent === null ? r.phase : `${Math.floor(r.percent)}% (${r.phase})` - return `Fast-installing ${r.name} โ€” ${where}` -} - function fastInstallRow(r: FastInstallRun): HTMLDivElement { if (r.error) { // The daemon has no job to report to: a failure stays here until Steam finishes. + // The error is the daemon's own message (content), the framing is spoken. return h( 'div', {}, - h('p', { class: 'text-danger' }, `Fast install of ${r.name} failed: ${r.error}`), - h('p', { class: 'field-help' }, "Steam's own download took over."), + h('p', { class: 'text-danger' }, said(`Fast install of ${r.name} failed: ${r.error}`, 'โ›” ', r.name, ': ', r.error)), + h('p', { class: 'field-help' }, glyph('โ†ช๏ธ', "Steam's own download took over.")), ) } + const pct = r.percent === null ? null : Math.floor(r.percent) + const where = pct === null ? r.phase : `${pct}% (${r.phase})` return h( 'div', {}, - h('p', {}, fastInstallLine(r)), - progressBar(r.percent === null ? null : Math.floor(r.percent) / 100, `${r.name} download`), - h('p', { class: 'field-help' }, `${fmtDuration(r.elapsed_seconds)} elapsed`), + h('p', {}, said(`Fast-installing ${r.name} โ€” ${where}`, 'โšก ', r.name, pct === null ? '' : ` ${pct}%`)), + progressBar(pct === null ? null : pct / 100, `${r.name} download`), + h('p', { class: 'field-help' }, said(`${fmtDuration(r.elapsed_seconds)} elapsed`, 'โณ ', fmtDuration(r.elapsed_seconds))), ) } @@ -135,7 +163,7 @@ export class FastInstallsElement extends LiveElement { protected update(): void { const runs = q.daemon.state.data?.fast_installs ?? [] - this.replaceChildren(...(runs.length ? [card('Fast install', runs.map(fastInstallRow))] : [])) + this.replaceChildren(...(runs.length ? [card('Fast install', runs.map(fastInstallRow), { icon: 'โšก' })] : [])) } } @@ -162,16 +190,18 @@ export class RecentJobsElement extends LiveElement { h( 'a', { href: jobHref(j.id), class: 'row-link' }, - h('span', {}, commandLabel(j.command)), - h('span', { class: 'muted grow ellipsis' }, j.summary ?? j.progress?.label ?? ''), - h('span', { class: 'muted' }, ago(j.created_at)), + glyph(COMMAND_ICON[j.command], commandLabel(j.command)), + // The job's summary is a server sentence: spoken here, shown in the job view. + h('span', { class: 'sr-only' }, j.summary ?? j.progress?.label ?? ''), + h('span', { class: 'grow' }), + h('span', { class: 'muted' }, since(j.created_at)), stateBadge(j.state), ), ), ), ), ], - { aside: link('/jobs/', 'All jobs') }, + { icon: 'โš™๏ธ', aside: link('/jobs/', glyph('โžก๏ธ', 'All jobs')) }, ), ) } diff --git a/web/src/sections/gaming/cards.test.ts b/web/src/sections/gaming/cards.test.ts index 5c75edb..b76aeea 100644 --- a/web/src/sections/gaming/cards.test.ts +++ b/web/src/sections/gaming/cards.test.ts @@ -74,7 +74,7 @@ describe('todayUnavailable', () => { describe('liveCard', () => { it('reports an engaged session with its game', () => { show(liveCard(makeBudgetSession())) - expect(screen.getByText(/Billing โ€” you are playing/)).toHaveClass('budget-verdict--engaged') + expect(screen.getByText(/Billing โ€” you are playing/).closest('.budget-verdict')).toHaveClass('budget-verdict--engaged') expect(screen.getByText(/Assigned game/)).toBeInTheDocument() // Engaged, so the credited game is described in the present tense. expect(screen.getByText(/Billing to/)).toBeInTheDocument() diff --git a/web/src/sections/gaming/cards.ts b/web/src/sections/gaming/cards.ts index b241c26..c7dd4d0 100644 --- a/web/src/sections/gaming/cards.ts +++ b/web/src/sections/gaming/cards.ts @@ -1,11 +1,15 @@ // The four budget panel sections (were BudgetTodayCard, BudgetLiveCard, // BudgetHistoryChart and BudgetRulesCard.tsx) as pure DOM builders. +// Textgate: glyphs, numbers and game names are painted; every sentence and +// label is spoken only (`said`/`glyph`), and the meter/verdict colours stay. -import { seriesClass } from '../../budgetSeries' +import { OTHER_KEY, UNATTRIBUTED_KEY, seriesClass } from '../../budgetSeries' import { fmtAgo, fmtDuration } from '../../format' import { budgetHistorySvg } from '../../lib/charts/budgetHistory' import { h } from '../../lib/dom' import type { BudgetHistoryDay, BudgetLegendEntry, BudgetRules, BudgetSession, BudgetToday } from '../../types' +import { glyph } from '../../ui/build' +import { said } from '../spoken' /** Which colour the meter takes: normal, into the warning band, or spent. * @@ -19,7 +23,22 @@ function meterState(today: BudgetToday): string { return today.warned_seconds.length > 0 ? 'warn' : 'ok' } -function warningLine(today: BudgetToday, maskedCount: number): HTMLElement | string { +/** A series name: game names are content; the sentinels and the "(launcher)" tag are glyphs. */ +export function seriesLabel(key: string, label: string): HTMLElement { + if (key === OTHER_KEY) return glyph('โž•', label) + if (key === UNATTRIBUTED_KEY) return glyph('โ”', label) + if (key.startsWith('launcher:')) return said(label, '๐Ÿš€ ', label.replace(/\s*\(launcher\)$/, '')) + return h('span', {}, label) +} + +/** "5m ago" painted as ๐Ÿ•“ 5m. */ +function asOf(iso: string): HTMLElement { + const ago = fmtAgo(iso) + const short = ago === 'unknown' ? '?' : ago === 'just now' ? '<10s' : ago.replace(/ ago$/, '') + return said(`as of ${ago}`, '๐Ÿ•“ ', short) +} + +function warningLine(today: BudgetToday, maskedCount: number): HTMLElement { if (today.blocked) { // Read the live mount count rather than inferring it from `blocked`: the // total-block branch releases every mount while leaving `blocked_at` set, @@ -28,12 +47,23 @@ function warningLine(today: BudgetToday, maskedCount: number): HTMLElement | str return h( 'span', { class: 'budget-badge budget-badge--blocked' }, - maskedCount > 0 ? 'Cutoff engaged โ€” launchers are masked' : 'Cutoff engaged โ€” launchers are not currently masked', + maskedCount > 0 + ? glyph('โ›”๐Ÿ”’', 'Cutoff engaged โ€” launchers are masked') + : glyph('โ›”๐Ÿ”“', 'Cutoff engaged โ€” launchers are not currently masked'), ) } - return today.next_warning_seconds === null - ? 'No further warnings today.' - : `Next warning at ${fmtDuration(today.next_warning_seconds)} remaining.` + const next = today.next_warning_seconds + return next === null + ? glyph('๐Ÿ”•', 'No further warnings today.') + : said(`Next warning at ${fmtDuration(next)} remaining.`, '๐Ÿ”” ', fmtDuration(next)) +} + +function usageLine(t: BudgetToday): HTMLElement { + const used = `${fmtDuration(t.seconds_used)} / ${fmtDuration(t.budget_seconds)} ยท ${Math.round(t.fraction_used * 100)}%` + const spoken = + `${fmtDuration(t.seconds_used)} of ${fmtDuration(t.budget_seconds)} used ยท ` + + `${Math.round(t.fraction_used * 100)}% ยท gaming day ${t.gaming_day} (starts ${t.day_starts_at})` + return said(spoken, used, ' ยท ๐Ÿ“… ', t.gaming_day, ' ยท ๐ŸŒ… ', t.day_starts_at.replace(/\s*local$/, '')) } export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry[], maskedCount: number): HTMLElement { @@ -46,19 +76,14 @@ export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry return h( 'section', { class: 'budget-today' }, - h('h2', {}, 'Today'), - h('p', { class: 'budget-hero' }, h('strong', {}, fmtDuration(today.seconds_remaining)), ' left'), + h('h2', {}, glyph('๐Ÿ“…', 'Today')), + h('p', { class: 'budget-hero' }, h('strong', {}, fmtDuration(today.seconds_remaining)), h('span', { class: 'sr-only' }, ' left')), h('div', { class: `budget-meter budget-meter--${meterState(today)}` }, fill), - h( - 'p', - { class: 'hint' }, - `${fmtDuration(today.seconds_used)} of ${fmtDuration(today.budget_seconds)} used ยท ` + - `${Math.round(today.fraction_used * 100)}% ยท gaming day ${today.gaming_day} (starts ${today.day_starts_at})`, - ), + h('p', { class: 'hint' }, usageLine(today)), h('p', { class: 'hint' }, warningLine(today, maskedCount)), today.games.length > 0 ? [ - h('h3', { class: 'budget-subhead' }, 'Today by game'), + h('h3', { class: 'budget-subhead' }, glyph('๐ŸŽฎ', 'Today by game')), h( 'ul', { class: 'budget-games' }, @@ -67,7 +92,7 @@ export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry 'li', {}, h('span', { class: `swatch ${seriesClass(game.key, indexFor.get(game.key) ?? i)}`, 'aria-hidden': 'true' }), - h('span', { class: 'budget-game-name' }, game.label), + h('span', { class: 'budget-game-name' }, seriesLabel(game.key, game.label)), h('span', { class: 'budget-game-time' }, fmtDuration(game.seconds)), h('span', { class: 'budget-game-share' }, `${Math.round(game.fraction * 100)}%`), ), @@ -80,34 +105,37 @@ export function todayCard(today: BudgetToday, legend: readonly BudgetLegendEntry /** Shown in place of `todayCard` when the state file cannot be read. */ export function todayUnavailable(error: string | null): HTMLElement { - return h('section', { class: 'budget-today' }, h('h2', {}, 'Today'), h('p', { class: 'error' }, error ?? 'Budget state unavailable.')) + return h( + 'section', + { class: 'budget-today' }, + h('h2', {}, glyph('๐Ÿ“…', 'Today')), + // The server's own error is shown as is; the fallback is a glyph. + h('p', { class: 'error' }, error ?? glyph('โš ๏ธ', 'Budget state unavailable.')), + ) } -const VERDICT_LABELS = new Map([ - ['engaged', 'Billing โ€” you are playing'], - ['not_applicable', 'Not billing โ€” no game running'], +const VERDICT = new Map([ + ['engaged', ['โ–ถ๏ธ', 'Billing โ€” you are playing']], + ['not_applicable', ['โธ๏ธ', 'Not billing โ€” no game running']], ]) export function liveCard(session: BudgetSession): HTMLElement { - const title = h('h2', {}, 'Right now') + const title = h('h2', {}, glyph('๐Ÿ“ก', 'Right now')) if (!session.available) { - return h('section', { class: 'budget-live' }, title, h('p', { class: 'hint' }, 'No verdict has been logged yet.')) + return h('section', { class: 'budget-live' }, title, h('p', { class: 'hint' }, glyph('๐Ÿ“ญ', 'No verdict has been logged yet.'))) } + const [icon, verdict] = VERDICT.get(session.state) ?? ['โ”', session.state] return h( 'section', { class: 'budget-live' }, title, - h( - 'p', - {}, - h('span', { class: `budget-verdict budget-verdict--${session.state}` }, VERDICT_LABELS.get(session.state) ?? session.state), - ), + h('p', {}, h('span', { class: `budget-verdict budget-verdict--${session.state}` }, glyph(icon, verdict))), session.qualifying_count > 0 ? h( 'p', { class: 'hint' }, - session.game_name ? ['Assigned game ', h('strong', {}, session.game_name), ' ยท '] : null, - `${session.qualifying_count} qualifying processes`, + session.game_name ? [said('Assigned game ', '๐ŸŽฏ '), h('strong', {}, session.game_name), ' ยท '] : null, + said(`${session.qualifying_count} qualifying processes`, 'โš™๏ธ ', session.qualifying_count), ) : null, // The assignment above is what the enforcer told you to play; this is @@ -118,24 +146,24 @@ export function liveCard(session: BudgetSession): HTMLElement { ? h( 'p', { class: 'hint' }, - session.state === 'engaged' ? 'Billing to ' : 'Last billed to ', + session.state === 'engaged' ? said('Billing to ', '๐Ÿ’ธ ') : said('Last billed to ', 'โฎ๏ธ๐Ÿ’ธ '), h('strong', {}, session.billing_label), ) : null, // The daemon logs on change or a 5-minute heartbeat, so this reading can // legitimately be minutes old. Saying so beats implying "now". - h('p', { class: 'hint' }, `as of ${fmtAgo(session.observed_at)}`), + h('p', { class: 'hint' }, asOf(session.observed_at)), ) } export function historyCard(days: readonly BudgetHistoryDay[], legend: readonly BudgetLegendEntry[], budgetSeconds: number): HTMLElement { - const title = h('h2', {}, 'Last 14 days') + const title = h('h2', {}, glyph('๐Ÿ“Š', 'Last 14 days')) if (days.length === 0) { return h( 'div', { class: 'chart' }, title, - h('p', { class: 'hint' }, 'No budget history recorded yet โ€” a bar appears for each gaming day from now on.'), + h('p', { class: 'hint' }, glyph('๐Ÿ“ญ', 'No budget history recorded yet โ€” a bar appears for each gaming day from now on.')), ) } // A