Skip to content

The agent that grows with you

simplify(desktop): a layout preview writes and restores the saved layout like any change

alt-glitchd16f9fcab568
diff --git a/apps/desktop/src/components/onboarding/first-run/assembly.ts b/apps/desktop/src/components/onboarding/first-run/assembly.ts
index 88be62a5943..e759f1f9814 100644
--- a/apps/desktop/src/components/onboarding/first-run/assembly.ts
+++ b/apps/desktop/src/components/onboarding/first-run/assembly.ts
@@ -25,21 +25,12 @@ import { $chatOnboardingSolo, $introView } from '@/store/onboarding-intro'
import { $paneStates, type PaneStateSnapshot } from '@/store/panes'
import { $activeSessionId, $selectedStoredSessionId } from '@/store/session'
-// Layout previews open now; until Continue or cancel their arrangement stays in memory.
-let previews = 0
-
-// The demo and a preview are borrowed: nothing they change is persisted as the user's layout.
-function holdLayout(): void {
- modeLayout.hold($chatOnboardingSolo.get() || previews > 0)
-}
-
+// The demo is borrowed: nothing it changes is persisted as the user's layout.
$chatOnboardingSolo.subscribe(solo => {
- holdLayout()
+ modeLayout.hold(solo)
document.documentElement.toggleAttribute('data-onboarding-demo', solo)
})
-export const isLayoutPreviewing = (): boolean => previews > 0
-
export const $chatOnboardingThreadIds = atom<readonly string[]>([])
export const $chatLayoutPicked = atom(false)
@@ -166,7 +157,7 @@ export interface PreviewUndo {
}
/** A layout preview's undo. A preview never switches Simple/Advanced and never ends the intro, so the
- * arrangement is all there is to put back; nothing is saved until Continue keeps it. */
+ * arrangement is all there is to put back. */
export function snapshotChatLayout(): PreviewUndo {
const snapshot = {
id: $activePresetId.get(),
@@ -175,20 +166,13 @@ export function snapshotChatLayout(): PreviewUndo {
tree: $layoutTree.get()
}
- previews += 1
- holdLayout()
-
- const settle = () => {
- previews -= 1
- holdLayout()
- }
-
const restore = () => {
if (snapshot.tree) {
$layoutTree.set(snapshot.tree)
$paneStates.set(snapshot.panes)
$userPlacedPanes.set(snapshot.placed)
markActivePreset(snapshot.id)
+ persistTree()
}
}
@@ -197,20 +181,10 @@ export function snapshotChatLayout(): PreviewUndo {
// for the mode it leaves, not the preview.
keep: send => {
restore()
- const sent = send()
-
- if (sent) {
- settle()
- modeLayout.flush()
- }
- return sent
+ return send()
},
- // Settled after the restore, so the restore's own changes do not read as the user leaving the intro.
- revert: () => {
- restore()
- settle()
- }
+ revert: restore
}
}
diff --git a/apps/desktop/src/components/onboarding/first-run/intro.ts b/apps/desktop/src/components/onboarding/first-run/intro.ts
index cfe9d57983e..a7dca3d9abc 100644
--- a/apps/desktop/src/components/onboarding/first-run/intro.ts
+++ b/apps/desktop/src/components/onboarding/first-run/intro.ts
@@ -9,7 +9,7 @@ import { $activeGatewayProfile } from '@/store/profile'
import { $selectedStoredSessionId } from '@/store/session'
import { retireTips } from '@/store/tips'
-import { $chatOnboardingThreadIds, endChatOnboardingSolo, isLayoutPreviewing, keepChatOnboardingLayout } from './assembly'
+import { $chatOnboardingThreadIds, endChatOnboardingSolo, keepChatOnboardingLayout } from './assembly'
/**
* The intro copy over an empty onboarding chat: it types centred (`playing`), springs up and waits at
@@ -100,8 +100,7 @@ function watchLeaveActions(): () => void {
const stops = [
() => window.removeEventListener(PANE_TOGGLE_REVEAL_EVENT, onReveal),
- // A layout preview opens and closes the sidebar itself (Basic places it); only the user's toggle leaves.
- $sidebarOpen.listen(() => !isLayoutPreviewing() && leaveIntro()),
+ $sidebarOpen.listen(() => leaveIntro()),
$activeGatewayProfile.listen(profile => profile !== introProfile && leaveIntro()),
$selectedStoredSessionId.listen(id => (!id || !$chatOnboardingThreadIds.get().includes(id)) && leaveIntro())
]
diff --git a/apps/desktop/src/components/onboarding/first-run/layout.test.ts b/apps/desktop/src/components/onboarding/first-run/layout.test.ts
index f5896489452..d01447d30cd 100644
--- a/apps/desktop/src/components/onboarding/first-run/layout.test.ts
+++ b/apps/desktop/src/components/onboarding/first-run/layout.test.ts
@@ -6,7 +6,6 @@ import { applyLayoutPreset } from '@/components/pane-shell/tree/presets'
import { $activePresetId, $layoutTree } from '@/components/pane-shell/tree/store'
import { applyAppearance } from '@/store/appearance-apply'
import { $interfaceMode, setInterfaceMode } from '@/store/interface-mode'
-import { $sidebarOpen, setSidebarOpen } from '@/store/layout'
import { $chatOnboardingSolo, $introView } from '@/store/onboarding-intro'
import { openDemoLayout, snapshotChatLayout } from './assembly'
@@ -45,30 +44,6 @@ describe('first-run layout beat', () => {
expect($activePresetId.get()).toBe('sidebar-left')
})
- it('keeps the intro while a preview opens the sidebar itself', () => {
- const undo = snapshotChatLayout()
- setSidebarOpen(!$sidebarOpen.get())
- undo.revert()
-
- expect($introView.get()).toBe('intro')
- })
-
- it('saves a previewed layout only when Continue keeps it', () => {
- skipIntro()
- const writes = vi.spyOn(window.localStorage, 'setItem')
-
- const cancelled = snapshotChatLayout()
- applyLayoutPreset('picked', group(['workspace']))
- cancelled.revert()
- expect(writes).not.toHaveBeenCalled()
-
- const kept = snapshotChatLayout()
- applyLayoutPreset('picked', group(['workspace']))
- kept.keep(() => applyAppearance({ layout: 'terminal-deck' }).success)
- expect(writes).toHaveBeenCalled()
- writes.mockRestore()
- })
-
it("keeps the other mode's own layout when Continue switches modes after a preview", () => {
skipIntro()
setInterfaceMode('advanced')
diff --git a/apps/desktop/src/lib/layout-persistence.ts b/apps/desktop/src/lib/layout-persistence.ts
index 48da99b76cd..2c94b4b18fb 100644
--- a/apps/desktop/src/lib/layout-persistence.ts
+++ b/apps/desktop/src/lib/layout-persistence.ts
@@ -146,10 +146,6 @@ export function createLayoutPersistence(initialMode: InterfaceMode, persistent:
hold(next: boolean) {
held = next
},
- /** Write every value as it is now, so a change made while held is kept. */
- flush() {
- entries.forEach(entry => entry.capture())
- },
has(key: string) {
return snapshots.has(keyFor(key))
},