Browse Source

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

Co-authored-by: Brendan Allan <[email protected]>
OpeOginni 2 weeks ago
parent
commit
687210a55d
3 changed files with 24 additions and 6 deletions
  1. 3 2
      packages/app/src/app.tsx
  2. 19 3
      packages/app/src/context/server.tsx
  3. 2 1
      packages/desktop/src/index.tsx

+ 3 - 2
packages/app/src/app.tsx

@@ -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>

+ 19 - 3
packages/app/src/context/server.tsx

@@ -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)

+ 2 - 1
packages/desktop/src/index.tsx

@@ -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>
             )
             )