feat(floating-terminal): amber attention dot for unacknowledged bells and completions (#7888)
Show a small amber dot on the floating-workspace launcher (both the floating-button and status-bar triggers) whenever any floating-workspace tab still has an unacknowledged terminal bell or agent completion, and a composited amber dot on the Windows tray icon when the window is minimized/hidden. Both clear through the existing show-until-interact paths — engaging with or closing the offending tab drops the dot with no stale unread state left behind. The launcher dot derives from the existing per-tab/per-pane unread maps via a new selectFloatingWorkspaceHasUnread selector (primitive boolean, empty- workspace early return, no bespoke state). The tray dot rides the notification dispatch and clears on window show/restore.
This commit is contained in:
@@ -88,6 +88,18 @@ vi.mock('./FloatingTerminalIconContextMenu', () => ({
|
||||
}
|
||||
}))
|
||||
|
||||
const storeState = vi.hoisted(() => ({ hasFloatingUnread: false }))
|
||||
|
||||
vi.mock('@/store', () => ({
|
||||
useAppStore: <T,>(selector: (state: typeof storeState) => T): T => selector(storeState)
|
||||
}))
|
||||
|
||||
// The real selector is covered in store/selectors.test.ts; here it just reads
|
||||
// the mocked flag so the dot's show/hide logic can be exercised in isolation.
|
||||
vi.mock('@/store/selectors', () => ({
|
||||
selectFloatingWorkspaceHasUnread: (state: typeof storeState): boolean => state.hasFloatingUnread
|
||||
}))
|
||||
|
||||
function visit(node: unknown, cb: (node: ReactElementLike) => void): void {
|
||||
if (node == null || typeof node === 'string' || typeof node === 'number') {
|
||||
return
|
||||
@@ -117,6 +129,16 @@ function findByProp(node: unknown, propName: string): ReactElementLike {
|
||||
return found
|
||||
}
|
||||
|
||||
function hasProp(node: unknown, propName: string): boolean {
|
||||
let found = false
|
||||
visit(node, (entry) => {
|
||||
if (entry.props[propName]) {
|
||||
found = true
|
||||
}
|
||||
})
|
||||
return found
|
||||
}
|
||||
|
||||
function runEffects(): void {
|
||||
const layoutEffects = hookRuntime.layoutEffects.splice(0)
|
||||
for (const effect of layoutEffects) {
|
||||
@@ -233,3 +255,43 @@ describe('FloatingTerminalToggleButton positioning', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('FloatingTerminalToggleButton attention dot', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
hookRuntime.effects = []
|
||||
hookRuntime.layoutEffects = []
|
||||
hookRuntime.index = 0
|
||||
hookRuntime.values = []
|
||||
storeState.hasFloatingUnread = false
|
||||
vi.stubGlobal('window', {
|
||||
addEventListener: vi.fn(),
|
||||
innerHeight: 800,
|
||||
innerWidth: 1200,
|
||||
localStorage: { getItem: vi.fn(() => null), setItem: vi.fn() },
|
||||
removeEventListener: vi.fn()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('renders the attention dot when closed with pending floating activity', async () => {
|
||||
storeState.hasFloatingUnread = true
|
||||
const element = await renderToggle(false)
|
||||
expect(hasProp(element, 'data-floating-terminal-attention')).toBe(true)
|
||||
})
|
||||
|
||||
it('hides the dot when the panel is open even with pending activity', async () => {
|
||||
storeState.hasFloatingUnread = true
|
||||
const element = await renderToggle(true)
|
||||
expect(hasProp(element, 'data-floating-terminal-attention')).toBe(false)
|
||||
})
|
||||
|
||||
it('hides the dot when there is no pending activity', async () => {
|
||||
storeState.hasFloatingUnread = false
|
||||
const element = await renderToggle(false)
|
||||
expect(hasProp(element, 'data-floating-terminal-attention')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,6 +4,8 @@ import { Button } from '@/components/ui/button'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { FloatingTerminalIconContextMenu } from './FloatingTerminalIconContextMenu'
|
||||
import { useShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import { useAppStore } from '@/store'
|
||||
import { selectFloatingWorkspaceHasUnread } from '@/store/selectors'
|
||||
import {
|
||||
anchorFloatingTerminalTriggerPosition,
|
||||
clampFloatingTerminalTriggerPosition,
|
||||
@@ -62,6 +64,12 @@ export function FloatingTerminalToggleButton({
|
||||
onToggle: () => void
|
||||
}): React.JSX.Element {
|
||||
const shortcutLabel = useShortcutLabel('floatingTerminal.toggle')
|
||||
// Why: show an attention dot while minimized (closed) when any floating-
|
||||
// workspace tab still has an unacknowledged bell or agent completion. Derived
|
||||
// from the shared unread maps, so it clears when the user engages with — or
|
||||
// closes — the offending tab (see selectFloatingWorkspaceHasUnread).
|
||||
const hasFloatingUnread = useAppStore(selectFloatingWorkspaceHasUnread)
|
||||
const showAttentionDot = !open && hasFloatingUnread
|
||||
const initialPositionState = useRef<FloatingTerminalTriggerPositionState | null>(null)
|
||||
if (initialPositionState.current === null) {
|
||||
initialPositionState.current = readInitialTriggerPosition()
|
||||
@@ -200,7 +208,7 @@ export function FloatingTerminalToggleButton({
|
||||
// pages a soft drop shadow lifts it; on near-black dark surfaces a
|
||||
// drop shadow vanishes, so use a distinctly lighter fill plus a
|
||||
// bright hairline ring to define the edge.
|
||||
className="cursor-grab rounded-lg border-transparent text-foreground bg-card shadow-[0_4px_12px_rgb(0_0_0_/_0.22),0_0_0_1px_color-mix(in_srgb,var(--foreground)_12%,transparent)] hover:-translate-y-0.5 hover:bg-accent active:translate-y-0 active:cursor-grabbing dark:bg-accent dark:shadow-[0_6px_16px_rgb(0_0_0_/_0.55),0_0_0_1px_rgb(255_255_255_/_0.22)] dark:hover:bg-[color-mix(in_srgb,var(--accent)_82%,white)]"
|
||||
className="relative cursor-grab rounded-lg border-transparent text-foreground bg-card shadow-[0_4px_12px_rgb(0_0_0_/_0.22),0_0_0_1px_color-mix(in_srgb,var(--foreground)_12%,transparent)] hover:-translate-y-0.5 hover:bg-accent active:translate-y-0 active:cursor-grabbing dark:bg-accent dark:shadow-[0_6px_16px_rgb(0_0_0_/_0.55),0_0_0_1px_rgb(255_255_255_/_0.22)] dark:hover:bg-[color-mix(in_srgb,var(--accent)_82%,white)]"
|
||||
data-floating-terminal-toggle
|
||||
aria-label={
|
||||
open
|
||||
@@ -208,10 +216,17 @@ export function FloatingTerminalToggleButton({
|
||||
'auto.components.floating.terminal.FloatingTerminalToggleButton.5785dd9148',
|
||||
'Minimize floating workspace'
|
||||
)
|
||||
: translate(
|
||||
'auto.components.floating.terminal.FloatingTerminalToggleButton.3b04b065b5',
|
||||
'Show floating workspace'
|
||||
)
|
||||
: showAttentionDot
|
||||
? // Why: announce pending activity to assistive tech; the dot
|
||||
// itself is aria-hidden decoration.
|
||||
translate(
|
||||
'auto.components.floating.terminal.FloatingTerminalToggleButton.4cb418b991',
|
||||
'Show floating workspace, new activity'
|
||||
)
|
||||
: translate(
|
||||
'auto.components.floating.terminal.FloatingTerminalToggleButton.3b04b065b5',
|
||||
'Show floating workspace'
|
||||
)
|
||||
}
|
||||
aria-pressed={open}
|
||||
onPointerDown={handlePointerDown}
|
||||
@@ -221,6 +236,16 @@ export function FloatingTerminalToggleButton({
|
||||
onClick={handleClick}
|
||||
>
|
||||
<PanelsTopLeft className="size-4" />
|
||||
{showAttentionDot ? (
|
||||
// Why: amber matches Orca's "needs attention / unread" convention
|
||||
// (the tab-unread bell); the ring matches the button fill so the
|
||||
// dot reads on both light (bg-card) and dark (dark:bg-accent).
|
||||
<span
|
||||
aria-hidden
|
||||
data-floating-terminal-attention
|
||||
className="pointer-events-none absolute right-1 top-1 size-2 rounded-full bg-amber-500 ring-2 ring-card dark:ring-accent"
|
||||
/>
|
||||
) : null}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="left" sideOffset={6}>
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { useAppStore } from '../../store'
|
||||
import { selectFloatingWorkspaceHasUnread } from '../../store/selectors'
|
||||
import type {
|
||||
ClaudeRateLimitAccountsState,
|
||||
CodexRateLimitAccountsState,
|
||||
@@ -1747,6 +1748,10 @@ function StatusBarInner({ floatingTerminalOpen }: StatusBarProps): React.JSX.Ele
|
||||
const statusBarVisible = useAppStore((s) => s.statusBarVisible)
|
||||
const statusBarItems = useAppStore((s) => s.statusBarItems)
|
||||
const recordFeatureInteraction = useAppStore((s) => s.recordFeatureInteraction)
|
||||
// Why: same launcher attention dot as the floating-button trigger, so an
|
||||
// unacknowledged bell/agent-completion in the floating workspace is visible
|
||||
// whichever trigger location the user picked (see FloatingTerminalToggleButton).
|
||||
const hasFloatingUnread = useAppStore(selectFloatingWorkspaceHasUnread)
|
||||
const floatingTerminalEnabled = settings?.floatingTerminalEnabled === true
|
||||
const floatingTerminalTriggerLocation =
|
||||
settings?.floatingTerminalTriggerLocation ?? 'floating-button'
|
||||
@@ -1908,6 +1913,9 @@ function StatusBarInner({ floatingTerminalOpen }: StatusBarProps): React.JSX.Ele
|
||||
const floatingTerminalActionLabel = floatingTerminalOpen
|
||||
? 'Minimize Floating Workspace'
|
||||
: 'Show Floating Workspace'
|
||||
// Why: only while the panel is closed; the dot reflects unacknowledged
|
||||
// floating-workspace activity and clears via the shared unread paths.
|
||||
const showFloatingWorkspaceAttentionDot = !floatingTerminalOpen && hasFloatingUnread
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -2032,13 +2040,26 @@ function StatusBarInner({ floatingTerminalOpen }: StatusBarProps): React.JSX.Ele
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex size-5 cursor-pointer items-center justify-center rounded border border-border bg-secondary text-secondary-foreground shadow-xs transition-colors hover:bg-accent hover:text-accent-foreground"
|
||||
aria-label={floatingTerminalActionLabel}
|
||||
className="relative inline-flex size-5 cursor-pointer items-center justify-center rounded border border-border bg-secondary text-secondary-foreground shadow-xs transition-colors hover:bg-accent hover:text-accent-foreground"
|
||||
aria-label={
|
||||
showFloatingWorkspaceAttentionDot
|
||||
? `${floatingTerminalActionLabel}, new activity`
|
||||
: floatingTerminalActionLabel
|
||||
}
|
||||
onClick={() => {
|
||||
window.dispatchEvent(new CustomEvent(TOGGLE_FLOATING_TERMINAL_EVENT))
|
||||
}}
|
||||
>
|
||||
<PanelsTopLeft className="size-3.5" />
|
||||
{showFloatingWorkspaceAttentionDot ? (
|
||||
// Why: amber = Orca's "needs attention" convention; ring
|
||||
// matches the button fill so the dot reads on the icon.
|
||||
<span
|
||||
aria-hidden
|
||||
data-floating-terminal-attention
|
||||
className="pointer-events-none absolute right-0.5 top-0.5 size-1.5 rounded-full bg-amber-500 ring-1 ring-secondary"
|
||||
/>
|
||||
) : null}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" sideOffset={6}>
|
||||
|
||||
@@ -10429,6 +10429,7 @@
|
||||
},
|
||||
"FloatingTerminalToggleButton": {
|
||||
"3b04b065b5": "Show floating workspace",
|
||||
"4cb418b991": "Show floating workspace, new activity",
|
||||
"5785dd9148": "Minimize floating workspace",
|
||||
"bfe7809a70": "{{value0}} floating workspace ({{value1}})"
|
||||
},
|
||||
|
||||
@@ -10429,6 +10429,7 @@
|
||||
},
|
||||
"FloatingTerminalToggleButton": {
|
||||
"3b04b065b5": "Mostrar espacio de trabajo flotante",
|
||||
"4cb418b991": "Show floating workspace, new activity",
|
||||
"5785dd9148": "Minimizar el espacio de trabajo flotante",
|
||||
"bfe7809a70": "{{value0}} espacio de trabajo flotante ({{value1}})"
|
||||
},
|
||||
|
||||
@@ -10429,6 +10429,7 @@
|
||||
},
|
||||
"FloatingTerminalToggleButton": {
|
||||
"3b04b065b5": "フローティングワークスペースを表示",
|
||||
"4cb418b991": "Show floating workspace, new activity",
|
||||
"5785dd9148": "フローティングワークスペースを最小限に抑える",
|
||||
"bfe7809a70": "{{value0}} フローティング ワークスペース ({{value1}})"
|
||||
},
|
||||
|
||||
@@ -10429,6 +10429,7 @@
|
||||
},
|
||||
"FloatingTerminalToggleButton": {
|
||||
"3b04b065b5": "플로팅 워크스페이스 표시",
|
||||
"4cb418b991": "Show floating workspace, new activity",
|
||||
"5785dd9148": "플로팅 워크스페이스 최소화",
|
||||
"bfe7809a70": "{{value0}} 플로팅 워크스페이스({{value1}})"
|
||||
},
|
||||
|
||||
@@ -10429,6 +10429,7 @@
|
||||
},
|
||||
"FloatingTerminalToggleButton": {
|
||||
"3b04b065b5": "显示浮动工作区",
|
||||
"4cb418b991": "Show floating workspace, new activity",
|
||||
"5785dd9148": "最小化浮动工作区",
|
||||
"bfe7809a70": "{{value0}} 浮动工作区 ({{value1}})"
|
||||
},
|
||||
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
getProjectHostSetupProjectionFromState,
|
||||
getWorktreeMapFromState,
|
||||
resetFloatingVisibleTabCountSelectorCacheForTest,
|
||||
selectFloatingVisibleTabCount
|
||||
selectFloatingVisibleTabCount,
|
||||
selectFloatingWorkspaceHasUnread
|
||||
} from './selectors'
|
||||
import { selectActiveTerminalChromeState } from './active-terminal-chrome-selector'
|
||||
|
||||
@@ -457,3 +458,70 @@ describe('store selectors', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('selectFloatingWorkspaceHasUnread', () => {
|
||||
const FLOATING = FLOATING_TERMINAL_WORKTREE_ID
|
||||
|
||||
type UnreadState = Parameters<typeof selectFloatingWorkspaceHasUnread>[0]
|
||||
|
||||
function makeState(overrides: Partial<UnreadState>): UnreadState {
|
||||
return {
|
||||
tabsByWorktree: {},
|
||||
unreadTerminalTabs: {},
|
||||
unreadAgentCompletionPanes: {},
|
||||
...overrides
|
||||
} as UnreadState
|
||||
}
|
||||
|
||||
function floatingTab(id: string): TerminalTab {
|
||||
return { id, title: id, ptyId: null } as unknown as TerminalTab
|
||||
}
|
||||
|
||||
it('is false when the floating workspace has no tabs', () => {
|
||||
expect(selectFloatingWorkspaceHasUnread(makeState({}))).toBe(false)
|
||||
})
|
||||
|
||||
it('is true for a bell — an unread floating tab', () => {
|
||||
const state = makeState({
|
||||
tabsByWorktree: { [FLOATING]: [floatingTab('ft1')] },
|
||||
unreadTerminalTabs: { ft1: true }
|
||||
})
|
||||
expect(selectFloatingWorkspaceHasUnread(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('is true for an agent completion — an unread floating pane', () => {
|
||||
const state = makeState({
|
||||
tabsByWorktree: { [FLOATING]: [floatingTab('ft1')] },
|
||||
unreadAgentCompletionPanes: { 'ft1:leaf-a': true }
|
||||
})
|
||||
expect(selectFloatingWorkspaceHasUnread(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('stays true while any of several floating tabs is still unacknowledged', () => {
|
||||
const state = makeState({
|
||||
tabsByWorktree: { [FLOATING]: [floatingTab('ft1'), floatingTab('ft2'), floatingTab('ft3')] },
|
||||
unreadTerminalTabs: { ft3: true }
|
||||
})
|
||||
expect(selectFloatingWorkspaceHasUnread(state)).toBe(true)
|
||||
})
|
||||
|
||||
it('ignores unread that belongs to non-floating (main workspace) tabs', () => {
|
||||
const state = makeState({
|
||||
tabsByWorktree: { [FLOATING]: [floatingTab('ft1')] },
|
||||
unreadTerminalTabs: { 'main-tab': true },
|
||||
unreadAgentCompletionPanes: { 'main-tab:leaf-x': true }
|
||||
})
|
||||
expect(selectFloatingWorkspaceHasUnread(state)).toBe(false)
|
||||
})
|
||||
|
||||
it('does not light for a stale unread entry whose floating tab no longer exists', () => {
|
||||
// Mirrors closing a floating tab: the tab is gone from tabsByWorktree, so even
|
||||
// a lingering map entry (there should be none — closeTab purges) cannot show.
|
||||
const state = makeState({
|
||||
tabsByWorktree: { [FLOATING]: [floatingTab('ft-live')] },
|
||||
unreadTerminalTabs: { 'ft-closed': true },
|
||||
unreadAgentCompletionPanes: { 'ft-closed:leaf-a': true }
|
||||
})
|
||||
expect(selectFloatingWorkspaceHasUnread(state)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -158,6 +158,49 @@ export function resetFloatingVisibleTabCountSelectorCacheForTest(): void {
|
||||
floatingVisibleTabCountCache = null
|
||||
}
|
||||
|
||||
type FloatingWorkspaceUnreadState = Pick<
|
||||
AppState,
|
||||
'tabsByWorktree' | 'unreadTerminalTabs' | 'unreadAgentCompletionPanes'
|
||||
>
|
||||
|
||||
/**
|
||||
* True when any terminal tab in the floating workspace has an unacknowledged
|
||||
* bell or agent completion — the signal behind the launcher attention dot.
|
||||
*
|
||||
* Derives from the existing "show until interact" unread maps rather than a
|
||||
* bespoke flag, so it clears exactly when the user engages with (or closes) the
|
||||
* offending tab, and reflects only tabs that still exist (stale map entries for
|
||||
* removed tabs cannot light it). Bells mark `unreadTerminalTabs[tabId]`;
|
||||
* completions mark `unreadAgentCompletionPanes[paneKey]` — both ungated.
|
||||
*
|
||||
* Returns a primitive boolean, so subscribers re-render only when it flips, and
|
||||
* the empty-workspace early return keeps the common case O(1) despite Zustand
|
||||
* rerunning selectors on every write.
|
||||
*/
|
||||
export function selectFloatingWorkspaceHasUnread(state: FloatingWorkspaceUnreadState): boolean {
|
||||
const tabs = state.tabsByWorktree[FLOATING_TERMINAL_WORKTREE_ID]
|
||||
if (!tabs || tabs.length === 0) {
|
||||
return false
|
||||
}
|
||||
const floatingTabIds = new Set<string>()
|
||||
for (const tab of tabs) {
|
||||
if (state.unreadTerminalTabs[tab.id]) {
|
||||
return true
|
||||
}
|
||||
floatingTabIds.add(tab.id)
|
||||
}
|
||||
// paneKey is `${tabId}:${leafId}` and tabIds never contain ":", so the prefix
|
||||
// up to the first ":" is the owning tab id.
|
||||
for (const paneKey of Object.keys(state.unreadAgentCompletionPanes)) {
|
||||
const separatorIndex = paneKey.indexOf(':')
|
||||
const tabId = separatorIndex === -1 ? paneKey : paneKey.slice(0, separatorIndex)
|
||||
if (floatingTabIds.has(tabId)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export function getAllWorktreesFromState(state: Pick<AppState, 'worktreesByRepo'>): Worktree[] {
|
||||
return getCachedAllWorktrees(state.worktreesByRepo)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user