diff --git a/frontend/src/hooks/useWakeLock.ts b/frontend/src/hooks/useWakeLock.ts new file mode 100644 index 0000000..1bf5943 --- /dev/null +++ b/frontend/src/hooks/useWakeLock.ts @@ -0,0 +1,26 @@ +import { useEffect, useRef } from 'react' + +export function useWakeLock(active: boolean) { + const lockRef = useRef(null) + + useEffect(() => { + if (!active) { + lockRef.current?.release().catch(() => {}) + lockRef.current = null + return + } + + if (!('wakeLock' in navigator)) return + + navigator.wakeLock.request('screen').then(lock => { + lockRef.current = lock + }).catch(() => { + // Wake Lock non disponible (mode économie d'énergie, navigateur non supporté) + }) + + return () => { + lockRef.current?.release().catch(() => {}) + lockRef.current = null + } + }, [active]) +}