platform.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /** Send a system notification (optional deep link) */
  13. notify(title: string, description?: string, href?: string): Promise<void>
  14. /** Open directory picker dialog (native on Tauri, server-backed on web) */
  15. openDirectoryPickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  16. /** Open native file picker dialog (Tauri only) */
  17. openFilePickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  18. /** Save file picker dialog (Tauri only) */
  19. saveFilePickerDialog?(opts?: { title?: string; defaultPath?: string }): Promise<string | null>
  20. /** Storage mechanism, defaults to localStorage */
  21. storage?: (name?: string) => SyncStorage | AsyncStorage
  22. /** Check for updates (Tauri only) */
  23. checkUpdate?(): Promise<{ updateAvailable: boolean; version?: string }>
  24. /** Install updates (Tauri only) */
  25. update?(): Promise<void>
  26. /** Fetch override */
  27. fetch?: typeof fetch
  28. }
  29. export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({
  30. name: "Platform",
  31. init: (props: { value: Platform }) => {
  32. return props.value
  33. },
  34. })