platform.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { createSimpleContext } from "@opencode-ai/ui/context"
  2. import { AsyncStorage, SyncStorage } from "@solid-primitives/storage"
  3. import type { Accessor } from "solid-js"
  4. export type Platform = {
  5. /** Platform discriminator */
  6. platform: "web" | "desktop"
  7. /** Desktop OS (Tauri only) */
  8. os?: "macos" | "windows" | "linux"
  9. /** App version */
  10. version?: string
  11. /** Open a URL in the default browser */
  12. openLink(url: string): void
  13. /** Open a local path in a local app (desktop only) */
  14. openPath?(path: string, app?: string): Promise<void>
  15. /** Restart the app */
  16. restart(): Promise<void>
  17. /** Navigate back in history */
  18. back(): void
  19. /** Navigate forward in history */
  20. forward(): void
  21. /** Send a system notification (optional deep link) */
  22. notify(title: string, description?: string, href?: string): Promise<void>
  23. /** Open directory picker dialog (native on Tauri, server-backed on web) */
  24. openDirectoryPickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  25. /** Open native file picker dialog (Tauri only) */
  26. openFilePickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise<string | string[] | null>
  27. /** Save file picker dialog (Tauri only) */
  28. saveFilePickerDialog?(opts?: { title?: string; defaultPath?: string }): Promise<string | null>
  29. /** Storage mechanism, defaults to localStorage */
  30. storage?: (name?: string) => SyncStorage | AsyncStorage
  31. /** Check for updates (Tauri only) */
  32. checkUpdate?(): Promise<{ updateAvailable: boolean; version?: string }>
  33. /** Install updates (Tauri only) */
  34. update?(): Promise<void>
  35. /** Fetch override */
  36. fetch?: typeof fetch
  37. /** Get the configured default server URL (platform-specific) */
  38. getDefaultServerUrl?(): Promise<string | null> | string | null
  39. /** Set the default server URL to use on app startup (platform-specific) */
  40. setDefaultServerUrl?(url: string | null): Promise<void> | void
  41. /** Parse markdown to HTML using native parser (desktop only, returns unprocessed code blocks) */
  42. parseMarkdown?(markdown: string): Promise<string>
  43. /** Webview zoom level (desktop only) */
  44. webviewZoom?: Accessor<number>
  45. /** Check if an editor app exists (desktop only) */
  46. checkAppExists?(appName: string): Promise<boolean>
  47. /** Read image from clipboard (desktop only) */
  48. readClipboardImage?(): Promise<File | null>
  49. }
  50. export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({
  51. name: "Platform",
  52. init: (props: { value: Platform }) => {
  53. return props.value
  54. },
  55. })