Skip to content

The agent that grows with you

fix(desktop): skip source restore in auxiliary windows

Gille9ae724761696
diff --git a/apps/desktop/src/app/chat/sidebar/connection-switcher.test.tsx b/apps/desktop/src/app/chat/sidebar/connection-switcher.test.tsx
index 79acb22e862..fa0af2324fb 100644
--- a/apps/desktop/src/app/chat/sidebar/connection-switcher.test.tsx
+++ b/apps/desktop/src/app/chat/sidebar/connection-switcher.test.tsx
@@ -41,6 +41,7 @@ vi.mock('@/store/boot', () => ({
}))
vi.mock('@/store/windows', () => ({
+ isAuxiliaryWindow: vi.fn(() => false),
isPeerInstanceWindow: vi.fn(() => false)
}))
@@ -77,6 +78,7 @@ const $pendingConnectionId = connectionStore.$pendingConnectionId
const initializeConnectionsRegistry = vi.mocked(connectionStore.initializeConnectionsRegistry)
const refreshConnectionsRegistry = vi.mocked(connectionStore.refreshConnectionsRegistry)
const selectConnection = vi.mocked(connectionStore.selectConnection)
+const isAuxiliaryWindow = vi.mocked(windowStore.isAuxiliaryWindow)
const isPeerInstanceWindow = vi.mocked(windowStore.isPeerInstanceWindow)
const onConnect = vi.fn()
@@ -112,6 +114,7 @@ afterEach(() => {
})
$pendingConnectionId.set(null)
$findInPage.set({ active: false, query: '', matchOrdinal: 0, matchCount: 0 })
+ isAuxiliaryWindow.mockReturnValue(false)
isPeerInstanceWindow.mockReturnValue(false)
})
@@ -150,6 +153,22 @@ describe('ConnectionSwitcher', () => {
expect(initializeConnectionsRegistry).not.toHaveBeenCalled()
})
+ it('keeps a secondary session window from replaying app-launch source restoration', async () => {
+ isAuxiliaryWindow.mockReturnValue(true)
+ $desktopBoot.set({
+ ...$desktopBoot.get(),
+ phase: 'renderer.ready',
+ progress: 100,
+ running: false,
+ visible: false
+ })
+
+ render(<ConnectionSwitcher onConnect={onConnect} />)
+
+ await waitFor(() => expect(refreshConnectionsRegistry).toHaveBeenCalledTimes(1))
+ expect(initializeConnectionsRegistry).not.toHaveBeenCalled()
+ })
+
it('adds no source chrome for a local-only setup', () => {
$connectionsRegistry.set(registry([connection('local', 'This device', 'local')]))
render(<ConnectionSwitcher onConnect={onConnect} />)
diff --git a/apps/desktop/src/app/chat/sidebar/connection-switcher.tsx b/apps/desktop/src/app/chat/sidebar/connection-switcher.tsx
index 22f559e7e33..ce0e56b801b 100644
--- a/apps/desktop/src/app/chat/sidebar/connection-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/connection-switcher.tsx
@@ -36,7 +36,7 @@ import {
} from '@/store/connections'
import { closeFindBar } from '@/store/find-in-page'
import { notifyError } from '@/store/notifications'
-import { isPeerInstanceWindow } from '@/store/windows'
+import { isAuxiliaryWindow, isPeerInstanceWindow } from '@/store/windows'
export function ConnectionSwitcher({ compact = false, onConnect }: { compact?: boolean; onConnect: () => void }) {
const { t } = useI18n()
@@ -65,10 +65,10 @@ export function ConnectionSwitcher({ compact = false, onConnect }: { compact?: b
// The primary boot owns its initial config/session fetches. Restoring a
// different source before those settle lets a late primary response repaint
// the sidebar under the new source label. Switch only after boot completes,
- // then the normal source reset/refetch remains the final writer. Full peer
- // windows already joined the shared backend during their own boot; replaying
- // this app-launch preference there would move them away from that backend.
- if (!boot.running && !isPeerInstanceWindow()) {
+ // then the normal source reset/refetch remains the final writer. Peer and
+ // auxiliary windows already boot into their intended runtime; replaying the
+ // primary window's app-launch preference would move them away from it.
+ if (!boot.running && !isAuxiliaryWindow() && !isPeerInstanceWindow()) {
void initializeConnectionsRegistry().catch(() => undefined)
}
}, [boot.running])