tui: pass dynamic port to frontend

Frontend now receives the server port via window.__OPENCODE__.port,
allowing it to connect when using a random free port instead of hardcoded 4096
This commit is contained in:
Dax Raad 2025-12-10 16:17:27 -05:00
parent 58e66dd3d1
commit 86f7cc17ae
3 changed files with 9 additions and 8 deletions

View file

@ -15,8 +15,14 @@ import { GlobalSDKProvider } from "./context/global-sdk"
import { SessionProvider } from "./context/session"
import { Show } from "solid-js"
declare global {
interface Window {
__OPENCODE__?: { updaterEnabled?: boolean; port?: number }
}
}
const host = import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "127.0.0.1"
const port = import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"
const port = window.__OPENCODE__?.port ?? import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"
const url =
new URLSearchParams(document.location.search).get("url") ||

View file

@ -175,7 +175,8 @@ pub fn run() {
.initialization_script(format!(
r#"
window.__OPENCODE__ ??= {{}};
window.__OPENCODE__.updaterEnabled = {updater_enabled}
window.__OPENCODE__.updaterEnabled = {updater_enabled};
window.__OPENCODE__.port = {port};
"#
));

View file

@ -47,12 +47,6 @@ const platform: Platform = {
},
}
declare global {
interface Window {
__OPENCODE__?: { updaterEnabled?: boolean }
}
}
render(() => {
onMount(() => {
if (window.__OPENCODE__?.updaterEnabled) runUpdater()