loading.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { render } from "solid-js/web"
  2. import { MetaProvider } from "@solidjs/meta"
  3. import "@opencode-ai/app/index.css"
  4. import { Font } from "@opencode-ai/ui/font"
  5. import { Splash } from "@opencode-ai/ui/logo"
  6. import "./styles.css"
  7. import { createSignal, Match, onMount } from "solid-js"
  8. import { commands, events, InitStep } from "./bindings"
  9. import { Channel } from "@tauri-apps/api/core"
  10. import { Switch } from "solid-js"
  11. const root = document.getElementById("root")!
  12. render(() => {
  13. let splash!: SVGSVGElement
  14. const [state, setState] = createSignal<InitStep | null>(null)
  15. const channel = new Channel<InitStep>()
  16. channel.onmessage = (e) => setState(e)
  17. commands.awaitInitialization(channel as any).then(() => {
  18. const currentOpacity = getComputedStyle(splash).opacity
  19. splash.style.animation = "none"
  20. splash.style.animationPlayState = "paused"
  21. splash.style.opacity = currentOpacity
  22. requestAnimationFrame(() => {
  23. splash.style.transition = "opacity 0.3s ease"
  24. requestAnimationFrame(() => {
  25. splash.style.opacity = "1"
  26. })
  27. })
  28. })
  29. return (
  30. <MetaProvider>
  31. <div class="w-screen h-screen bg-background-base flex items-center justify-center">
  32. <Font />
  33. <div class="flex flex-col items-center gap-10">
  34. <Splash ref={splash} class="h-25 animate-[pulse-splash_2s_ease-in-out_infinite]" />
  35. <span class="text-text-base">
  36. <Switch fallback="Just a moment...">
  37. <Match when={state()?.phase === "done"}>
  38. {(_) => {
  39. onMount(() => {
  40. setTimeout(() => events.loadingWindowComplete.emit(null), 1000)
  41. })
  42. return "All done"
  43. }}
  44. </Match>
  45. <Match when={state()?.phase === "sqlite_waiting"}>
  46. {(_) => {
  47. const textItems = [
  48. "Just a moment...",
  49. "Migrating your database",
  50. "This could take a couple of minutes",
  51. ]
  52. const [textIndex, setTextIndex] = createSignal(0)
  53. onMount(async () => {
  54. await new Promise((res) => setTimeout(res, 3000))
  55. setTextIndex(1)
  56. await new Promise((res) => setTimeout(res, 6000))
  57. setTextIndex(2)
  58. })
  59. return <>{textItems[textIndex()]}</>
  60. }}
  61. </Match>
  62. </Switch>
  63. </span>
  64. </div>
  65. </div>
  66. </MetaProvider>
  67. )
  68. }, root)