diff --git a/src/App.tsx b/src/App.tsx index 21fe836..37db27c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -62,6 +62,22 @@ function App() { const [currentTime, setCurrentTime] = useState(0); const [duration, setDuration] = useState(0); const audioRef = useRef(null); + const [lastClicked, setLastClicked] = useState(new Date); + + const click = () => setLastClicked(new Date); + + useEffect(() => { + const IDLE_TIMEOUT_MS = 15 * 60 * 1000; // 15 minutes + window.setTimeout(() => { + setDisplayText("Asleep. Tap screen to scan."); + fetch('/api/reader/auto', { method: 'POST' }); + }, lastClicked.getTime() + IDLE_TIMEOUT_MS - new Date().getTime()); + + return () => { + setDisplayText(WELCOME_TEXT); + fetch('/api/reader/on', { method: 'POST' }); + } + }, [lastClicked]); const handleEnded = () => { if ((album?.tracks?.length ?? 0) > nowPlaying + 1) { // if there's a next track @@ -216,7 +232,7 @@ function App() {

This album cannot be played, as Chandler doesn't own a copy.

); return ( -
+