mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-19 10:31:16 -07:00
feat: custom loading phrase when interactive shell requires input (#12535)
This commit is contained in:
39
packages/cli/src/ui/hooks/useInactivityTimer.ts
Normal file
39
packages/cli/src/ui/hooks/useInactivityTimer.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
/**
|
||||
* Returns true after a specified delay of inactivity.
|
||||
* Inactivity is defined as 'trigger' not changing for 'delayMs' milliseconds.
|
||||
*
|
||||
* @param isActive Whether the timer should be running.
|
||||
* @param trigger Any value that, when changed, resets the inactivity timer.
|
||||
* @param delayMs The delay in milliseconds before considering the state inactive.
|
||||
*/
|
||||
export const useInactivityTimer = (
|
||||
isActive: boolean,
|
||||
trigger: unknown,
|
||||
delayMs: number = 5000,
|
||||
): boolean => {
|
||||
const [isInactive, setIsInactive] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isActive) {
|
||||
setIsInactive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setIsInactive(false);
|
||||
const timer = setTimeout(() => {
|
||||
setIsInactive(true);
|
||||
}, delayMs);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [isActive, trigger, delayMs]);
|
||||
|
||||
return isInactive;
|
||||
};
|
||||
Reference in New Issue
Block a user