import { useEffect } from 'react'; import { useAtomValue } from 'jotai'; import { callEmbedAtom } from '../state/callEmbed'; import { invokeTauri } from './useTauri'; /** * P5-46 — keep the system awake during calls (call continuity). Mirrors the * call-embed atom (undefined = no active call) onto the native `set_call_active` * command, which holds a `SetThreadExecutionState` request on Windows while a * voice/video call is active and releases it when the call ends. No-op in the * browser. */ export function useTauriCallPower(): void { const callEmbed = useAtomValue(callEmbedAtom); useEffect(() => { invokeTauri('set_call_active', { active: callEmbed !== undefined }); // #76 — if the shell unmounts while a call is still active (forced // reload/HMR, or a future teardown path that doesn't end the call first), // release the native keep-awake state instead of leaving it held forever. return () => { invokeTauri('set_call_active', { active: false }); }; }, [callEmbed]); }