summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/entry.tsx
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2026-03-12 16:10:52 +0800
committerGitHub <[email protected]>2026-03-12 08:10:52 +0000
commitb76ead3fe80a6159fdbfcc9b82c7c6318be68e7f (patch)
treebad16ba8185403eb9dc97b6c996bbfa78ae7918b /packages/app/src/entry.tsx
parent51835ecf90e23b34957f4dde843bbba1134f17fe (diff)
downloadopencode-b76ead3fe80a6159fdbfcc9b82c7c6318be68e7f.tar.gz
opencode-b76ead3fe80a6159fdbfcc9b82c7c6318be68e7f.zip
refactor(desktop): rework default server initialization and connection handling (#16965)
Diffstat (limited to 'packages/app/src/entry.tsx')
-rw-r--r--packages/app/src/entry.tsx33
1 files changed, 20 insertions, 13 deletions
diff --git a/packages/app/src/entry.tsx b/packages/app/src/entry.tsx
index e9c0a4397..c62baccba 100644
--- a/packages/app/src/entry.tsx
+++ b/packages/app/src/entry.tsx
@@ -98,6 +98,19 @@ if (!(root instanceof HTMLElement) && import.meta.env.DEV) {
throw new Error(getRootNotFoundError())
}
+const getCurrentUrl = () => {
+ if (location.hostname.includes("opencode.ai")) return "http://localhost:4096"
+ if (import.meta.env.DEV)
+ return `http://${import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "localhost"}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}`
+ return location.origin
+}
+
+const getDefaultUrl = () => {
+ const lsDefault = readDefaultServerUrl()
+ if (lsDefault) return lsDefault
+ return getCurrentUrl()
+}
+
const platform: Platform = {
platform: "web",
version: pkg.version,
@@ -106,26 +119,20 @@ const platform: Platform = {
forward,
restart,
notify,
- getDefaultServerUrl: async () => readDefaultServerUrl(),
- setDefaultServerUrl: writeDefaultServerUrl,
+ getDefaultServer: async () => {
+ const stored = readDefaultServerUrl()
+ return stored ? ServerConnection.Key.make(stored) : null
+ },
+ setDefaultServer: writeDefaultServerUrl,
}
-const defaultUrl = iife(() => {
- const lsDefault = readDefaultServerUrl()
- if (lsDefault) return lsDefault
- if (location.hostname.includes("opencode.ai")) return "http://localhost:4096"
- if (import.meta.env.DEV)
- return `http://${import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "localhost"}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}`
- return location.origin
-})
-
if (root instanceof HTMLElement) {
- const server: ServerConnection.Http = { type: "http", http: { url: defaultUrl } }
+ const server: ServerConnection.Http = { type: "http", http: { url: getCurrentUrl() } }
render(
() => (
<PlatformProvider value={platform}>
<AppBaseProviders>
- <AppInterface defaultServer={ServerConnection.key(server)} servers={[server]} />
+ <AppInterface defaultServer={ServerConnection.Key.make(getDefaultUrl())} servers={[server]} />
</AppBaseProviders>
</PlatformProvider>
),