Skip to content

Commit d531dff

Browse files
committed
Export DesktopInterface from desktop and add PlatformContext
1 parent 923bf36 commit d531dff

File tree

11 files changed

+71
-20
lines changed

11 files changed

+71
-20
lines changed

packages/desktop/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
</script>
2424
<noscript>You need to enable JavaScript to run this app.</noscript>
2525
<div id="root"></div>
26-
<script src="/src/index.tsx" type="module"></script>
26+
<script src="/src/entry.tsx" type="module"></script>
2727
</body>
2828
</html>

packages/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"type": "module",
66
"exports": {
7-
".": "./src/index.tsx",
7+
".": "./src/index.ts",
88
"./vite": "./vite.js"
99
},
1010
"scripts": {
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* @refresh reload */
21
import "@/index.css"
3-
import { render } from "solid-js/web"
42
import { Router, Route, Navigate } from "@solidjs/router"
53
import { MetaProvider } from "@solidjs/meta"
64
import { Font } from "@opencode-ai/ui/font"
@@ -27,15 +25,8 @@ const url =
2725
? `http://${host}:${port}`
2826
: "/")
2927

30-
const root = document.getElementById("root")
31-
if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
32-
throw new Error(
33-
"Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
34-
)
35-
}
36-
37-
render(
38-
() => (
28+
export function DesktopInterface() {
29+
return (
3930
<MarkedProvider>
4031
<DiffComponentProvider component={Diff}>
4132
<GlobalSDKProvider url={url}>
@@ -72,6 +63,5 @@ render(
7263
</GlobalSDKProvider>
7364
</DiffComponentProvider>
7465
</MarkedProvider>
75-
),
76-
root!,
77-
)
66+
)
67+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createContext } from "solid-js"
2+
import { useContext } from "solid-js"
3+
4+
export interface Platform {}
5+
6+
const PlatformContext = createContext<Platform>()
7+
8+
export const PlatformProvider = PlatformContext.Provider
9+
10+
export function usePlatform() {
11+
const ctx = useContext(PlatformContext)
12+
if (!ctx) throw new Error("usePlatform must be used within a PlatformProvider")
13+
return ctx
14+
}

packages/desktop/src/entry.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @refresh reload
2+
import { render } from "solid-js/web"
3+
import { DesktopInterface } from "@/DesktopInterface"
4+
import { Platform, PlatformProvider } from "@/PlatformContext"
5+
6+
const root = document.getElementById("root")
7+
if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
8+
throw new Error(
9+
"Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
10+
)
11+
}
12+
13+
const platform: Platform = {}
14+
15+
render(
16+
() => (
17+
<PlatformProvider value={platform}>
18+
<DesktopInterface />
19+
</PlatformProvider>
20+
),
21+
root!,
22+
)

packages/desktop/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { PlatformProvider, type Platform } from "./PlatformContext"
2+
export { DesktopInterface } from "./DesktopInterface"

packages/tauri/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
</script>
2424
<noscript>You need to enable JavaScript to run this app.</noscript>
2525
<div id="root"></div>
26-
<script src="/src/index.ts" type="module"></script>
26+
<script src="/src/index.tsx" type="module"></script>
2727
</body>
2828
</html>

packages/tauri/src-tauri/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
sync::{Arc, Mutex},
55
time::{Duration, Instant},
66
};
7-
use tauri::{App, AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindow};
7+
use tauri::{AppHandle, Manager, RunEvent, WebviewUrl, WebviewWindow};
88
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogResult};
99
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
1010
use tauri_plugin_shell::ShellExt;

packages/tauri/src/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/tauri/src/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @refresh reload
2+
import { render } from "solid-js/web"
3+
import { DesktopInterface, PlatformProvider, Platform } from "@opencode-ai/desktop"
4+
5+
const root = document.getElementById("root")
6+
if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
7+
throw new Error(
8+
"Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
9+
)
10+
}
11+
12+
const platform: Platform = {}
13+
14+
render(
15+
() => (
16+
<PlatformProvider value={platform}>
17+
<DesktopInterface />
18+
</PlatformProvider>
19+
),
20+
root!,
21+
)

0 commit comments

Comments
 (0)