| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import { createSimpleContext } from "@opencode-ai/ui/context"
- import type { AsyncStorage, SyncStorage } from "@solid-primitives/storage"
- import type { Accessor } from "solid-js"
- import { ServerConnection } from "./server"
- type PickerPaths = string | string[] | null
- type OpenDirectoryPickerOptions = { title?: string; multiple?: boolean }
- type OpenFilePickerOptions = { title?: string; multiple?: boolean; accept?: string[]; extensions?: string[] }
- type SaveFilePickerOptions = { title?: string; defaultPath?: string }
- type UpdateInfo = { updateAvailable: boolean; version?: string }
- export type Platform = {
- /** Platform discriminator */
- platform: "web" | "desktop"
- /** Desktop OS (Tauri only) */
- os?: "macos" | "windows" | "linux"
- /** App version */
- version?: string
- /** Open a URL in the default browser */
- openLink(url: string): void
- /** Open a local path in a local app (desktop only) */
- openPath?(path: string, app?: string): Promise<void>
- /** Restart the app */
- restart(): Promise<void>
- /** Navigate back in history */
- back(): void
- /** Navigate forward in history */
- forward(): void
- /** Send a system notification (optional deep link) */
- notify(title: string, description?: string, href?: string): Promise<void>
- /** Open directory picker dialog (native on Tauri, server-backed on web) */
- openDirectoryPickerDialog?(opts?: OpenDirectoryPickerOptions): Promise<PickerPaths>
- /** Open native file picker dialog (Tauri only) */
- openFilePickerDialog?(opts?: OpenFilePickerOptions): Promise<PickerPaths>
- /** Save file picker dialog (Tauri only) */
- saveFilePickerDialog?(opts?: SaveFilePickerOptions): Promise<string | null>
- /** Storage mechanism, defaults to localStorage */
- storage?: (name?: string) => SyncStorage | AsyncStorage
- /** Check for a downloadable desktop update */
- checkUpdate?(): Promise<UpdateInfo>
- /** Install the downloaded update using the platform restart flow */
- updateAndRestart?(): Promise<void>
- /** Fetch override */
- fetch?: typeof fetch
- /** Get the configured default server URL (platform-specific) */
- getDefaultServer?(): Promise<ServerConnection.Key | null>
- /** Set the default server URL to use on app startup (platform-specific) */
- setDefaultServer?(url: ServerConnection.Key | null): Promise<void> | void
- /** Get the configured WSL integration (desktop only) */
- getWslEnabled?(): Promise<boolean>
- /** Set the configured WSL integration (desktop only) */
- setWslEnabled?(config: boolean): Promise<void> | void
- /** Get the preferred display backend (desktop only) */
- getDisplayBackend?(): Promise<DisplayBackend | null> | DisplayBackend | null
- /** Set the preferred display backend (desktop only) */
- setDisplayBackend?(backend: DisplayBackend): Promise<void>
- /** Parse markdown to HTML using native parser (desktop only, returns unprocessed code blocks) */
- parseMarkdown?(markdown: string): Promise<string>
- /** Webview zoom level (desktop only) */
- webviewZoom?: Accessor<number>
- /** Check if an editor app exists (desktop only) */
- checkAppExists?(appName: string): Promise<boolean>
- /** Read image from clipboard (desktop only) */
- readClipboardImage?(): Promise<File | null>
- }
- export type DisplayBackend = "auto" | "wayland"
- export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({
- name: "Platform",
- init: (props: { value: Platform }) => {
- return props.value
- },
- })
|