feat(ui): add download progress controls

Replace the downloading action button with a dedicated progress component in
both card and detail views. The card now shows percent plus current speed, while
the detail modal shows bytes, speed, ETA, percent, and an inline cancel affordance
using the same backend progress payload.

Expose download cancellation as a peer command that cancels the tracked transfer
token and lets the running operation clear the authoritative active-operation
snapshot. Add a View Files action that resolves the game root safely and opens it
with the platform file viewer through Tauri's shell plugin.

Test Plan:
- just fmt
- just frontend-test
- just test
- just build
- just clippy
- git diff --cached --check

Refs: design reference e308009a08
This commit is contained in:
2026-05-20 23:20:53 +02:00
parent e308009a08
commit 47e2bbd454
16 changed files with 776 additions and 48 deletions
@@ -1,6 +1,7 @@
import { CSSProperties, JSX, MouseEvent } from 'react';
import { JSX, MouseEvent } from 'react';
import { Icon } from './Icon';
import { DownloadProgress } from './DownloadProgress';
import { Game, InstallStatus } from '../lib/types';
import { actionLabel, primaryActionFor, PrimaryAction } from '../lib/gameState';
@@ -9,6 +10,7 @@ interface Props {
size?: 'md' | 'lg';
full?: boolean;
onClick: () => void;
onCancelDownload?: (game: Game) => void;
}
const ICON_FOR_ACTION: Partial<Record<PrimaryAction, JSX.Element>> = {
@@ -18,29 +20,34 @@ const ICON_FOR_ACTION: Partial<Record<PrimaryAction, JSX.Element>> = {
download: <Icon.download />,
};
const downloadProgressPercent = (game: Game): number | undefined => {
const progress = game.download_progress;
if (!progress || progress.total_bytes <= 0) return undefined;
return Math.max(0, Math.min(100, (progress.downloaded_bytes / progress.total_bytes) * 100));
};
/** Color-coded primary action: Play / Install / Update / Download / busy. */
export const ActionButton = ({ game, size = 'md', full = false, onClick }: Props) => {
export const ActionButton = ({
game,
size = 'md',
full = false,
onClick,
onCancelDownload,
}: Props) => {
const action = primaryActionFor(game);
const isDownloading = game.install_status === InstallStatus.Downloading;
const progressPercent = downloadProgressPercent(game);
if (isDownloading) {
return (
<DownloadProgress
game={game}
size={size}
full={full}
onCancel={size === 'lg' ? onCancelDownload : undefined}
/>
);
}
const cls = [
'act-btn',
`act-${action}`,
isDownloading ? 'act-downloading' : '',
size === 'lg' ? 'act-lg' : '',
full ? 'act-full' : '',
].filter(Boolean).join(' ');
const disabled = action === 'busy' || action === 'disabled';
const style = progressPercent === undefined
? undefined
: ({ '--download-progress': `${progressPercent}%` } as CSSProperties);
const handle = (e: MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
@@ -49,8 +56,7 @@ export const ActionButton = ({ game, size = 'md', full = false, onClick }: Props
};
return (
<button className={cls} onClick={handle} disabled={disabled} style={style}>
{isDownloading && <span className="act-progress-fill" aria-hidden />}
<button className={cls} onClick={handle} disabled={disabled}>
{ICON_FOR_ACTION[action]}
<span className="act-label">{actionLabel(game)}</span>
</button>