feat(shopping): hook useWakeLock avec fallback gracieux
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
|
||||
export function useWakeLock(active: boolean) {
|
||||
const lockRef = useRef<WakeLockSentinel | null>(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])
|
||||
}
|
||||
Reference in New Issue
Block a user