entry.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // @refresh reload
  2. import { render } from "solid-js/web"
  3. import { AppBaseProviders, AppInterface } from "@/app"
  4. import { Platform, PlatformProvider } from "@/context/platform"
  5. import pkg from "../package.json"
  6. const root = document.getElementById("root")
  7. if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
  8. throw new Error(
  9. "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
  10. )
  11. }
  12. const platform: Platform = {
  13. platform: "web",
  14. version: pkg.version,
  15. openLink(url: string) {
  16. window.open(url, "_blank")
  17. },
  18. restart: async () => {
  19. window.location.reload()
  20. },
  21. notify: async (title, description, href) => {
  22. if (!("Notification" in window)) return
  23. const permission =
  24. Notification.permission === "default"
  25. ? await Notification.requestPermission().catch(() => "denied")
  26. : Notification.permission
  27. if (permission !== "granted") return
  28. const inView = document.visibilityState === "visible" && document.hasFocus()
  29. if (inView) return
  30. await Promise.resolve()
  31. .then(() => {
  32. const notification = new Notification(title, {
  33. body: description ?? "",
  34. icon: "https://opencode.ai/favicon-96x96-v2.png",
  35. })
  36. notification.onclick = () => {
  37. window.focus()
  38. if (href) {
  39. window.history.pushState(null, "", href)
  40. window.dispatchEvent(new PopStateEvent("popstate"))
  41. }
  42. notification.close()
  43. }
  44. })
  45. .catch(() => undefined)
  46. },
  47. }
  48. render(
  49. () => (
  50. <PlatformProvider value={platform}>
  51. <AppBaseProviders>
  52. <AppInterface />
  53. </AppBaseProviders>
  54. </PlatformProvider>
  55. ),
  56. root!,
  57. )