mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
7a7a9f5e6b
111 of 122 top-level src/utils/ files move into 16 topic folders (audio, cache, cover, share, server, playback, playlist, deviceSync, waveform, mix, format, export, changelog, ui, perf, componentHelpers). True singletons with no cluster stay at the utils/ root. Pure file-move: a path-aware codemod rewrote 539 relative-import specifiers across 275 files; no logic touched. The hot-path coverage gate list (.github/frontend-hot-path-files.txt) is updated to the new paths for the 11 gated utils files — a mechanical consequence of the move, not a CI change. tsc is green.
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { createPortal } from 'react-dom';
|
|
import { usePerfProbeFlag } from '../utils/perf/perfFlags';
|
|
|
|
const SAMPLE_MS = 500;
|
|
|
|
/** FPS from rAF callbacks over sliding ~500ms windows; only runs when Performance Probe enables the overlay. */
|
|
export default function FpsOverlay() {
|
|
const showFpsOverlay = usePerfProbeFlag('showFpsOverlay');
|
|
const [fps, setFps] = useState(0);
|
|
|
|
useEffect(() => {
|
|
if (!showFpsOverlay) {
|
|
setFps(0);
|
|
return;
|
|
}
|
|
|
|
let frames = 0;
|
|
let lastReport = performance.now();
|
|
let rafId = 0;
|
|
|
|
const loop = () => {
|
|
frames++;
|
|
const now = performance.now();
|
|
if (now - lastReport >= SAMPLE_MS) {
|
|
const elapsedSec = (now - lastReport) / 1000;
|
|
setFps(Math.round(frames / elapsedSec));
|
|
frames = 0;
|
|
lastReport = now;
|
|
}
|
|
rafId = requestAnimationFrame(loop);
|
|
};
|
|
|
|
rafId = requestAnimationFrame(loop);
|
|
return () => cancelAnimationFrame(rafId);
|
|
}, [showFpsOverlay]);
|
|
|
|
if (!showFpsOverlay) return null;
|
|
|
|
return createPortal(
|
|
<div className="fps-overlay" aria-hidden="true">
|
|
{fps}
|
|
{' '}
|
|
<span className="fps-overlay__unit">FPS</span>
|
|
</div>,
|
|
document.body,
|
|
);
|
|
}
|