import * as React from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { useI18n } from '@/lib/i18n'; import { getUrlScheme } from '@/lib/url'; import { getAppLinkConfirmationSnapshot, settleAppLinkConfirmation, subscribeAppLinkConfirmation, type AppLinkConfirmationChoice, } from './appLinkConfirmation'; /** * App-level dialog confirming application deep links (obsidian://, vscode://, * ...) rendered in chat markdown before the OS is asked to open them. * Dismissing via the close button, Escape, or the backdrop cancels the open. */ export const AppLinkConfirmDialog = () => { const { t } = useI18n(); const request = React.useSyncExternalStore( subscribeAppLinkConfirmation, getAppLinkConfirmationSnapshot, getAppLinkConfirmationSnapshot, ); const url = request?.url ?? ''; const scheme = getUrlScheme(url) ?? ''; const settle = React.useCallback((choice: AppLinkConfirmationChoice) => { settleAppLinkConfirmation(choice); }, []); return ( { if (!open) { settle('cancel'); } }} > {t('chat.appLink.confirm.title')} {scheme ? t('chat.appLink.confirm.description', { scheme: `${scheme}://` }) : t('chat.appLink.confirm.descriptionPlain')}
{url}
); };