platform.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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" | "desktop"
  6. /** Desktop OS (Tauri only) */
  7. os?: "macos" | "windows" | "linux"
  8. /** App version */
  9. version?: string
  10. /** Open a URL in the default browser */
  11. openLink(url: string): void
  12. /** Restart the app */
  13. restart(): Promise<void>
  14. /** Send a system notification (optional deep link) */
  15. notify(title: string, description?: string, href?: string): Promise<void>
  16. /** Open directory picker dialog (native on Tauri, server-backed on web) */
  17. openDirectoryPickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  18. /** Open native file picker dialog (Tauri only) */
  19. openFilePickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  20. /** Save file picker dialog (Tauri only) */
  21. saveFilePickerDialog?(opts?: { title?: string; defaultPath?: string }): Promise<string | null>
  22. /** Storage mechanism, defaults to localStorage */
  23. storage?: (name?: string) => SyncStorage | AsyncStorage
  24. /** Check for updates (Tauri only) */
  25. checkUpdate?(): Promise<{ updateAvailable: boolean; version?: string }>
  26. /** Install updates (Tauri only) */
  27. update?(): Promise<void>
  28. /** Fetch override */
  29. fetch?: typeof fetch
  30. /** Get the configured default server URL (desktop only) */
  31. getDefaultServerUrl?(): Promise<string | null>
  32. /** Set the default server URL to use on app startup (desktop only) */
  33. setDefaultServerUrl?(url: string | null): Promise<void>
  34. }
  35. export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({
  36. name: "Platform",
  37. init: (props: { value: Platform }) => {
  38. return props.value
  39. },
  40. })