Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-app): center plugin consent modal over the plugin embed

Andy Paviafaf2b9443dc3
diff --git a/desktop-app/ui/src/components/PluginConsentModal/index.tsx b/desktop-app/ui/src/components/PluginConsentModal/index.tsx
index 6174af16b..265506e26 100644
--- a/desktop-app/ui/src/components/PluginConsentModal/index.tsx
+++ b/desktop-app/ui/src/components/PluginConsentModal/index.tsx
@@ -1,8 +1,23 @@
-import { useEffect, useId, useRef, useState } from 'react'
+import { type CSSProperties, useEffect, useId, useLayoutEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import { Button } from '@components/Common'
import type { PluginConsentModalProps } from './types'
+/**
+ * The plugin's live rectangle in the renderer is the `.sandbox-ui-embed-slot`
+ * div that the native WebContentsView floats above (see SandboxUiPage). While
+ * this prompt is up the native view is hidden, but the slot stays laid out — so
+ * it is the correct box to center the prompt over, rather than the whole
+ * desktop window. Returns null when no plugin embed is mounted, which lets the
+ * prompt fall back to full-window centering.
+ */
+function readEmbedSlotRect(): DOMRect | null {
+ const el = document.querySelector('.sandbox-ui-embed-slot')
+ if (!el) return null
+ const rect = el.getBoundingClientRect()
+ return rect.width > 0 && rect.height > 0 ? rect : null
+}
+
/**
* The plugin permission prompt (spec §9.2, §9.4).
*
@@ -34,6 +49,25 @@ export function PluginConsentModal({ request, onResolve }: PluginConsentModalPro
allowButtonRef.current?.focus()
}, [request.promptId])
+ // Track the plugin embed's rectangle so the prompt centers over the plugin
+ // UI, not the entire desktop app. Re-measure on the same signals that move
+ // the embed slot (resize, scroll, sidebar/layout shifts).
+ const [slotRect, setSlotRect] = useState<DOMRect | null>(null)
+ useLayoutEffect(() => {
+ const measure = (): void => setSlotRect(readEmbedSlotRect())
+ measure()
+ const slot = document.querySelector('.sandbox-ui-embed-slot')
+ const observer = slot ? new ResizeObserver(measure) : null
+ if (slot) observer?.observe(slot)
+ window.addEventListener('resize', measure)
+ window.addEventListener('scroll', measure, true)
+ return () => {
+ observer?.disconnect()
+ window.removeEventListener('resize', measure)
+ window.removeEventListener('scroll', measure, true)
+ }
+ }, [request.promptId])
+
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
// Escape denies everything — a prompt nobody answered is not consent.
@@ -52,8 +86,26 @@ export function PluginConsentModal({ request, onResolve }: PluginConsentModalPro
})
}
+ // Confine the fixed backdrop to the plugin's rectangle so `place-items:
+ // center` centers the dialog over the plugin UI. Setting right/bottom to auto
+ // overrides the stylesheet's `inset: 0`. No slot → undefined → full-window.
+ const backdropStyle: CSSProperties | undefined = slotRect
+ ? {
+ top: slotRect.top,
+ left: slotRect.left,
+ width: slotRect.width,
+ height: slotRect.height,
+ right: 'auto',
+ bottom: 'auto',
+ }
+ : undefined
+
return createPortal(
- <div className="confirm-dialog-backdrop da-plugin-consent-backdrop" role="presentation">
+ <div
+ className="confirm-dialog-backdrop da-plugin-consent-backdrop"
+ role="presentation"
+ style={backdropStyle}
+ >
<div
className="confirm-dialog da-plugin-consent"
role="dialog"