platform.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { createSimpleContext } from "@opencode-ai/ui/context"
  2. import { AsyncStorage, SyncStorage } from "@solid-primitives/storage"
  3. export type Platform = {
  4. /** Platform discriminator */
  5. platform: "web" | "tauri"
  6. /** App version */
  7. version?: string
  8. /** Open a URL in the default browser */
  9. openLink(url: string): void
  10. /** Restart the app */
  11. restart(): Promise<void>
  12. /** Open native directory picker dialog (Tauri only) */
  13. openDirectoryPickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  14. /** Open native file picker dialog (Tauri only) */
  15. openFilePickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  16. /** Save file picker dialog (Tauri only) */
  17. saveFilePickerDialog?(opts?: { title?: string; defaultPath?: string }): Promise<string | null>
  18. /** Storage mechanism, defaults to localStorage */
  19. storage?: (name?: string) => SyncStorage | AsyncStorage
  20. /** Check for updates (Tauri only) */
  21. checkUpdate?(): Promise<{ updateAvailable: boolean; version?: string }>
  22. /** Install updates (Tauri only) */
  23. update?(): Promise<void>
  24. /** Fetch override */
  25. fetch?: typeof fetch
  26. }
  27. export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({
  28. name: "Platform",
  29. init: (props: { value: Platform }) => {
  30. return props.value
  31. },
  32. })