Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { createEffect, createMemo, createSignal, onCleanup, Show } from "solid-js"import { useTheme } from "../context/theme"import { Spinner } from "./spinner"
export function StartupLoading(props: { ready: () => boolean }) { const theme = useTheme() const [show, setShow] = createSignal(false) const text = createMemo(() => (props.ready() ? "Finishing startup…" : "Loading plugins…")) let wait: NodeJS.Timeout | undefined let hold: NodeJS.Timeout | undefined let stamp = 0
createEffect(() => { if (props.ready()) { if (wait) { clearTimeout(wait) wait = undefined } if (!show()) return if (hold) return
const left = 3000 - (Date.now() - stamp) if (left <= 0) { setShow(false) return }
hold = setTimeout(() => { hold = undefined setShow(false) }, left).unref() return }
if (hold) { clearTimeout(hold) hold = undefined } if (show()) return if (wait) return
wait = setTimeout(() => { wait = undefined stamp = Date.now() setShow(true) }, 500).unref() })
onCleanup(() => { if (wait) clearTimeout(wait) if (hold) clearTimeout(hold) })
return ( <Show when={show()}> <box position="absolute" zIndex={5000} left={0} right={0} bottom={1} justifyContent="center" alignItems="center"> <box backgroundColor={theme.background.raised.base} paddingLeft={1} paddingRight={1}> <Spinner color={theme.text.muted}>{text()}</Spinner> </box> </box> </Show> )}