Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

test(desktop): cover activity exit and quick restarts

leepokai6267210257e2
diff --git a/apps/desktop/src/renderer/components/Overlay.tsx b/apps/desktop/src/renderer/components/Overlay.tsx
index 7ca4d089..915f309b 100644
--- a/apps/desktop/src/renderer/components/Overlay.tsx
+++ b/apps/desktop/src/renderer/components/Overlay.tsx
@@ -1,6 +1,7 @@
import { createContext, useContext, useEffect, useId, useLayoutEffect, useRef, useState, type ReactElement, type ReactNode, type RefObject } from 'react'
import { createPortal } from 'react-dom'
import { reduceMotion } from '../lib/theme'
+import { afterExit } from '../lib/exit-delay'
import { Icon } from './Icon'
import { HStack, VStack } from './Stack'
import { Text } from './Text'
@@ -26,8 +27,7 @@ export function usePresence(open: boolean, exitMs = 300, animateOnMount = true)
}
}
setShown(false)
- const timer = setTimeout(() => setMounted(false), reduceMotion() ? 0 : exitMs)
- return () => clearTimeout(timer)
+ return afterExit(exitMs, () => setMounted(false))
}, [open, exitMs])
return { mounted, shown }
}
diff --git a/apps/desktop/src/renderer/lib/exit-delay.ts b/apps/desktop/src/renderer/lib/exit-delay.ts
new file mode 100644
index 00000000..268b6b4d
--- /dev/null
+++ b/apps/desktop/src/renderer/lib/exit-delay.ts
@@ -0,0 +1,5 @@
+/** Hold exiting content until its animation ends; reopening cancels the pending removal. */
+export function afterExit(duration: number, remove: () => void): () => void {
+ const timer = setTimeout(remove, duration)
+ return () => clearTimeout(timer)
+}
diff --git a/apps/desktop/src/renderer/views/thread/WorkingTransition.tsx b/apps/desktop/src/renderer/views/thread/WorkingTransition.tsx
index f1af1431..1c732751 100644
--- a/apps/desktop/src/renderer/views/thread/WorkingTransition.tsx
+++ b/apps/desktop/src/renderer/views/thread/WorkingTransition.tsx
@@ -2,21 +2,20 @@ import { useLayoutEffect, useRef } from 'react'
import type { Bot } from '@shared/models'
import { usePresence } from '../../components/Overlay'
import { WorkingIndicator } from './ChatRows'
+import { workingExitMs, workingTransition } from './working-transition'
/** Keep the activity and its space alive until the exit finishes, including a quick restart. */
export function WorkingTransition({ bot, visible }: { bot: Bot; visible: boolean }) {
// Matches --working-duration; initial history appears without an entrance animation.
- const presence = usePresence(visible, 420, false)
+ const presence = usePresence(visible, workingExitMs, false)
const lastActive = useRef(bot)
- useLayoutEffect(() => {
- if (visible) lastActive.current = bot
- }, [bot, visible])
- const active = visible ? bot : lastActive.current
+ const { active, indicator } = workingTransition(bot, lastActive.current, visible, presence.mounted)
+ useLayoutEffect(() => { lastActive.current = active }, [active])
return (
<div className={`chat-working ${presence.shown ? 'shown' : ''}`} inert={!visible} aria-hidden={!visible}>
<div className="chat-working-clip">
<div className="chat-working-content">
- {presence.mounted ? <WorkingIndicator bot={active} /> : null}
+ {indicator ? <WorkingIndicator bot={indicator} /> : null}
</div>
</div>
</div>
diff --git a/apps/desktop/src/renderer/views/thread/working-transition.test.ts b/apps/desktop/src/renderer/views/thread/working-transition.test.ts
new file mode 100644
index 00000000..4ad89e9d
--- /dev/null
+++ b/apps/desktop/src/renderer/views/thread/working-transition.test.ts
@@ -0,0 +1,38 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { normalizeBot } from '../../../shared/models.ts'
+import { afterExit } from '../../lib/exit-delay.ts'
+import { workingExitMs, workingTransition } from './working-transition.ts'
+
+const working = (startedAt: number) => normalizeBot({ id: 'bot', name: 'Bot', startedAt, status: 'working' })
+const finished = normalizeBot({ id: 'bot', name: 'Bot', status: 'idle' })
+
+test('finished activity keeps its last working bot for 420 ms, then leaves', (t) => {
+ t.mock.timers.enable({ apis: ['setTimeout'] })
+ const live = working(100)
+ let mounted = true
+ const cancel = afterExit(workingExitMs, () => { mounted = false })
+ const shown = () => workingTransition(finished, live, false, mounted).indicator
+ assert.equal(shown(), live)
+ t.mock.timers.tick(419)
+ assert.equal(shown()?.startedAt, 100)
+ t.mock.timers.tick(1)
+ assert.equal(shown(), null)
+ cancel()
+})
+
+test('restarting during exit cancels removal and retains the new activity on its next exit', (t) => {
+ t.mock.timers.enable({ apis: ['setTimeout'] })
+ const previous = working(100)
+ let mounted = true
+ const cancel = afterExit(workingExitMs, () => { mounted = false })
+ t.mock.timers.tick(200)
+ assert.equal(workingTransition(finished, previous, false, mounted).indicator, previous)
+ cancel() // usePresence effect cleanup when visible becomes true again.
+ const restarted = working(200)
+ const next = workingTransition(restarted, previous, true, mounted)
+ assert.equal(next.indicator, restarted)
+ t.mock.timers.tick(1000)
+ assert.equal(mounted, true)
+ assert.equal(workingTransition(finished, next.active, false, mounted).indicator, restarted)
+})
diff --git a/apps/desktop/src/renderer/views/thread/working-transition.ts b/apps/desktop/src/renderer/views/thread/working-transition.ts
new file mode 100644
index 00000000..49906f36
--- /dev/null
+++ b/apps/desktop/src/renderer/views/thread/working-transition.ts
@@ -0,0 +1,10 @@
+import type { Bot } from '../../../shared/models.ts'
+
+/** Matches --working-duration in thread.css. */
+export const workingExitMs = 420
+
+/** Preserve the last live bot through exit, until its animation has finished. */
+export function workingTransition(current: Bot, previous: Bot, visible: boolean, mounted: boolean) {
+ const active = visible ? current : previous
+ return { active, indicator: mounted ? active : null }
+}