/* eslint-disable @typescript-eslint/naming-convention */ import { useCallback, useEffect, useState } from 'react' import React from 'react' import { Button } from '@janhq/uikit' import { useAtomValue } from 'jotai' import { CopyIcon, CheckIcon, FolderIcon } from 'lucide-react' import { useClipboard } from '@/hooks/useClipboard' import { useLogs } from '@/hooks/useLogs' import { usePath } from '@/hooks/usePath' import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom' type ServerLogsProps = { limit?: number; withCopy?: boolean } const ServerLogs = (props: ServerLogsProps) => { const { limit = 0 } = props const { getLogs } = useLogs() const serverEnabled = useAtomValue(serverEnabledAtom) const [logs, setLogs] = useState([]) const { onRevealInFinder } = usePath() const clipboard = useClipboard({ timeout: 1000 }) const updateLogs = useCallback( () => getLogs('server').then((log) => { if (typeof log?.split === 'function') { setLogs(log.split(/\r?\n|\r|\n/g)) } }), // eslint-disable-next-line react-hooks/exhaustive-deps [] ) useEffect(() => { if (serverEnabled) { updateLogs() } }, [serverEnabled, updateLogs]) useEffect(() => { updateLogs() // Log polling interval const intervalId = setInterval(() => { updateLogs() }, window.core?.api?.pollingInterval ?? 1000) // clean up interval return () => clearInterval(intervalId) }, [updateLogs]) return ( <>
{logs.length > 1 ? (
{logs.slice(-limit).map((log, i) => { return (

{log}

) })}
) : (

Empty logs

)}
) } export default ServerLogs