A verification pass re-read every finding from the original sweep against the code on this branch rather than against the commit messages. It found that four of them were still broken, two because the edit I made was inert. Commit messages claim; code decides. - **The Storybook typecheck was never on.** `tsconfig.json` listed `.storybook` as a bare directory name, and tsc silently skips dot-prefixed directories in that form — so the entry typechecked nothing at all. Proved it by planting `export const __probe: string = 1` in `.storybook/preview.tsx` and watching `bun run lint` pass. `.storybook/**/*` is what actually pulls it in; the same probe now fails as it should. - **The Moonlight stale-PIN reset was a no-op.** `submit.reset()` sat at the top of `onSubmit`, immediately before `submit.mutate(...)` — which moves the status to pending in the same update, so it cleared a flag that was already changing. The green "PIN sent" note therefore still greeted the next pairing attempt over an empty PIN box. It now resets on the transition that actually matters: `pin_pending` going false → true. - **The session⇄game controls had the enforcement flag inverted**, and I never touched it. `enforced.length === 0 || …` reads an EMPTY list as "this build enforces everything", when the contract says the opposite in as many words: "Empty on a platform with no launch path (macOS), so the console can say so instead of offering a switch that does nothing". On exactly the platform the flag exists for, every control stayed live and reported success for an axis the host would never act on. Absent still means "assume it acts" — that is the compatible reading for an older host, and a different case from present-empty. - **Logout stopped revoking after a restart.** The epoch was a module-level counter starting at 1, so it revoked within one process run and then reset — and since the seal key derives from the stable mgmt token, a cookie captured before a restart unsealed fine and was accepted again for the rest of its 7-day TTL. One service restart undid the whole fix. It persists next to the host's config now. Verified: log out, restart the console, the captured cookie still 401s, a fresh login still works. Two more the pass rated as partial, both worth closing: - The plugin-UI response filter was a denylist of four header names, so `Clear-Site-Data` sailed through — a plugin error page could wipe `pf_session` and sign the operator out of the console, on our own origin, because the iframe is same-origin by design. It is an allowlist now; a plugin-supplied CSP, `X-Frame-Options` or CORS header no longer speaks for us either. - A half-configured TLS setup now refuses to start instead of logging a warning and serving anyway. Neither shape can work — one path missing puts the login password on the LAN in the clear, and PUNKTFUNK_UI_SECURE without TLS marks the cookie Secure so the browser drops it and login can never stick. Exiting with a reason beats a console that looks fine and is not. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
152 lines
4.7 KiB
TypeScript
152 lines
4.7 KiB
TypeScript
import { useQueryClient } from "@tanstack/react-query";
|
|
import { Info, KeyRound } from "lucide-react";
|
|
import { type FC, useEffect, useRef, useState } from "react";
|
|
import { getListPairedClientsQueryKey } from "@/api/gen/clients/clients";
|
|
import type { PairingStatus } from "@/api/gen/model/pairingStatus";
|
|
import {
|
|
getGetPairingStatusQueryKey,
|
|
useGetPairingStatus,
|
|
useSubmitPairingPin,
|
|
} from "@/api/gen/pairing/pairing";
|
|
import { QueryState } from "@/components/query-state";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import type { Loadable } from "@/lib/query";
|
|
import { m } from "@/paraglide/messages";
|
|
|
|
/** Container: GameStream/Moonlight pairing — poll status, own the PIN entry, submit it. */
|
|
export const MoonlightPairingSection: FC = () => {
|
|
const qc = useQueryClient();
|
|
const [pin, setPin] = useState("");
|
|
const pairing = useGetPairingStatus({ query: { refetchInterval: 2_000 } });
|
|
const submit = useSubmitPairingPin();
|
|
|
|
// Clear the previous attempt's outcome when a NEW pairing knock arrives.
|
|
//
|
|
// The mutation's success flag outlives the form — the section never unmounts, only the inner
|
|
// <form> is conditional — so the green "PIN sent" note was still on screen above an empty PIN
|
|
// box the next time Moonlight asked. Resetting inside `onSubmit` (the first attempt at this)
|
|
// does nothing: `mutate` moves the status to pending in the same update, so `isSuccess` was
|
|
// already about to go false. The transition that matters is `pin_pending` going false → true.
|
|
const pending = pairing.data?.pin_pending ?? false;
|
|
const wasPending = useRef(pending);
|
|
useEffect(() => {
|
|
if (pending && !wasPending.current) {
|
|
submit.reset();
|
|
setPin("");
|
|
}
|
|
wasPending.current = pending;
|
|
}, [pending, submit.reset]);
|
|
|
|
const onSubmit = () => {
|
|
submit.mutate(
|
|
{ data: { pin } },
|
|
{
|
|
onSuccess: () => {
|
|
setPin("");
|
|
qc.invalidateQueries({ queryKey: getGetPairingStatusQueryKey() });
|
|
// The success message tells the operator to check the paired list, so refresh it —
|
|
// both planes, since this card's count spans them.
|
|
qc.invalidateQueries({ queryKey: getListPairedClientsQueryKey() });
|
|
},
|
|
},
|
|
);
|
|
};
|
|
|
|
return (
|
|
<MoonlightPairing
|
|
pairing={pairing}
|
|
pin={pin}
|
|
onPinChange={setPin}
|
|
onSubmit={onSubmit}
|
|
isSubmitting={submit.isPending}
|
|
isSuccess={submit.isSuccess}
|
|
isError={submit.isError}
|
|
/>
|
|
);
|
|
};
|
|
|
|
/** GameStream/Moonlight pairing: the client shows a PIN, the operator submits it here. */
|
|
export const MoonlightPairing: FC<{
|
|
pairing: Loadable<PairingStatus>;
|
|
pin: string;
|
|
onPinChange: (v: string) => void;
|
|
onSubmit: () => void;
|
|
isSubmitting: boolean;
|
|
isSuccess: boolean;
|
|
isError: boolean;
|
|
}> = ({
|
|
pairing,
|
|
pin,
|
|
onPinChange,
|
|
onSubmit,
|
|
isSubmitting,
|
|
isSuccess,
|
|
isError,
|
|
}) => {
|
|
const pending = pairing.data?.pin_pending ?? false;
|
|
return (
|
|
<QueryState
|
|
isLoading={pairing.isLoading}
|
|
error={pairing.error}
|
|
refetch={pairing.refetch}
|
|
>
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<KeyRound className="size-4" />
|
|
{m.pairing_moonlight_title()}
|
|
</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{!pending ? (
|
|
<p className="text-sm text-muted-foreground">{m.pairing_idle()}</p>
|
|
) : (
|
|
<form
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
onSubmit();
|
|
}}
|
|
className="space-y-4"
|
|
>
|
|
<p className="text-sm">{m.pairing_waiting()}</p>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="pin">{m.pairing_pin_label()}</Label>
|
|
<Input
|
|
id="pin"
|
|
inputMode="numeric"
|
|
autoComplete="off"
|
|
maxLength={16}
|
|
value={pin}
|
|
onChange={(e) =>
|
|
onPinChange(e.target.value.replace(/\D/g, ""))
|
|
}
|
|
placeholder="0000"
|
|
className="font-mono text-lg tracking-widest"
|
|
/>
|
|
</div>
|
|
<Button type="submit" disabled={pin.length < 4 || isSubmitting}>
|
|
{m.pairing_submit()}
|
|
</Button>
|
|
{/* A 204 means the PIN was DELIVERED to the waiting handshake, not that pairing
|
|
succeeded — the ceremony verifies it out-of-band. So report "sent", not
|
|
"paired", and let the operator confirm via the Paired devices list. */}
|
|
{isSuccess && (
|
|
<p className="flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
<Info className="size-4" />
|
|
{m.pairing_pin_sent()}
|
|
</p>
|
|
)}
|
|
{isError && (
|
|
<p className="text-sm text-destructive">{m.pairing_failed()}</p>
|
|
)}
|
|
</form>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
</QueryState>
|
|
);
|
|
};
|