summaryrefslogtreecommitdiffhomepage
path: root/packages/desktop
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2025-12-08 13:43:36 +0800
committerBrendan Allan <[email protected]>2025-12-08 13:43:36 +0800
commitd531dff8d3f5c60df2e5c08e8bd04bf9a234dbc3 (patch)
tree7c38fd75c3e6f04307b78abe7a93c8321e041143 /packages/desktop
parent923bf36593e517196a332ddce2ffe5f2fd216f5e (diff)
downloadopencode-d531dff8d3f5c60df2e5c08e8bd04bf9a234dbc3.tar.gz
opencode-d531dff8d3f5c60df2e5c08e8bd04bf9a234dbc3.zip
Export DesktopInterface from desktop and add PlatformContext
Diffstat (limited to 'packages/desktop')
-rw-r--r--packages/desktop/index.html2
-rw-r--r--packages/desktop/package.json2
-rw-r--r--packages/desktop/src/DesktopInterface.tsx (renamed from packages/desktop/src/index.tsx)18
-rw-r--r--packages/desktop/src/PlatformContext.tsx14
-rw-r--r--packages/desktop/src/entry.tsx22
-rw-r--r--packages/desktop/src/index.ts2
6 files changed, 44 insertions, 16 deletions
diff --git a/packages/desktop/index.html b/packages/desktop/index.html
index 0ac3d566d..b9d3e5351 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.json
index a71a33fe8..f71f33eda 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.tsx
index 3c21b9a37..c4de3e089 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.tsx
new file mode 100644
index 000000000..5b510a8d4
--- /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.tsx
new file mode 100644
index 000000000..82c5dd331
--- /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.ts
new file mode 100644
index 000000000..2142e4886
--- /dev/null
+++ b/packages/desktop/src/index.ts
@@ -0,0 +1,2 @@
+export { PlatformProvider, type Platform } from "./PlatformContext"
+export { DesktopInterface } from "./DesktopInterface"