console.log('test') import { ipcRenderer } from 'electron' import React, { useCallback, useEffect, useRef, useState } from 'react' import { render } from 'react-dom' // @ts-ignore import chime from 'url:../assets/chime.mp3' const useKeyPress = (handler: (e: KeyboardEvent) => void) => { const handlerRef = useRef() useEffect(() => { handlerRef.current = handler }, [handler]) useEffect(() => { const fn = (event: KeyboardEvent) => { if (handlerRef.current) handlerRef.current(event) } window.addEventListener('keydown', fn) return () => { window.removeEventListener('keydown', fn) } }, []) } const Banner: React.FC = () => { const close = useCallback(() => { ipcRenderer.send('close') }, []) const [done, setDone] = useState(false) const [auto, setAuto] = useState(false) const [countdown, setCountdown] = useState(null) const handler = useCallback( (e: KeyboardEvent) => { if (done) close() }, [countdown, done] ) useKeyPress(handler) useEffect(() => { if (done && auto) setTimeout(() => close(), 1500) }, [done, auto]) useEffect(() => { if (countdown === null) return else if (countdown > 0) { setTimeout(() => setCountdown(countdown - 1), 1000) } else { const audio = new Audio(chime) audio.play() setDone(true) } }, [countdown]) useEffect(() => { const autoClose = ipcRenderer.sendSync('load', { key: 'autoClose' }) setAuto(autoClose) const time = ipcRenderer.sendSync('load', { key: 'duration' }) setCountdown(time) }, []) return (

Look Away

{countdown}
Look at least 6 meters away.
You will hear a sound when you are done.
) } render(, document.querySelector('main'))