The open source coding agent.
TypeScript
Export DesktopInterface from desktop and add PlatformContext
Brendan Alland531dff8d3f5
diff --git a/packages/desktop/index.html b/packages/desktop/index.htmlindex 0ac3d566d2a..b9d3e535120 100644--- a/packages/desktop/index.html+++ b/packages/desktop/index.html@@ -23,6 +23,6 @@</script><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div>- <script src="/src/index.tsx" type="module"></script>+ <script src="/src/entry.tsx" type="module"></script></body></html>diff --git a/packages/desktop/package.json b/packages/desktop/package.jsonindex a71a33fe8da..f71f33eda1e 100644--- a/packages/desktop/package.json+++ b/packages/desktop/package.json@@ -4,7 +4,7 @@"description": "","type": "module","exports": {- ".": "./src/index.tsx",+ ".": "./src/index.ts","./vite": "./vite.js"},"scripts": {diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/DesktopInterface.tsxsimilarity index 88%rename from packages/desktop/src/index.tsxrename to packages/desktop/src/DesktopInterface.tsxindex 3c21b9a37d7..c4de3e089cd 100644--- a/packages/desktop/src/index.tsx+++ b/packages/desktop/src/DesktopInterface.tsx@@ -1,6 +1,4 @@-/* @refresh reload */import "@/index.css"-import { render } from "solid-js/web"import { Router, Route, Navigate } from "@solidjs/router"import { MetaProvider } from "@solidjs/meta"import { Font } from "@opencode-ai/ui/font"@@ -27,15 +25,8 @@ const url =? `http://${host}:${port}`: "/")-const root = document.getElementById("root")-if (import.meta.env.DEV && !(root instanceof HTMLElement)) {- throw new Error(- "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",- )-}--render(- () => (+export function DesktopInterface() {+ return (<MarkedProvider><DiffComponentProvider component={Diff}><GlobalSDKProvider url={url}>@@ -72,6 +63,5 @@ render(</GlobalSDKProvider></DiffComponentProvider></MarkedProvider>- ),- root!,-)+ )+}diff --git a/packages/desktop/src/PlatformContext.tsx b/packages/desktop/src/PlatformContext.tsxnew file mode 100644index 00000000000..5b510a8d457--- /dev/null+++ b/packages/desktop/src/PlatformContext.tsx@@ -0,0 +1,14 @@+import { createContext } from "solid-js"+import { useContext } from "solid-js"++export interface Platform {}++const PlatformContext = createContext<Platform>()++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/entry.tsx b/packages/desktop/src/entry.tsxnew file mode 100644index 00000000000..82c5dd33137--- /dev/null+++ b/packages/desktop/src/entry.tsx@@ -0,0 +1,22 @@+// @refresh reload+import { render } from "solid-js/web"+import { DesktopInterface } from "@/DesktopInterface"+import { Platform, PlatformProvider } from "@/PlatformContext"++const root = document.getElementById("root")+if (import.meta.env.DEV && !(root instanceof HTMLElement)) {+ throw new Error(+ "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",+ )+}++const platform: Platform = {}++render(+ () => (+ <PlatformProvider value={platform}>+ <DesktopInterface />+ </PlatformProvider>+ ),+ root!,+)diff --git a/packages/desktop/src/index.ts b/packages/desktop/src/index.tsnew file mode 100644index 00000000000..2142e488626--- /dev/null+++ b/packages/desktop/src/index.ts@@ -0,0 +1,2 @@+export { PlatformProvider, type Platform } from "./PlatformContext"+export { DesktopInterface } from "./DesktopInterface"diff --git a/packages/tauri/index.html b/packages/tauri/index.htmlindex 898aec67a0e..0ac3d566d2a 100644--- a/packages/tauri/index.html+++ b/packages/tauri/index.html@@ -23,6 +23,6 @@</script><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div>- <script src="/src/index.ts" type="module"></script>+ <script src="/src/index.tsx" type="module"></script></body></html>diff --git a/packages/tauri/src-tauri/src/lib.rs b/packages/tauri/src-tauri/src/lib.rsindex bada4dee2d3..1809d2f8b47 100644--- a/packages/tauri/src-tauri/src/lib.rs+++ b/packages/tauri/src-tauri/src/lib.rs@@ -4,7 +4,7 @@ use std::{sync::{Arc, Mutex},time::{Duration, Instant},};-use tauri::{App, AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindow};+use tauri::{AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindow};use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogResult};use tauri_plugin_shell::process::{CommandChild, CommandEvent};use tauri_plugin_shell::ShellExt;diff --git a/packages/tauri/src/index.ts b/packages/tauri/src/index.tsdeleted file mode 100644index b9060d6285b..00000000000--- a/packages/tauri/src/index.ts+++ /dev/null@@ -1 +0,0 @@-import "@opencode-ai/desktop"diff --git a/packages/tauri/src/index.tsx b/packages/tauri/src/index.tsxnew file mode 100644index 00000000000..9371b48260c--- /dev/null+++ b/packages/tauri/src/index.tsx@@ -0,0 +1,21 @@+// @refresh reload+import { render } from "solid-js/web"+import { DesktopInterface, PlatformProvider, Platform } from "@opencode-ai/desktop"++const root = document.getElementById("root")+if (import.meta.env.DEV && !(root instanceof HTMLElement)) {+ throw new Error(+ "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",+ )+}++const platform: Platform = {}++render(+ () => (+ <PlatformProvider value={platform}>+ <DesktopInterface />+ </PlatformProvider>+ ),+ root!,+)diff --git a/packages/tauri/tsconfig.json b/packages/tauri/tsconfig.jsonindex 75abdef2659..cf73096e571 100644--- a/packages/tauri/tsconfig.json+++ b/packages/tauri/tsconfig.json@@ -17,7 +17,10 @@"strict": true,"noUnusedLocals": true,"noUnusedParameters": true,- "noFallthroughCasesInSwitch": true+ "noFallthroughCasesInSwitch": true,++ "jsx": "preserve",+ "jsxImportSource": "solid-js"},"include": ["src"]}