feat(desktop): add isSidecar prop to AppInterface and logic to persist sidecar server urls (#12366)

Co-authored-by: Brendan Allan <git@brendonovich.dev>
This commit is contained in:
OpeOginni
2026-02-09 08:18:06 +01:00
committed by GitHub
parent b12eab782f
commit 687210a55d
3 changed files with 24 additions and 6 deletions

View File

@@ -84,7 +84,8 @@ function ServerKey(props: ParentProps) {
) )
} }
export function AppInterface(props: { defaultUrl?: string; children?: JSX.Element }) {
export function AppInterface(props: { defaultUrl?: string; children?: JSX.Element; isSidecar?: boolean }) {
const platform = usePlatform() const platform = usePlatform()
const stored = (() => { const stored = (() => {
@@ -106,7 +107,7 @@ export function AppInterface(props: { defaultUrl?: string; children?: JSX.Elemen
} }
return ( return (
<ServerProvider defaultUrl={defaultServerUrl()}> <ServerProvider defaultUrl={defaultServerUrl()} isSidecar={props.isSidecar}>
<ServerKey> <ServerKey>
<GlobalSDKProvider> <GlobalSDKProvider>
<GlobalSyncProvider> <GlobalSyncProvider>

View File

@@ -28,7 +28,7 @@ function projectsKey(url: string) {
export const { use: useServer, provider: ServerProvider } = createSimpleContext({ export const { use: useServer, provider: ServerProvider } = createSimpleContext({
name: "Server", name: "Server",
init: (props: { defaultUrl: string }) => { init: (props: { defaultUrl: string, isSidecar?: boolean }) => {
const platform = usePlatform() const platform = usePlatform()
const [store, setStore, _, ready] = persisted( const [store, setStore, _, ready] = persisted(
@@ -59,7 +59,13 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
const fallback = normalizeServerUrl(props.defaultUrl) const fallback = normalizeServerUrl(props.defaultUrl)
if (fallback && url === fallback) { if (fallback && url === fallback) {
setState("active", url) batch(() => {
if (!store.list.includes(url)) {
// Add the fallback url to the list if it's not already in the list
setStore("list", store.list.length, url)
}
setState("active", url)
})
return return
} }
@@ -89,7 +95,17 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
if (state.active) return if (state.active) return
const url = normalizeServerUrl(props.defaultUrl) const url = normalizeServerUrl(props.defaultUrl)
if (!url) return if (!url) return
setState("active", url) batch(() => {
// Add the new sidecar url
if(props.isSidecar && props.defaultUrl) {
add(props.defaultUrl)
}
setState("active", url)
})
console.log(store.list)
}) })
const isReady = createMemo(() => ready() && !!state.active) const isReady = createMemo(() => ready() && !!state.active)

View File

@@ -404,6 +404,7 @@ render(() => {
window.__OPENCODE__ ??= {} window.__OPENCODE__ ??= {}
window.__OPENCODE__.serverPassword = data().password ?? undefined window.__OPENCODE__.serverPassword = data().password ?? undefined
function Inner() { function Inner() {
const cmd = useCommand() const cmd = useCommand()
@@ -413,7 +414,7 @@ render(() => {
} }
return ( return (
<AppInterface defaultUrl={data().url}> <AppInterface defaultUrl={data().url} isSidecar>
<Inner /> <Inner />
</AppInterface> </AppInterface>
) )