desktop: Game services card in App info (Game Center and Play Games Services status, ids, counts vs config, pending changes, sync buttons through the confirm-token write, PGS setup plan, console links); en + tr strings; dev fixture
This commit is contained in:
parent
26f0723641
commit
22286c7e02
6 changed files with 135 additions and 2 deletions
76
apps/desktop/src/ui/GameServicesCard.tsx
Normal file
76
apps/desktop/src/ui/GameServicesCard.tsx
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// Game services: Game Center (App Store) and Play Games Services (Google Play) side by side, from `games status --json`
|
||||
// (cli/games-status.ts): enabled, App ID capability, entitlement / APP_ID resource, ids, leaderboard and achievement
|
||||
// counts on the store vs the config, pending changes and findings. The sync buttons are the confirm-token writes
|
||||
// (dry run -> native dialog -> apply) of `apple game-center` and `play games`; the PGS setup is a console plan.
|
||||
import type { Project } from '../api';
|
||||
import { t } from '../i18n';
|
||||
import { useRead, useWrite } from '../store';
|
||||
import { ConsolePlanButton } from './ConsolePlan';
|
||||
import { StoreGlyph } from './icons';
|
||||
import { Card, Chip, ErrorNotice, Skeleton } from './kit';
|
||||
import { OpenLink } from './OpenLink';
|
||||
import { WriteButton } from './WriteButton';
|
||||
|
||||
interface Finding { store: 'apple' | 'play'; level: 'error' | 'warn' | 'ok'; id: string; msg: string; fix?: string }
|
||||
interface Counts { leaderboards: number; achievements: number }
|
||||
export interface GameServicesStatus {
|
||||
apple: null | { capability: boolean | null; enabled: boolean; version: string | null; versionEnabled: boolean | null; config: Counts; changes: string[]; error?: string } & Counts;
|
||||
play: null | { appId: string | null; resource: string | null; config: Counts; changes: string[]; error?: string } & Counts;
|
||||
findings: Finding[];
|
||||
links: { label: string; url: string }[];
|
||||
}
|
||||
|
||||
const tone = (l: Finding['level']) => (l === 'error' ? 'bad' : l === 'warn' ? 'warn' : 'ok');
|
||||
const yesNo = (v: boolean | null | undefined) => (v === null || v === undefined ? <Chip tone="neutral">{t('gs.unknown')}</Chip> : <Chip tone={v ? 'ok' : 'bad'}>{v ? t('gs.yes') : t('gs.no')}</Chip>);
|
||||
|
||||
export function GameServicesCard({ project }: { project: Project }) {
|
||||
const r = useRead<GameServicesStatus>(project.id, 'games.status', { network: true, title: t('gs.title') });
|
||||
const w = useWrite(project.id);
|
||||
if (!r.data) return r.error ? <ErrorNotice error={r.error} tone="warn" /> : <Card title={t('gs.title')} icon="sparkle"><Skeleton lines={3} block /></Card>;
|
||||
const s = r.data;
|
||||
if (!s.apple && !s.play && !s.findings.length) return null;
|
||||
const f = (store: 'apple' | 'play') => s.findings.filter(x => x.store === store);
|
||||
const count = (have: Counts, want: Counts) => t('gs.counts', { lb: have.leaderboards, lbWant: want.leaderboards, ach: have.achievements, achWant: want.achievements });
|
||||
return (
|
||||
<Card title={t('gs.title')} icon="sparkle" sub={t('gs.sub')}>
|
||||
<div className="grid g2" style={{ alignItems: 'start' }}>
|
||||
{s.apple && (
|
||||
<div className="stack" style={{ gap: 8 }}>
|
||||
<div className="row" style={{ gap: 6 }}><StoreGlyph store="ios" className="ic13" /><strong>{t('gs.gameCenter')}</strong></div>
|
||||
{s.apple.error ? <span className="small muted">{s.apple.error}</span> : (
|
||||
<dl className="kv">
|
||||
<dt>{t('gs.enabled')}</dt><dd>{yesNo(s.apple.enabled)}</dd>
|
||||
<dt>{t('gs.capability')}</dt><dd>{yesNo(s.apple.capability)}</dd>
|
||||
<dt>{t('gs.version', { v: s.apple.version ?? '-' })}</dt><dd>{yesNo(s.apple.versionEnabled)}</dd>
|
||||
<dt>{t('gs.items')}</dt><dd className="small">{count(s.apple, s.apple.config)}</dd>
|
||||
</dl>
|
||||
)}
|
||||
{f('apple').map(x => <Chip key={x.id} tone={tone(x.level)} title={x.fix}>{x.msg}</Chip>)}
|
||||
{!!s.apple.changes.length && <span className="small muted">{t('gs.pending', { n: s.apple.changes.length })}: {s.apple.changes.slice(0, 4).join('; ')}</span>}
|
||||
<div className="row" style={{ gap: 6 }}>
|
||||
<WriteButton run={w} primary icon="upload" w={{ method: 'apple.game_center', args: {}, title: t('gs.syncApple'), done: t('gs.synced'), after: r.refresh }} hint={t('gs.syncHint')}>{t('gs.syncApple')}</WriteButton>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{s.play && (
|
||||
<div className="stack" style={{ gap: 8 }}>
|
||||
<div className="row" style={{ gap: 6 }}><StoreGlyph store="android" className="ic13" /><strong>{t('gs.playGames')}</strong></div>
|
||||
<dl className="kv">
|
||||
<dt>{t('gs.projectId')}</dt><dd>{s.play.appId ? <span className="mono-id">{s.play.appId}</span> : <Chip tone="warn">{t('gs.notSet')}</Chip>}</dd>
|
||||
<dt>{t('gs.resource')}</dt><dd>{s.play.resource ? <span className="mono-id small">{s.play.resource}</span> : <Chip tone="warn">{t('gs.notSet')}</Chip>}</dd>
|
||||
{!s.play.error && <><dt>{t('gs.items')}</dt><dd className="small">{count(s.play, s.play.config)}</dd></>}
|
||||
</dl>
|
||||
{s.play.error && <span className="small muted">{s.play.error}</span>}
|
||||
{f('play').map(x => <Chip key={x.id} tone={tone(x.level)} title={x.fix}>{x.msg}</Chip>)}
|
||||
{!!s.play.changes.length && <span className="small muted">{t('gs.pending', { n: s.play.changes.length })}: {s.play.changes.slice(0, 4).join('; ')}</span>}
|
||||
<div className="row" style={{ gap: 6 }}>
|
||||
<WriteButton run={w} primary icon="upload" disabled={!s.play.appId} w={{ method: 'play.games', args: {}, title: t('gs.syncPlay'), done: t('gs.synced'), after: r.refresh }} hint={t('gs.syncHint')}>{t('gs.syncPlay')}</WriteButton>
|
||||
<ConsolePlanButton project={project} form="play-games-services" label={t('gs.setup')} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!!s.links.length && <div className="row small" style={{ gap: 12, marginTop: 10, flexWrap: 'wrap' }}>{s.links.map(l => <span key={l.url} className="row" style={{ gap: 4 }}>{l.label}<OpenLink url={l.url} /></span>)}</div>}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue