Skip to content

Commit 687210a

Browse files
feat(desktop): add isSidecar prop to AppInterface and logic to persist sidecar server urls (#12366)
Co-authored-by: Brendan Allan <git@brendonovich.dev>
1 parent b12eab7 commit 687210a

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

packages/app/src/app.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ function ServerKey(props: ParentProps) {
8484
)
8585
}
8686

87-
export function AppInterface(props: { defaultUrl?: string; children?: JSX.Element }) {
87+
88+
export function AppInterface(props: { defaultUrl?: string; children?: JSX.Element; isSidecar?: boolean }) {
8889
const platform = usePlatform()
8990

9091
const stored = (() => {
@@ -106,7 +107,7 @@ export function AppInterface(props: { defaultUrl?: string; children?: JSX.Elemen
106107
}
107108

108109
return (
109-
<ServerProvider defaultUrl={defaultServerUrl()}>
110+
<ServerProvider defaultUrl={defaultServerUrl()} isSidecar={props.isSidecar}>
110111
<ServerKey>
111112
<GlobalSDKProvider>
112113
<GlobalSyncProvider>

packages/app/src/context/server.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function projectsKey(url: string) {
2828

2929
export const { use: useServer, provider: ServerProvider } = createSimpleContext({
3030
name: "Server",
31-
init: (props: { defaultUrl: string }) => {
31+
init: (props: { defaultUrl: string, isSidecar?: boolean }) => {
3232
const platform = usePlatform()
3333

3434
const [store, setStore, _, ready] = persisted(
@@ -59,7 +59,13 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
5959

6060
const fallback = normalizeServerUrl(props.defaultUrl)
6161
if (fallback && url === fallback) {
62-
setState("active", url)
62+
batch(() => {
63+
if (!store.list.includes(url)) {
64+
// Add the fallback url to the list if it's not already in the list
65+
setStore("list", store.list.length, url)
66+
}
67+
setState("active", url)
68+
})
6369
return
6470
}
6571

@@ -89,7 +95,17 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
8995
if (state.active) return
9096
const url = normalizeServerUrl(props.defaultUrl)
9197
if (!url) return
92-
setState("active", url)
98+
batch(() => {
99+
100+
// Add the new sidecar url
101+
if(props.isSidecar && props.defaultUrl) {
102+
add(props.defaultUrl)
103+
}
104+
105+
setState("active", url)
106+
})
107+
108+
console.log(store.list)
93109
})
94110

95111
const isReady = createMemo(() => ready() && !!state.active)

packages/desktop/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ render(() => {
404404
window.__OPENCODE__ ??= {}
405405
window.__OPENCODE__.serverPassword = data().password ?? undefined
406406

407+
407408
function Inner() {
408409
const cmd = useCommand()
409410

@@ -413,7 +414,7 @@ render(() => {
413414
}
414415

415416
return (
416-
<AppInterface defaultUrl={data().url}>
417+
<AppInterface defaultUrl={data().url} isSidecar>
417418
<Inner />
418419
</AppInterface>
419420
)

0 commit comments

Comments
 (0)