diff --git a/packages/desktop/src/PlatformContext.tsx b/packages/desktop/src/PlatformContext.tsx deleted file mode 100644 index 5b510a8d4..000000000 --- a/packages/desktop/src/PlatformContext.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { createContext } from "solid-js" -import { useContext } from "solid-js" - -export interface Platform {} - -const PlatformContext = createContext() - -export const PlatformProvider = PlatformContext.Provider - -export function usePlatform() { - const ctx = useContext(PlatformContext) - if (!ctx) throw new Error("usePlatform must be used within a PlatformProvider") - return ctx -} diff --git a/packages/desktop/src/DesktopInterface.tsx b/packages/desktop/src/app.tsx similarity index 98% rename from packages/desktop/src/DesktopInterface.tsx rename to packages/desktop/src/app.tsx index 31d52863d..0ca4d5e6b 100644 --- a/packages/desktop/src/DesktopInterface.tsx +++ b/packages/desktop/src/app.tsx @@ -24,7 +24,7 @@ const url = ? `http://${host}:${port}` : "/") -export function DesktopInterface() { +export function App() { return ( diff --git a/packages/desktop/src/context/platform.tsx b/packages/desktop/src/context/platform.tsx new file mode 100644 index 000000000..21be49cbd --- /dev/null +++ b/packages/desktop/src/context/platform.tsx @@ -0,0 +1,25 @@ +import { createSimpleContext } from "@opencode-ai/ui/context" + +export type Platform = { + /** Platform discriminator */ + platform: "web" | "tauri" + + /** Open native directory picker dialog (Tauri only) */ + openDirectoryPickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise + + /** Open native file picker dialog (Tauri only) */ + openFilePickerDialog?(opts?: { title?: string; multiple?: boolean }): Promise + + /** Save file picker dialog (Tauri only) */ + saveFilePickerDialog?(opts?: { title?: string; defaultPath?: string }): Promise + + /** Open a URL in the default browser */ + openLink(url: string): void +} + +export const { use: usePlatform, provider: PlatformProvider } = createSimpleContext({ + name: "Platform", + init: (props: { value: Platform }) => { + return props.value + }, +}) diff --git a/packages/desktop/src/entry.tsx b/packages/desktop/src/entry.tsx index 82c5dd331..eec6396e9 100644 --- a/packages/desktop/src/entry.tsx +++ b/packages/desktop/src/entry.tsx @@ -1,7 +1,7 @@ // @refresh reload import { render } from "solid-js/web" -import { DesktopInterface } from "@/DesktopInterface" -import { Platform, PlatformProvider } from "@/PlatformContext" +import { App } from "@/app" +import { Platform, PlatformProvider } from "@/context/platform" const root = document.getElementById("root") if (import.meta.env.DEV && !(root instanceof HTMLElement)) { @@ -10,12 +10,17 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) { ) } -const platform: Platform = {} +const platform: Platform = { + platform: "web", + openLink(url: string) { + window.open(url, "_blank") + }, +} render( () => ( - + ), root!, diff --git a/packages/desktop/src/index.ts b/packages/desktop/src/index.ts index 2142e4886..cf5be9f51 100644 --- a/packages/desktop/src/index.ts +++ b/packages/desktop/src/index.ts @@ -1,2 +1,2 @@ -export { PlatformProvider, type Platform } from "./PlatformContext" -export { DesktopInterface } from "./DesktopInterface" +export { PlatformProvider, type Platform } from "./context/platform" +export { App } from "./app" diff --git a/packages/desktop/src/pages/layout.tsx b/packages/desktop/src/pages/layout.tsx index 03eeedfb1..25e3aafb6 100644 --- a/packages/desktop/src/pages/layout.tsx +++ b/packages/desktop/src/pages/layout.tsx @@ -196,7 +196,7 @@ export default function Layout(props: ParentProps) { return ( - +