Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(desktop): open Quick Composer as a composer, capture screenshots on demand (#19523)

Arvin Xuc33818b0d000
diff --git a/apps/desktop/src/main/controllers/ScreenCaptureCtr.ts b/apps/desktop/src/main/controllers/ScreenCaptureCtr.ts
index 84d22e1ccf0..a91b365675d 100644
--- a/apps/desktop/src/main/controllers/ScreenCaptureCtr.ts
+++ b/apps/desktop/src/main/controllers/ScreenCaptureCtr.ts
@@ -20,6 +20,12 @@ export default class ScreenCaptureCtr extends ControllerModule {
console.info('[screenCapture:overlay]', payload.event, payload.data ?? '');
}
+ @IpcMethod()
+ async beginCapture(): Promise<boolean> {
+ logger.debug('beginCapture request');
+ return this.app.screenCaptureManager.beginCapture();
+ }
+
@IpcMethod()
async previewWindow(windowId: number): Promise<CapturePreviewResult> {
logger.debug(`previewWindow request: ${windowId}`);
diff --git a/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.test.ts b/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.test.ts
index d4326242880..331228af78d 100644
--- a/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.test.ts
+++ b/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.test.ts
@@ -144,18 +144,74 @@ describe('ScreenCaptureManager', () => {
expect(mockBrowserWindow.moveTop).toHaveBeenCalled();
});
+ it('opens the composer without checking permission or enumerating windows', async () => {
+ mockGetScreenCaptureStatus.mockReturnValue('denied');
+ const manager = new ScreenCaptureManager(createApp());
+
+ await manager.startSession();
+
+ expect(mockGetScreenCaptureStatus).not.toHaveBeenCalled();
+ expect(mockDialogShowMessageBox).not.toHaveBeenCalled();
+ expect(mockEnumerateWindows).not.toHaveBeenCalled();
+ expect(mockBrowserWindow.show).toHaveBeenCalled();
+ expect(mockBrowserWindow.webContents.send).toHaveBeenCalledWith(
+ 'screenCaptureSession',
+ expect.objectContaining({ windows: [] }),
+ );
+ });
+
+ describe('beginCapture', () => {
+ it('enumerates windows and pushes them to the overlay once permission is granted', async () => {
+ const windows = [
+ {
+ appName: 'Safari',
+ bounds: { height: 200, width: 300, x: 5, y: 6 },
+ order: 0,
+ overlayBounds: { height: 200, width: 300, x: 5, y: 6 },
+ title: 'Docs',
+ windowId: 42,
+ },
+ ];
+ mockEnumerateWindows.mockResolvedValue(windows);
+ const manager = new ScreenCaptureManager(createApp());
+ await manager.startSession();
+ mockBrowserWindow.webContents.send.mockClear();
+
+ await expect(manager.beginCapture()).resolves.toBe(true);
+
+ expect(mockEnumerateWindows).toHaveBeenCalledWith(
+ { height: 900, width: 1440, x: 0, y: 0 },
+ 2,
+ );
+ expect(mockBrowserWindow.webContents.send).toHaveBeenCalledWith(
+ 'screenCaptureSession',
+ expect.objectContaining({ windows }),
+ );
+ });
+
+ it('returns false without an active session', async () => {
+ const manager = new ScreenCaptureManager(createApp());
+
+ await expect(manager.beginCapture()).resolves.toBe(false);
+
+ expect(mockEnumerateWindows).not.toHaveBeenCalled();
+ });
+ });
+
describe('permission caching', () => {
- it('queries screen capture status only once across sessions when granted', async () => {
+ it('queries screen capture status only once across captures when granted', async () => {
const manager = new ScreenCaptureManager(createApp());
await manager.startSession();
+ await manager.beginCapture();
manager.close();
await manager.startSession();
+ await manager.beginCapture();
expect(mockGetScreenCaptureStatus).toHaveBeenCalledTimes(1);
});
- it('skips the status query in startSession after prewarm', async () => {
+ it('skips the status query in beginCapture after prewarm', async () => {
const manager = new ScreenCaptureManager(createApp());
manager.prewarmPermissionCheck();
@@ -163,31 +219,36 @@ describe('ScreenCaptureManager', () => {
expect(mockGetScreenCaptureStatus).toHaveBeenCalledTimes(1);
await manager.startSession();
+ await expect(manager.beginCapture()).resolves.toBe(true);
expect(mockGetScreenCaptureStatus).toHaveBeenCalledTimes(1);
- expect(mockBrowserWindow.show).toHaveBeenCalled();
});
- it('re-queries status on each session while permission is not granted', async () => {
+ it('re-queries status on each capture while permission is not granted', async () => {
mockGetScreenCaptureStatus.mockReturnValue('denied');
mockDialogShowMessageBox.mockResolvedValue({ response: 1 });
const manager = new ScreenCaptureManager(createApp());
await manager.startSession();
+ await manager.beginCapture();
await manager.startSession();
+ await manager.beginCapture();
expect(mockGetScreenCaptureStatus).toHaveBeenCalledTimes(2);
});
});
- it('blocks quick composer and prompts for permission when screen recording is unavailable', async () => {
+ it('closes the overlay and prompts for permission when screen recording is unavailable', async () => {
mockGetScreenCaptureStatus.mockReturnValue('denied');
mockDialogShowMessageBox.mockResolvedValue({ response: 0 });
const app = createApp();
const manager = new ScreenCaptureManager(app);
-
await manager.startSession();
+ await expect(manager.beginCapture()).resolves.toBe(false);
+
+ expect(mockBrowserWindow.destroy).toHaveBeenCalled();
+ expect(manager.isActive).toBe(false);
expect(mockDialogShowMessageBox).toHaveBeenCalledWith(
app.browserManager.getMainWindow().browserWindow,
expect.objectContaining({
@@ -197,19 +258,18 @@ describe('ScreenCaptureManager', () => {
);
expect(mockRequestScreenCaptureAccess).toHaveBeenCalled();
expect(mockEnumerateWindows).not.toHaveBeenCalled();
- expect(MockBrowserWindow).not.toHaveBeenCalled();
});
it('does not open settings when permission prompt is dismissed', async () => {
mockGetScreenCaptureStatus.mockReturnValue('denied');
mockDialogShowMessageBox.mockResolvedValue({ response: 1 });
const manager = new ScreenCaptureManager(createApp());
-
await manager.startSession();
+ await manager.beginCapture();
+
expect(mockRequestScreenCaptureAccess).not.toHaveBeenCalled();
expect(mockEnumerateWindows).not.toHaveBeenCalled();
- expect(MockBrowserWindow).not.toHaveBeenCalled();
});
it('shows an app-modal prompt when the main window is hidden', async () => {
@@ -217,6 +277,7 @@ describe('ScreenCaptureManager', () => {
const manager = new ScreenCaptureManager(createApp({ mainWindowVisible: false }));
await manager.startSession();
+ await manager.beginCapture();
expect(mockDialogShowMessageBox).toHaveBeenCalledWith(
expect.objectContaining({
@@ -286,6 +347,7 @@ describe('ScreenCaptureManager', () => {
const app = createApp();
const manager = new ScreenCaptureManager(app);
await manager.startSession();
+ await manager.beginCapture();
const pngBuffer = Buffer.from([9, 9, 9]);
mockCaptureWindow.mockResolvedValue(pngBuffer);
diff --git a/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.ts b/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.ts
index 34ea9ea85df..3305b740769 100644
--- a/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.ts
+++ b/apps/desktop/src/main/modules/screenCapture/ScreenCaptureManager.ts
@@ -94,11 +94,11 @@ export class ScreenCaptureManager {
return this.overlayWindow !== null && !this.overlayWindow.isDestroyed();
}
+ /**
+ * Open the composer overlay. Screenshots are opt-in, so the permission check
+ * and window enumeration are deferred to `beginCapture`.
+ */
async startSession(): Promise<void> {
- if (!(await this.ensureScreenCaptureAccess())) {
- return;
- }
-
if (this.isActive) {
logger.warn('Capture session already active');
this.close();
@@ -109,21 +109,50 @@ export class ScreenCaptureManager {
const { bounds, scaleFactor } = display;
logger.info(
- `Starting capture session on display ${display.id} (${bounds.width}x${bounds.height} @${scaleFactor}x)`,
+ `Starting composer session on display ${display.id} (${bounds.width}x${bounds.height} @${scaleFactor}x)`,
);
- const windows = await enumerateWindows(bounds, scaleFactor);
-
this.session = {
displayBounds: bounds,
scaleFactor,
- windows,
+ windows: [],
...this.snapshot,
};
await this.createOverlayWindow(bounds);
}
+ /**
+ * Switch the active session into capture mode: verify Screen Recording
+ * access, then enumerate on-screen windows for hover hit-testing.
+ * Resolves `false` when capture cannot start.
+ */
+ async beginCapture(): Promise<boolean> {
+ if (!this.session) return false;
+
+ const status = this.resolveScreenCaptureStatus();
+ if (status !== 'granted') {
+ // The overlay sits at screen-saver level and would cover the dialog.
+ this.close();
+ await this.promptScreenCaptureAccess(status);
+ return false;
+ }
+
+ const { displayBounds, scaleFactor } = this.session;
+ const windows = await enumerateWindows(displayBounds, scaleFactor);
+ // The overlay may have been closed while windows were being enumerated.
+ if (!this.session) return false;
+
+ this.session = { ...this.session, windows };
+ logger.info(`Capture mode started with ${windows.length} windows`);
+
+ if (this.overlayWindow && !this.overlayWindow.isDestroyed()) {
+ this.overlayWindow.webContents.send('screenCaptureSession', this.session);
+ }
+
+ return true;
+ }
+
async handlePreviewWindow(windowId: number): Promise<CapturePreviewResult> {
if (!this.session) {
return { error: 'no active session', success: false };
@@ -289,17 +318,17 @@ export class ScreenCaptureManager {
});
}
- private async ensureScreenCaptureAccess(): Promise<boolean> {
- if (!isMac || this.screenCaptureGranted) {
- return true;
- }
+ private resolveScreenCaptureStatus(): ReturnType<typeof getScreenCaptureStatus> {
+ if (!isMac || this.screenCaptureGranted) return 'granted';
const status = getScreenCaptureStatus();
- if (status === 'granted') {
- this.screenCaptureGranted = true;
- return true;
- }
+ if (status === 'granted') this.screenCaptureGranted = true;
+ return status;
+ }
+ private async promptScreenCaptureAccess(
+ status: ReturnType<typeof getScreenCaptureStatus>,
+ ): Promise<void> {
const t = this.app.i18n.ns('dialog');
const mainWindow = this.app.browserManager.getMainWindow();
const parentWindow = mainWindow?.browserWindow?.isVisible?.() ? mainWindow.browserWindow : null;
@@ -320,13 +349,11 @@ export class ScreenCaptureManager {
if (result.response !== 0) {
logger.info(`Screen capture permission prompt dismissed; status=${status}`);
- return false;
+ return;
}
logger.info(`Opening screen capture permission settings; status=${status}`);
await requestScreenCaptureAccess();
-
- return false;
}
private async createOverlayWindow(bounds: Electron.Rectangle): Promise<void> {
diff --git a/apps/desktop/src/overlay/ChatPanel.test.tsx b/apps/desktop/src/overlay/ChatPanel.test.tsx
index fdc8745d527..2591e2f7ca8 100644
--- a/apps/desktop/src/overlay/ChatPanel.test.tsx
+++ b/apps/desktop/src/overlay/ChatPanel.test.tsx
@@ -1,6 +1,10 @@
import { describe, expect, it, vi } from 'vitest';
-import { resolveOverlayModelSelectionPayload, shouldShowOverlayModelSelector } from './ChatPanel';
+import {
+ canSubmitOverlayPrompt,
+ resolveOverlayModelSelectionPayload,
+ shouldShowOverlayModelSelector,
+} from './ChatPanel';
import { resolvePanelPlacement } from './panelPlacement';
vi.mock('./chatPanel.css.ts', () => new Proxy({}, { get: (_, key) => String(key) }));
@@ -46,6 +50,23 @@ describe('ChatPanel', () => {
});
});
+ it('allows sending a prompt without any screenshot', () => {
+ expect(canSubmitOverlayPrompt({ prompt: 'hello', selections: [] })).toBe(true);
+ expect(canSubmitOverlayPrompt({ prompt: ' ', selections: [] })).toBe(false);
+ });
+
+ it('waits for attached screenshots to finish uploading before sending', () => {
+ expect(
+ canSubmitOverlayPrompt({
+ prompt: 'hello',
+ selections: [{ uploadStatus: 'ready' }, { uploadStatus: 'uploading' }],
+ }),
+ ).toBe(false);
+ expect(
+ canSubmitOverlayPrompt({ prompt: 'hello', selections: [{ uploadStatus: 'ready' }] }),
+ ).toBe(true);
+ });
+
it('hides the model selector and omits model payload for heterogeneous agents', () => {
const heterogeneousAgent = {
heterogeneousType: 'codex',
diff --git a/apps/desktop/src/overlay/ChatPanel.tsx b/apps/desktop/src/overlay/ChatPanel.tsx
index 55a718ce7e1..70040993c9d 100644
--- a/apps/desktop/src/overlay/ChatPanel.tsx
+++ b/apps/desktop/src/overlay/ChatPanel.tsx
@@ -6,7 +6,14 @@ import type {
ScreenCaptureOverlayTheme,
} from '@lobechat/electron-client-ipc';
import { ModelIcon } from '@lobehub/icons';
-import { AlertCircleIcon, CheckIcon, ChevronDownIcon, Loader2Icon, XIcon } from 'lucide-react';
+import {
+ AlertCircleIcon,
+ CameraIcon,
+ CheckIcon,
+ ChevronDownIcon,
+ Loader2Icon,
+ XIcon,
+} from 'lucide-react';
import type {
CSSProperties,
KeyboardEvent as ReactKeyboardEvent,
@@ -45,10 +52,12 @@ export interface ChatPanelSubmitPayload {
export interface ChatPanelProps {
agentId?: string;
agents?: ScreenCaptureAgentOption[];
+ capturing?: boolean;
hidden?: boolean;
modelId?: string;
models?: ScreenCaptureModelOption[];
onRemoveSelection: (selectionId: string) => void;
+ onStartCapture: () => void;
onSubmit: (payload: ChatPanelSubmitPayload) => void;
placementResetKey?: number;
selections: ChatPanelSelection[];
@@ -60,6 +69,15 @@ export interface ChatPanelProps {
export const shouldShowOverlayModelSelector = (agent?: ScreenCaptureAgentOption) =>
!agent?.heterogeneousType;
+/** Screenshots are optional; a prompt alone is sendable once attached uploads finish. */
+export const canSubmitOverlayPrompt = ({
+ prompt,
+ selections,
+}: {
+ prompt: string;
+ selections: Pick<ChatPanelSelection, 'uploadStatus'>[];
+}) => prompt.trim().length > 0 && selections.every((item) => item.uploadStatus === 'ready');
+
export const resolveOverlayModelSelectionPayload = ({
agent,
model,
@@ -129,10 +147,12 @@ const ChatPanel = memo<ChatPanelProps>(
({
agentId: initialAgentId,
agents,
+ capturing = false,
hidden = false,
modelId: initialModelId,
models,
onRemoveSelection,
+ onStartCapture,
onSubmit,
placementResetKey = 0,
selections,
@@ -290,16 +310,9 @@ const ChatPanel = memo<ChatPanelProps>(
if (!hidden && textareaRef.current) {
textareaRef.current.focus();
}
- }, [hidden, selected]);
+ }, [hidden, selected, capturing]);
- useEffect(() => {
- if (!selected) setPrompt('');
- }, [selected]);
-
- const allUploadsReady = useMemo(
- () => selections.every((item) => item.uploadStatus === 'ready'),
- [selections],
- );
+ const canSend = canSubmitOverlayPrompt({ prompt, selections });
const hasUploading = useMemo(
() => selections.some((item) => item.uploadStatus === 'uploading'),
[selections],
@@ -310,7 +323,7 @@ const ChatPanel = memo<ChatPanelProps>(
);
const submit = useCallback(() => {
- if (selections.length === 0 || !prompt.trim() || !allUploadsReady) return;
+ if (!canSend) return;
const modelSelection = resolveOverlayModelSelectionPayload({
agent: currentAgent,
model: currentModel,
@@ -324,16 +337,7 @@ const ChatPanel = memo<ChatPanelProps>(
prompt: prompt.trim(),
provider: modelSelection.provider,
});
- }, [
- selections,
- prompt,
- agentId,
- currentAgent,
- modelId,
- currentModel,
- onSubmit,
- allUploadsReady,
- ]);
+ }, [selections, prompt, agentId, currentAgent, modelId, currentModel, onSubmit, canSend]);
const handleKeyDown = useCallback(
(e: ReactKeyboardEvent<HTMLTextAreaElement>) => {
@@ -345,8 +349,6 @@ const ChatPanel = memo<ChatPanelProps>(
[submit],
);
- const canSend = selected && prompt.trim().length > 0 && allUploadsReady;
-
const handleAgentChange = useCallback((value: string) => {
setAgentId(value || undefined);
}, []);
@@ -473,7 +475,9 @@ const ChatPanel = memo<ChatPanelProps>(
? selectionCount > 1
? OVERLAY_COPY.multipleSelectedPlaceholder
: OVERLAY_COPY.selectedPlaceholder
- : OVERLAY_COPY.idlePlaceholder
+ : capturing
+ ? OVERLAY_COPY.idlePlaceholder
+ : OVERLAY_COPY.composePlaceholder
}
onChange={(e) => setPrompt(e.target.value)}
onKeyDown={handleKeyDown}
@@ -575,6 +579,20 @@ const ChatPanel = memo<ChatPanelProps>(
</div>
<div className={styles.actionBarRight}>
+ <button
+ aria-label={OVERLAY_COPY.captureLabel}
+ aria-pressed={capturing}
+ className={cn(
+ styles.iconBtn,
+ styles.captureBtn,
+ capturing && styles.captureBtnActive,
+ )}
+ title={OVERLAY_COPY.captureLabel}
+ type="button"
+ onClick={onStartCapture}
+ >
+ <CameraIcon size={16} strokeWidth={2} />
+ </button>
<button
aria-label={OVERLAY_COPY.sendAriaLabel}
className={styles.sendBtn}
diff --git a/apps/desktop/src/overlay/ScreenCaptureOverlay.tsx b/apps/desktop/src/overlay/ScreenCaptureOverlay.tsx
index 4a1420d4608..07632deb518 100644
--- a/apps/desktop/src/overlay/ScreenCaptureOverlay.tsx
+++ b/apps/desktop/src/overlay/ScreenCaptureOverlay.tsx
@@ -7,9 +7,15 @@ import type { MouseEvent as ReactMouseEvent } from 'react';
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import ChatPanel, { type ChatPanelSelection, type ChatPanelSubmitPayload } from './ChatPanel';
+import { cn } from './cn';
import { OVERLAY_COPY, OVERLAY_LAYOUT, OVERLAY_SHORTCUTS } from './constants';
import * as styles from './overlay.css.ts';
-import { resolveCommittedSelectionRect, shouldHideChatPanel } from './overlaySelectionState';
+import {
+ type OverlayMode,
+ resolveCommittedSelectionRect,
+ resolveEscapeAction,
+ shouldHideChatPanel,
+} from './overlaySelectionState';
import { useDragSelection } from './useDragSelection';
import { getTopmostWindowAtPoint, useWindowHighlight } from './useWindowHighlight';
import WindowTag from './WindowTag';
@@ -18,6 +24,7 @@ const clipLabel = (text: string, max = OVERLAY_LAYOUT.labelClipLength): string =
text.length > max ? `${text.slice(0, max)}…` : text;
const ScreenCaptureOverlay = memo(() => {
+ const [mode, setMode] = useState<OverlayMode>('compose');
const [isPanelHidden, setIsPanelHidden] = useState(false);
const [pendingSelectionRect, setPendingSelectionRect] = useState<
ChatPanelSelection['rect'] | null
@@ -26,6 +33,7 @@ const ScreenCaptureOverlay = memo(() => {
const [session, setSession] = useState<ScreenCaptureSession | null>(null);
const [selections, setSelections] = useState<ChatPanelSelection[]>([]);
const capturingRef = useRef(false);
+ const startingCaptureRef = useRef(false);
const pendingWindowRef = useRef<ScreenCaptureSession['windows'][number] | null>(null);
const pointerStartRef = useRef<{ x: number; y: number } | null>(null);
@@ -50,6 +58,7 @@ const ScreenCaptureOverlay = memo(() => {
[selections],
);
const hasSelections = selections.length > 0;
+ const isCapturing = mode === 'capture';
const { hoveredWindow, handleMouseMove: hitTest } = useWindowHighlight(windows);
const {
dragRect,
@@ -111,15 +120,49 @@ const ScreenCaptureOverlay = memo(() => {
});
}, []);
+ /**
+ * The overlay opens as a plain composer; screenshots start only when the
+ * user asks. Main checks Screen Recording access and enumerates windows
+ * before we switch into capture mode.
+ */
+ const startCapture = useCallback(() => {
+ if (isCapturing || startingCaptureRef.current) return;
+ startingCaptureRef.current = true;
+ traceOverlayEvent('capture.start');
+
+ void Promise.resolve(window.electronAPI?.invoke?.('screenCapture.beginCapture'))
+ .then((started) => {
+ traceOverlayEvent('capture.start.result', { started: !!started });
+ if (started) setMode('capture');
+ })
+ .finally(() => {
+ startingCaptureRef.current = false;
+ });
+ }, [isCapturing, traceOverlayEvent]);
+
+ const exitCapture = useCallback(() => {
+ if (capturingRef.current) return;
+ traceOverlayEvent('capture.exit');
+ pendingWindowRef.current = null;
+ pointerStartRef.current = null;
+ reset();
+ setPendingSelectionRect(null);
+ setIsPanelHidden(false);
+ setMode('compose');
+ }, [reset, traceOverlayEvent]);
+
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
- if (e.key === 'Escape') {
+ if (e.key !== 'Escape') return;
+ if (resolveEscapeAction({ mode, selectionCount: selections.length }) === 'exitCapture') {
+ exitCapture();
+ } else {
handleClose();
}
};
window.addEventListener('keydown', onKeyDown);
return () => window.removeEventListener('keydown', onKeyDown);
- }, [handleClose]);
+ }, [exitCapture, handleClose, mode, selections.length]);
/**
* Upload status comes from the main process via
@@ -227,7 +270,9 @@ const ScreenCaptureOverlay = memo(() => {
const handleMouseDown = useCallback(
(e: ReactMouseEvent) => {
- if (e.button === 2) {
+ // In composer mode the transparent overlay only exists to host the panel,
+ // so a press anywhere outside it dismisses, like Spotlight.
+ if (!isCapturing || e.button === 2) {
handleClose();
return;
}
@@ -265,6 +310,7 @@ const ScreenCaptureOverlay = memo(() => {
}
},
[
+ isCapturing,
hasSelections,
hoveredWindow,
windows,
@@ -279,6 +325,8 @@ const ScreenCaptureOverlay = memo(() => {
const handleMouseMoveEvent = useCallback(
(e: ReactMouseEvent) => {
+ if (!isCapturing) return;
+
const pointerStart = pointerStartRef.current;
const dragging = isDraggingRef.current;
@@ -310,7 +358,15 @@ const ScreenCaptureOverlay = memo(() => {
hitTest(e.clientX, e.clientY);
}
},
- [hasSelections, isDraggingRef, onMouseDown, onMouseMove, hitTest, traceOverlayEvent],
+ [
+ isCapturing,
+ hasSelections,
+ isDraggingRef,
+ onMouseDown,
+ onMouseMove,
+ hitTest,
+ traceOverlayEvent,
+ ],
);
const handleMouseUp = useCallback(() => {
@@ -370,21 +426,23 @@ const ScreenCaptureOverlay = memo(() => {
isPreviewingSelection: !!pendingSelectionRect,
isSelecting: isPanelHidden,
});
- const showHover = hoveredWindow && !hasSelections && !isDragging && !committedSelectionRect;
+ const showHover =
+ isCapturing && hoveredWindow && !hasSelections && !isDragging && !committedSelectionRect;
const showDrag = isDragging && dragRect;
- const showHint = !hasSelections && !isDragging && !pendingSelectionRect;
+ const showHint = isCapturing && !hasSelections && !isDragging && !pendingSelectionRect;
return (
<div
- className={styles.overlay}
+ className={cn(styles.overlay, !isCapturing && styles.overlayCompose)}
style={{
- cursor: committedSelectionRect
- ? 'default'
- : isDragging
- ? 'crosshair'
- : hoveredWindow
- ? 'pointer'
- : 'crosshair',
+ cursor:
+ !isCapturing || committedSelectionRect
+ ? 'default'
+ : isDragging
+ ? 'crosshair'
+ : hoveredWindow
+ ? 'pointer'
+ : 'crosshair',
}}
onContextMenu={(e) => e.preventDefault()}
onMouseDown={handleMouseDown}
@@ -433,6 +491,7 @@ const ScreenCaptureOverlay = memo(() => {
<ChatPanel
agentId={session?.defaultAgentId}
agents={session?.agents}
+ capturing={isCapturing}
hidden={panelHidden}
modelId={session?.defaultModelId}
models={session?.models}
@@ -442,6 +501,7 @@ const ScreenCaptureOverlay = memo(() => {
viewportHeight={viewportHeight}
viewportWidth={viewportWidth}
onRemoveSelection={removeSelection}
+ onStartCapture={startCapture}
onSubmit={handleSubmit}
/>
diff --git a/apps/desktop/src/overlay/chatPanel.css.ts b/apps/desktop/src/overlay/chatPanel.css.ts
index 6ed77908cf9..82e3d591e56 100644
--- a/apps/desktop/src/overlay/chatPanel.css.ts
+++ b/apps/desktop/src/overlay/chatPanel.css.ts
@@ -165,6 +165,16 @@ export const iconBtn = style({
},
});
+export const captureBtn = style({
+ height: 32,
+ width: 32,
+});
+
+export const captureBtnActive = style({
+ background: v(vars.colorFillSecondary),
+ color: v(vars.colorText),
+});
+
export const multiSelectionSummary = style({
borderBottom: `1px solid ${v(vars.colorBorderSecondary)}`,
display: 'flex',
diff --git a/apps/desktop/src/overlay/constants.ts b/apps/desktop/src/overlay/constants.ts
index e0c9457c3e5..5ccf0bc19ad 100644
--- a/apps/desktop/src/overlay/constants.ts
+++ b/apps/desktop/src/overlay/constants.ts
@@ -1,8 +1,10 @@
export const OVERLAY_COPY = {
agentSelectLabel: 'Agent',
agentSelectPlaceholder: 'Default agent',
+ captureLabel: 'Take a screenshot',
clearSelectionLabel: 'Clear selection',
closeLabel: 'Close',
+ composePlaceholder: 'Ask anything…',
customRegionLabel: 'Custom region',
hintDragRegion: 'Capture a region',
hintDragTrigger: 'Drag',
diff --git a/apps/desktop/src/overlay/overlay.css.ts b/apps/desktop/src/overlay/overlay.css.ts
index 0bee7bfa941..329c5b6730d 100644
--- a/apps/desktop/src/overlay/overlay.css.ts
+++ b/apps/desktop/src/overlay/overlay.css.ts
@@ -87,6 +87,14 @@ export const overlay = style({
},
});
+/** Composer mode floats the panel over the desktop without dimming it. */
+export const overlayCompose = style({
+ 'background': 'transparent',
+ '::before': {
+ display: 'none',
+ },
+});
+
export const windowHighlight = style([
overlayFrame,
overlayInsetFrame,
diff --git a/apps/desktop/src/overlay/overlaySelectionState.test.ts b/apps/desktop/src/overlay/overlaySelectionState.test.ts
index 12a8e408291..7e6bc00388a 100644
--- a/apps/desktop/src/overlay/overlaySelectionState.test.ts
+++ b/apps/desktop/src/overlay/overlaySelectionState.test.ts
@@ -1,8 +1,21 @@
import { describe, expect, it } from 'vitest';
-import { resolveCommittedSelectionRect, shouldHideChatPanel } from './overlaySelectionState';
+import {
+ resolveCommittedSelectionRect,
+ resolveEscapeAction,
+ shouldHideChatPanel,
+} from './overlaySelectionState';
describe('overlaySelectionState', () => {
+ it('backs out of an empty capture pass to the composer on Esc', () => {
+ expect(resolveEscapeAction({ mode: 'capture', selectionCount: 0 })).toBe('exitCapture');
+ });
+
+ it('closes the overlay on Esc from the composer or once screenshots exist', () => {
+ expect(resolveEscapeAction({ mode: 'compose', selectionCount: 0 })).toBe('close');
+ expect(resolveEscapeAction({ mode: 'capture', selectionCount: 2 })).toBe('close');
+ });
+
it('keeps the pending selection rect visible until the committed selection arrives', () => {
expect(
resolveCommittedSelectionRect({
diff --git a/apps/desktop/src/overlay/overlaySelectionState.ts b/apps/desktop/src/overlay/overlaySelectionState.ts
index 59b2ec7211f..d56becc44cf 100644
--- a/apps/desktop/src/overlay/overlaySelectionState.ts
+++ b/apps/desktop/src/overlay/overlaySelectionState.ts
@@ -1,6 +1,18 @@
import type { ChatPanelSelection } from './ChatPanel';
import type { Rect } from './useDockPosition';
+export type OverlayMode = 'capture' | 'compose';
+
+/** Esc backs out of an empty capture pass before it closes the composer. */
+export const resolveEscapeAction = ({
+ mode,
+ selectionCount,
+}: {
+ mode: OverlayMode;
+ selectionCount: number;
+}): 'close' | 'exitCapture' =>
+ mode === 'capture' && selectionCount === 0 ? 'exitCapture' : 'close';
+
export const resolveCommittedSelectionRect = ({
pendingSelectionRect,
selection,