import { useCallback, useEffect, useState } from 'react' import { Button, Modal } from '@janhq/joi' import { useAtom, useAtomValue } from 'jotai' import useCortex from '@/hooks/useCortex' import Spinner from '../Loader/Spinner' import { waitingForCortexAtom } from '@/helpers/atoms/App.atom' import { hostAtom, janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom' const WaitingForCortexModal: React.FC = () => { const host = useAtomValue(hostAtom) const [waitingForCortex, setWaitingForCortex] = useAtom(waitingForCortexAtom) const [timedOut, setTimedOut] = useState(false) const { isSystemAlive } = useCortex() const [janDataFolderPath, setJanDataFolderPath] = useAtom( janDataFolderPathAtom ) const checkSystemAlive = useCallback(async () => { setWaitingForCortex(!(await isSystemAlive())) }, [setWaitingForCortex, isSystemAlive]) const getAppDataFolder = useCallback(async () => { return window.electronAPI?.appDataFolder().then(setJanDataFolderPath) }, [setJanDataFolderPath]) // Check health for the first time on mount useEffect(() => { checkSystemAlive() getAppDataFolder() }, [checkSystemAlive, getAppDataFolder]) useEffect(() => { setTimeout(() => { if (waitingForCortex) setTimedOut(true) }, 5000) }, [waitingForCortex]) return ( {timedOut ? ( <>

{`Hmm, Jan's taking longer than usual to start up...`}

API Server starting at{' '} {host.replace('/v1', '')}/api

Check logs at{' '} window?.electronAPI?.openAppLog()} className="cursor-pointer text-[hsla(var(--app-link))]" > {janDataFolderPath} {' '} if this persists or restart app.

) : (

Jan is getting ready! This usually
takes a few seconds...

)}
{timedOut && ( )} } /> ) } export default WaitingForCortexModal