mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
☕ feat: Prevent Screen Sleep During Response Generation (#10597)
* feat: prevent screen sleep during response generation * refactor: screen wake lock functionality during response generation * chore: import order * chore: reorder import statements in WakeLockManager component --------- Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
5ac9ac57cc
commit
040d083088
7 changed files with 262 additions and 0 deletions
|
|
@ -29,6 +29,13 @@ const toggleSwitchConfigs = [
|
|||
hoverCardText: undefined,
|
||||
key: 'hideSidePanel',
|
||||
},
|
||||
{
|
||||
stateAtom: store.keepScreenAwake,
|
||||
localizationKey: 'com_nav_keep_screen_awake',
|
||||
switchId: 'keepScreenAwake',
|
||||
hoverCardText: undefined,
|
||||
key: 'keepScreenAwake',
|
||||
},
|
||||
];
|
||||
|
||||
export const ThemeSelector = ({
|
||||
|
|
|
|||
31
client/src/components/System/WakeLockManager.tsx
Normal file
31
client/src/components/System/WakeLockManager.tsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue