/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/tui/src/component/startup-loading.tsx
63 строки
2 KB
Dax
refactor(server): canonicalize service API (#31049)
07 июн 2026, 06:27
Не верифицирован
07 июн 2026, 06:27
fe0c4f8
Код
Авторство
О чём код?
import { 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().theme 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.backgroundPanel} paddingLeft={1} paddingRight={1}> <Spinner color={theme.textMuted}>{text()}</Spinner> </box> </box> </Show> ) }