( message: string, notificationType: string, )
| 36 | * @param timeout - The timeout in milliseconds (defaults to 6000ms) |
| 37 | */ |
| 38 | export function useNotifyAfterTimeout( |
| 39 | message: string, |
| 40 | notificationType: string, |
| 41 | ): void { |
| 42 | const terminal = useTerminalNotification() |
| 43 | |
| 44 | // Reset interaction time when hook is called to make sure that requests |
| 45 | // that took a long time to complete don't pop up a notification right away. |
| 46 | // Must be immediate because useEffect runs after Ink's render cycle has |
| 47 | // already flushed; without it the timestamp stays stale and a premature |
| 48 | // notification fires if the user is idle (no subsequent renders to flush). |
| 49 | useEffect(() => { |
| 50 | updateLastInteractionTime(true) |
| 51 | }, []) |
| 52 | |
| 53 | useEffect(() => { |
| 54 | let hasNotified = false |
| 55 | const timer = setInterval(() => { |
| 56 | if (shouldNotify(DEFAULT_INTERACTION_THRESHOLD_MS) && !hasNotified) { |
| 57 | hasNotified = true |
| 58 | clearInterval(timer) |
| 59 | void sendNotification({ message, notificationType }, terminal) |
| 60 | } |
| 61 | }, DEFAULT_INTERACTION_THRESHOLD_MS) |
| 62 | |
| 63 | return () => clearInterval(timer) |
| 64 | }, [message, notificationType, terminal]) |
| 65 | } |
| 66 |
no test coverage detected