index.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // @refresh reload
  2. import { render } from "solid-js/web"
  3. import { App, PlatformProvider, Platform } from "@opencode-ai/desktop"
  4. import { onMount } from "solid-js"
  5. import { open, save } from "@tauri-apps/plugin-dialog"
  6. import { open as shellOpen } from "@tauri-apps/plugin-shell"
  7. import { type as ostype } from "@tauri-apps/plugin-os"
  8. import { runUpdater, UPDATER_ENABLED } from "./updater"
  9. import { createMenu } from "./menu"
  10. const root = document.getElementById("root")
  11. if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
  12. throw new Error(
  13. "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
  14. )
  15. }
  16. const platform: Platform = {
  17. platform: "tauri",
  18. async openDirectoryPickerDialog(opts) {
  19. const result = await open({
  20. directory: true,
  21. multiple: opts?.multiple ?? false,
  22. title: opts?.title ?? "Choose a folder",
  23. })
  24. return result
  25. },
  26. async openFilePickerDialog(opts) {
  27. const result = await open({
  28. directory: false,
  29. multiple: opts?.multiple ?? false,
  30. title: opts?.title ?? "Choose a file",
  31. })
  32. return result
  33. },
  34. async saveFilePickerDialog(opts) {
  35. const result = await save({
  36. title: opts?.title ?? "Save file",
  37. defaultPath: opts?.defaultPath,
  38. })
  39. return result
  40. },
  41. openLink(url: string) {
  42. shellOpen(url)
  43. },
  44. }
  45. createMenu()
  46. render(() => {
  47. onMount(() => {
  48. if (UPDATER_ENABLED) runUpdater()
  49. })
  50. return (
  51. <PlatformProvider value={platform}>
  52. {ostype() === "macos" && (
  53. <div class="bg-background-base border-b border-border-weak-base h-8" data-tauri-drag-region />
  54. )}
  55. <App />
  56. </PlatformProvider>
  57. )
  58. }, root!)