Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: James Long <jlongster@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: 冯基魁 <56265583+fengjikui@users.noreply.github.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: Victor Navarro <vn4varro@gmail.com> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Nabs <nabil@instafork.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: AidenGeunGeun <eastlandwyvern@gmail.com> Co-authored-by: Mark <geraint0923@users.noreply.github.com>
139 lines
4.5 KiB
TypeScript
139 lines
4.5 KiB
TypeScript
import { createSimpleContext } from "@opencode-ai/ui/context"
|
|
import type { AsyncStorage, SyncStorage } from "@solid-primitives/storage"
|
|
import type { Accessor } from "solid-js"
|
|
import type { DesktopMenuAction } from "../desktop-menu"
|
|
import { ServerConnection } from "./server"
|
|
import type { WslServersPlatform } from "../wsl/types"
|
|
import type { UpdaterPlatform } from "../updater"
|
|
|
|
type PickerPaths = string | string[] | null
|
|
type OpenDirectoryPickerOptions = { title?: string; multiple?: boolean }
|
|
type OpenAttachmentPickerOptions = {
|
|
title?: string
|
|
multiple?: boolean
|
|
accept?: string[]
|
|
extensions?: string[]
|
|
defaultPath?: string
|
|
}
|
|
type SaveFilePickerOptions = { title?: string; defaultPath?: string }
|
|
type PlatformName = "web" | "desktop"
|
|
type DesktopOS = "macos" | "windows" | "linux"
|
|
|
|
export type FatalRendererErrorLog = {
|
|
error: string
|
|
url: string
|
|
version?: string
|
|
platform: PlatformName
|
|
os?: DesktopOS
|
|
}
|
|
|
|
type PlatformBase = {
|
|
/** 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>
|
|
|
|
/** Reveal a local path in the system file manager; false when the path does not exist (desktop only) */
|
|
revealPath?(path: string): Promise<boolean>
|
|
|
|
/** 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 a native attachment picker and read selected files sequentially (desktop only) */
|
|
openAttachmentPickerDialog?(
|
|
opts: OpenAttachmentPickerOptions,
|
|
onFile: (file: File) => Promise<unknown>,
|
|
): Promise<void>
|
|
|
|
/** Resolve the native source path for a desktop File. */
|
|
getPathForFile?(file: File): string
|
|
|
|
/** Open a native save file picker dialog (desktop only) */
|
|
saveFilePickerDialog?(opts?: SaveFilePickerOptions): Promise<string | null>
|
|
|
|
/** Storage mechanism, defaults to localStorage */
|
|
storage?: (name?: string) => SyncStorage | AsyncStorage
|
|
|
|
/** Stable platform window identity for window-scoped persistence */
|
|
windowID?: string
|
|
|
|
/** Application-global desktop updater */
|
|
updater?: UpdaterPlatform
|
|
|
|
/** 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
|
|
|
|
/** Manage WSL sidecar servers (Electron on Windows only) */
|
|
wslServers?: WslServersPlatform
|
|
|
|
/** 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>
|
|
|
|
/** Get whether native pinch/Ctrl-scroll zoom gestures are enabled (desktop only) */
|
|
getPinchZoomEnabled?(): Promise<boolean> | boolean
|
|
|
|
/** Allow native pinch/Ctrl-scroll zoom gestures (desktop only) */
|
|
setPinchZoomEnabled?(enabled: boolean): Promise<void> | void
|
|
|
|
/** Run a desktop-only menu action from the app chrome */
|
|
runDesktopMenuAction?(action: DesktopMenuAction): Promise<void> | void
|
|
|
|
/** Check if an editor app exists (desktop only) */
|
|
checkAppExists?(appName: string): Promise<boolean>
|
|
|
|
/** Read image from clipboard (desktop only) */
|
|
readClipboardImage?(): Promise<File | null>
|
|
|
|
/** Export collected diagnostic logs (desktop only) */
|
|
exportDebugLogs?(): Promise<string>
|
|
|
|
/** Record a fatal renderer error in platform logs (desktop only) */
|
|
recordFatalRendererError?(error: FatalRendererErrorLog): Promise<void>
|
|
}
|
|
|
|
export type Platform = PlatformBase &
|
|
(
|
|
| { platform: "web"; os?: never }
|
|
| {
|
|
platform: "desktop"
|
|
os?: DesktopOS
|
|
openDirectoryPickerDialog(opts?: OpenDirectoryPickerOptions): Promise<PickerPaths>
|
|
}
|
|
)
|
|
|
|
export type DisplayBackend = "auto" | "wayland"
|
|
|
|
export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({
|
|
name: "Platform",
|
|
init: (props: { value: Platform }) => {
|
|
return props.value
|
|
},
|
|
})
|