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.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(desktop): the window takes clicks again when two prompts open at once
leepokai219935410dff
diff --git a/apps/desktop/src/renderer/components/Overlay.tsx b/apps/desktop/src/renderer/components/Overlay.tsxindex a0b02f7d..04f446fa 100644--- a/apps/desktop/src/renderer/components/Overlay.tsx+++ b/apps/desktop/src/renderer/components/Overlay.tsx@@ -2,6 +2,7 @@ import { createContext, useContext, useEffect, useId, useLayoutEffect, useRef, uimport { createPortal } from 'react-dom'import { reduceMotion } from '../lib/theme'import { afterExit } from '../lib/exit-delay'+import { stackModals } from '../lib/modal-stack'import { useTr } from '../lib/use-language'import { Icon } from './Icon'import { HStack, VStack } from './Stack'@@ -37,18 +38,18 @@ export function usePresence(open: boolean, exitMs = 300, animateOnMount = true)export const DismissContext = createContext<() => void>(() => {})export const useDismiss = () => useContext(DismissContext)-/** Stack depth: only the top layer takes Escape. */-const stack: number[] = []+/** Layers in the order they opened: Escape goes to the newest one still live (not inert under the modal on top). */+const stack: { id: number; layer: RefObject<HTMLElement | null> }[] = []let nextLayer = 0-export function useEscape(active: boolean, onEscape: () => void) {+export function useEscape(active: boolean, onEscape: () => void, layer: RefObject<HTMLElement | null>) {const handler = useRef(onEscape)handler.current = onEscapeuseEffect(() => {if (!active) returnconst id = ++nextLayer- stack.push(id)+ stack.push({ id, layer })const onKey = (e: KeyboardEvent) => {- if (e.key === 'Escape' && stack[stack.length - 1] === id) {+ if (e.key === 'Escape' && stack.findLast((entry) => !entry.layer.current?.inert)?.id === id) {e.preventDefault()e.stopPropagation()handler.current()@@ -57,9 +58,9 @@ export function useEscape(active: boolean, onEscape: () => void) {window.addEventListener('keydown', onKey, true)return () => {window.removeEventListener('keydown', onKey, true)- stack.splice(stack.indexOf(id), 1)+ stack.splice(stack.findIndex((entry) => entry.id === id), 1)}- }, [active])+ }, [active, layer])}const FOCUSABLE = 'button:not(:disabled), [href], input:not(:disabled), textarea:not(:disabled), select:not(:disabled), [tabindex]:not([tabindex="-1"])'@@ -67,6 +68,25 @@ const FOCUSABLE = 'button:not(:disabled), [href], input:not(:disabled), textarea/** The open modal's title id, so its `ModalHeader` names the dialog. */const ModalTitleContext = createContext<string | undefined>(undefined)+/** The open modals with where focus returns when each closes, and the page layers they made inert. */+const openModals = new Map<HTMLElement, HTMLElement | null>()+const mutedByModals = new WeakSet<HTMLElement>()++/** Applies `stackModals` to the page and moves focus into the modal on top. */+function syncModals() {+ const layers = [...document.body.children].filter((el): el is HTMLElement => el instanceof HTMLElement)+ const { top, mute, unmute } = stackModals(layers.map((el) => ({ el, z: Number(getComputedStyle(el).zIndex) || 0, modal: openModals.has(el), inert: el.inert, muted: mutedByModals.has(el) })))+ for (const el of mute) {+ el.inert = true+ mutedByModals.add(el)+ }+ for (const el of unmute) {+ el.inert = false+ mutedByModals.delete(el)+ }+ if (top && !top.contains(document.activeElement)) (top.querySelector<HTMLElement>('[data-autofocus]') ?? top.querySelector<HTMLElement>('[data-modal-card]'))?.focus({ preventScroll: true })+}+/*** An open modal holds focus: everything behind it goes inert, focus moves in (to a* `data-autofocus` control, else the card itself), and returns to where it was on close.@@ -75,10 +95,8 @@ function useModalFocus(open: boolean, mounted: boolean, layer: RefObject<HTMLEleuseEffect(() => {const node = layer.currentif (!open || !node) return- const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null- const muted = [...document.body.children].filter((el): el is HTMLElement => el instanceof HTMLElement && el !== node && !el.inert)- for (const el of muted) el.inert = true- if (!node.contains(document.activeElement)) (node.querySelector<HTMLElement>('[data-autofocus]') ?? node.querySelector<HTMLElement>('[data-modal-card]'))?.focus({ preventScroll: true })+ openModals.set(node, document.activeElement instanceof HTMLElement ? document.activeElement : null)+ syncModals()// Tab cycles inside the top modal instead of leaving the page.const onKey = (e: KeyboardEvent) => {if (e.key !== 'Tab' || node.inert) return@@ -95,8 +113,15 @@ function useModalFocus(open: boolean, mounted: boolean, layer: RefObject<HTMLElewindow.addEventListener('keydown', onKey, true)return () => {window.removeEventListener('keydown', onKey, true)- for (const el of muted) el.inert = false- if (previous?.isConnected) previous.focus({ preventScroll: true })+ const previous = openModals.get(node)+ openModals.delete(node)+ syncModals()+ if (previous?.isConnected && !previous.closest('[inert]')) {+ previous.focus({ preventScroll: true })+ return+ }+ // Its opener is under a modal still open: the modal opened from this one returns there instead.+ for (const [other, theirs] of openModals) if (theirs && node.contains(theirs)) openModals.set(other, previous ?? null)}}, [open, mounted, layer])}@@ -118,7 +143,7 @@ export function Sheet({ open, onClose, width, height, maxHeight, dismissOnDim =const layer = useRef<HTMLDivElement>(null)const titleId = useId()if (open) last.current = children- useEscape(open, onClose)+ useEscape(open, onClose, layer)useModalFocus(open, mounted, layer)if (!mounted) return nullreturn createPortal(@@ -159,7 +184,7 @@ export function Dialog({ open, title, message, actions, cancel = 'Cancel', onCloconst layer = useRef<HTMLDivElement>(null)const id = useId()if (open) last.current = { title, message, actions, children }- useEscape(open && cancel !== null, onClose)+ useEscape(open && cancel !== null, onClose, layer)useModalFocus(open, mounted, layer)if (!mounted) return nullconst shownContent = last.current@@ -344,17 +369,18 @@ export function AnchoredMenu({ open, onClose, anchor, point, items, reactions }:const { mounted, shown } = usePresence(open, 120)const [rect, setRect] = useState<DOMRect | null>(null)const frozen = useRef<MenuItem[]>([])+ const layer = useRef<HTMLDivElement>(null)if (open) frozen.current = items()useLayoutEffect(() => {if (!open) returnif (point) setRect(new DOMRect(point.x, point.y, 0, 0))else if (anchor?.current) setRect(anchor.current.getBoundingClientRect())}, [open, point, anchor])- useEscape(open, onClose)+ useEscape(open, onClose, layer)if (!mounted || !rect) return nullconst { style, width, room } = anchorPlacement(rect)return createPortal(- <div className={`anchored ${shown ? 'shown' : ''}`} onMouseDown={(e) => e.target === e.currentTarget && onClose()} onContextMenu={(e) => { e.preventDefault(); onClose() }}>+ <div ref={layer} className={`anchored ${shown ? 'shown' : ''}`} onMouseDown={(e) => e.target === e.currentTarget && onClose()} onContextMenu={(e) => { e.preventDefault(); onClose() }}><div className="anchored-panel" style={{ ...style, maxWidth: width }}><MenuPanel items={frozen.current} reactions={reactions} dismiss={onClose} maxHeight={Math.min(420, room)} /></div>diff --git a/apps/desktop/src/renderer/lib/modal-stack.test.ts b/apps/desktop/src/renderer/lib/modal-stack.test.tsnew file mode 100644index 00000000..d7ab106a--- /dev/null+++ b/apps/desktop/src/renderer/lib/modal-stack.test.ts@@ -0,0 +1,57 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { stackModals, type PageLayer } from './modal-stack.ts'++const SHEET = 100+const DIALOG = 200+const layer = (el: string, overrides: Partial<PageLayer<string>> = {}): PageLayer<string> => ({ el, z: 0, modal: false, inert: false, muted: false, ...overrides })++test('a dialog stays on top of a sheet whichever opened first on the render', () => {+ for (const order of [['sheet', 'dialog'], ['dialog', 'sheet']]) {+ const layers = [layer('root'), ...order.map((el) => layer(el, { modal: true, z: el === 'dialog' ? DIALOG : SHEET }))]+ const { top, mute, unmute } = stackModals(layers)+ assert.equal(top, 'dialog')+ assert.deepEqual(mute.sort(), ['root', 'sheet'])+ assert.deepEqual(unmute, [])+ }+})++test('the later of two modals at the same z-index is on top', () => {+ const { top, mute } = stackModals([layer('root'), layer('a', { modal: true, z: SHEET }), layer('b', { modal: true, z: SHEET })])+ assert.equal(top, 'b')+ assert.deepEqual(mute, ['root', 'a'])+})++test('closing the top modal hands clicks to the next one down', () => {+ const { top, mute, unmute } = stackModals([+ layer('root', { inert: true, muted: true }),+ layer('sheet', { modal: true, z: SHEET, inert: true, muted: true }),+ layer('dialog', { z: DIALOG }),+ ])+ assert.equal(top, 'sheet')+ assert.deepEqual(unmute, ['sheet'])+ assert.deepEqual(mute, [])+})++test('a menu opened from the top modal comes back when a modal over it closes', () => {+ const { top, unmute } = stackModals([+ layer('root', { inert: true, muted: true }),+ layer('sheet', { modal: true, z: SHEET }),+ layer('menu', { z: 300, inert: true, muted: true }),+ layer('dialog', { z: DIALOG }),+ ])+ assert.equal(top, 'sheet')+ assert.deepEqual(unmute, ['menu'])+})++test('a menu open before the modal goes inert under it', () => {+ const { mute } = stackModals([layer('root'), layer('menu', { z: 300 }), layer('sheet', { modal: true, z: SHEET })])+ assert.deepEqual(mute, ['root', 'menu'])+})++test('the last close restores only the layers modals made inert', () => {+ const { top, mute, unmute } = stackModals([layer('root', { inert: true, muted: true }), layer('own', { inert: true }), layer('sheet')])+ assert.equal(top, null)+ assert.deepEqual(unmute, ['root'])+ assert.deepEqual(mute, [])+})diff --git a/apps/desktop/src/renderer/lib/modal-stack.ts b/apps/desktop/src/renderer/lib/modal-stack.tsnew file mode 100644index 00000000..f274761c--- /dev/null+++ b/apps/desktop/src/renderer/lib/modal-stack.ts@@ -0,0 +1,26 @@+/** A page layer (a child of `<body>`), listed in page order. */+export interface PageLayer<T> {+ el: T+ z: number+ /** An open sheet or dialog. */+ modal: boolean+ inert: boolean+ /** Made inert by modals, so theirs to restore. */+ muted: boolean+}++/**+ * Which layers take clicks, focus and Escape while modals are open. Only the modal drawn on top+ * (highest z-index, the later one on a tie) does, plus the layers after it that aren't modals+ * (a menu opened from it); every other layer goes inert. Two modals can open on the same render+ * in either order, so this is recomputed on every open and close.+ */+export function stackModals<T>(layers: readonly PageLayer<T>[]) {+ const top = layers.reduce((best, layer, i) => (layer.modal && (best < 0 || layer.z >= layers[best].z) ? i : best), -1)+ const live = (layer: PageLayer<T>, i: number) => top < 0 || i === top || (i > top && !layer.modal)+ return {+ top: top < 0 ? null : layers[top].el,+ mute: layers.filter((layer, i) => !live(layer, i) && !layer.inert).map((layer) => layer.el),+ unmute: layers.filter((layer, i) => live(layer, i) && layer.muted).map((layer) => layer.el),+ }+}diff --git a/apps/desktop/src/renderer/views/bots/parts.tsx b/apps/desktop/src/renderer/views/bots/parts.tsxindex 27b7670c..263c4307 100644--- a/apps/desktop/src/renderer/views/bots/parts.tsx+++ b/apps/desktop/src/renderer/views/bots/parts.tsx@@ -78,13 +78,14 @@ export function AvatarPicker({ shape, color, onShape, onColor }: { shape: stringexport function AnchoredPanel({ open, onClose, anchor, children }: { open: boolean; onClose: () => void; anchor: RefObject<HTMLElement | null>; children: ReactNode }) {const { mounted, shown } = usePresence(open, 120)const [rect, setRect] = useState<DOMRect | null>(null)+ const layer = useRef<HTMLDivElement>(null)useLayoutEffect(() => {if (open && anchor.current) setRect(anchor.current.getBoundingClientRect())}, [open, anchor])- useEscape(open, onClose)+ useEscape(open, onClose, layer)if (!mounted || !rect) return nullreturn createPortal(- <div className={`anchored ${shown ? 'shown' : ''}`} onMouseDown={(e) => e.target === e.currentTarget && onClose()}>+ <div ref={layer} className={`anchored ${shown ? 'shown' : ''}`} onMouseDown={(e) => e.target === e.currentTarget && onClose()}><div className="anchored-panel" style={anchorPlacement(rect).style}>{children}</div>diff --git a/docs/design/ui-conventions.md b/docs/design/ui-conventions.mdindex 41c9b92b..92cbd01b 100644--- a/docs/design/ui-conventions.md+++ b/docs/design/ui-conventions.md@@ -55,7 +55,7 @@ The chat window's account menu copies Grok Bot's: Usage, Get Codync for mobile,The iPhone and the desktop no longer share UI code. `CodyncUI` (`apps/ios/Kit/`) is the iPhone app's own package; the desktop app (`apps/desktop/src/renderer/`) is a TypeScript port of the same screens with its own `BotStore`, chat items (`views/thread/chat-items.ts`) and Markdown blocks (`markdown-blocks.ts`).- The iPhone chat's chrome is in `ThreadView.swift` (`body`, `chrome`, `header`). The iPhone conversation is a UIKit collection view of hosted SwiftUI rows (`ConversationList.swift`): it loads earlier messages from the computer as the reader scrolls up, runs under the bars and the composer (the list sits in the safe area and reaches past it, so rows never get a safe area of their own), follows the newest message until they scroll away (with a round "Jump to latest" button), and pops each new message in ([chat messages](../features/chat-messages.md)).-- The desktop UI rules (custom controls, no system menus except the tray, icon-only buttons, fill or border) are implemented in `apps/desktop/src/renderer/components/` (`Controls.tsx`, `Overlay.tsx`, `Icon.tsx`, `Text.tsx`, `Stack.tsx`); how views use them and the theme tokens: [desktop styles](../guides/desktop-styles.md). Chrome on the sidebar (its header actions, the computer filter, Extensions) is outlined; chrome floating over the conversation (the title pill, the composer) is filled with a shadow, and the composer also carries the floating-layer outline. Corner radii and shadows come from the `--radius-*` and `--shadow-*` scale in `styles/theme.css`. Status text uses `--attention` (`--warning` is for dots and fills only), and destructive fills use `--danger-fill` with `--on-danger`, so both stay readable in light and dark. Sheets and dialogs hold focus while open: the window behind goes inert, Tab cycles inside, and focus returns to where it was on close.+- The desktop UI rules (custom controls, no system menus except the tray, icon-only buttons, fill or border) are implemented in `apps/desktop/src/renderer/components/` (`Controls.tsx`, `Overlay.tsx`, `Icon.tsx`, `Text.tsx`, `Stack.tsx`); how views use them and the theme tokens: [desktop styles](../guides/desktop-styles.md). Chrome on the sidebar (its header actions, the computer filter, Extensions) is outlined; chrome floating over the conversation (the title pill, the composer) is filled with a shadow, and the composer also carries the floating-layer outline. Corner radii and shadows come from the `--radius-*` and `--shadow-*` scale in `styles/theme.css`. Status text uses `--attention` (`--warning` is for dots and fills only), and destructive fills use `--danger-fill` with `--on-danger`, so both stay readable in light and dark. Sheets and dialogs hold focus while open: the window behind goes inert, Tab cycles inside, and focus returns to where it was on close. With several open at once, only the one drawn on top (a dialog over a sheet) and the menus opened from it take clicks, focus and Escape; the next one down takes over when it closes, and focus goes back to the first one's opener when the last closes.- The Android app (`apps/android/`) ports the iPhone screens one to one in Compose. Where iOS uses system UI (the tab bar, menus, sheets, Liquid Glass), Android draws the same look with its `design` module: glass from Kyant's backdrop library (blur, lens refraction and highlight on RenderEffect/RuntimeShader), the iOS sheet with its grabber and drag-to-close, glass menus and context menus, Inter for SF Pro and Material Symbols for SF Symbols (`Symbol("sf.name")`), and the soft scroll edge under its bars (`ScrollEdge`: the content behind the header, composer and tab bar blurs and washes out). Android has no Liquid Glass of its own; Material widgets aren't used.- A change to one lands in the other and the TUI in the same change; see [native client parity](#native-client-parity).