File size: 1,144 Bytes
f0743f4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import { useRecoilValue } from 'recoil';
import useWakeLock from '~/hooks/useWakeLock';
import store from '~/store';
/**
* WakeLockManager Component
*
* Manages the Screen Wake Lock during AI response generation to prevent
* device screens from sleeping or dimming during long-running operations.
*
* The wake lock is only active when:
* 1. Any conversation is currently generating a response (anySubmittingSelector)
* 2. User has not disabled the feature in settings (keepScreenAwake preference)
*
* This component is rendered at the root level of the application
* to ensure wake lock state persists across all conversations and routes.
*
* @see useWakeLock - The hook that manages the actual wake lock implementation
* @see anySubmittingSelector - Recoil selector tracking if any conversation is generating
*/
const WakeLockManager = () => {
const isSubmitting = useRecoilValue(store.anySubmittingSelector);
const keepScreenAwake = useRecoilValue(store.keepScreenAwake);
const shouldPreventSleep = isSubmitting && keepScreenAwake;
useWakeLock(shouldPreventSleep);
return null;
};
export default WakeLockManager;
|