import { getSystemTheme, Themes } from 'lib/theme' import { ZOO_STUDIO_PROTOCOL } from 'lib/constants' import { isDesktop } from 'lib/isDesktop' import { useSearchParams } from 'react-router-dom' import { ASK_TO_OPEN_QUERY_PARAM } from 'lib/constants' import { VITE_KC_SITE_BASE_URL } from 'env' import { ActionButton } from './ActionButton' import { Transition } from '@headlessui/react' /** * This component is a handler that checks if a certain query parameter * is present, and if so, it will show a modal asking the user if they * want to open the current page in the desktop app. */ export const OpenInDesktopAppHandler = (props: React.PropsWithChildren) => { const theme = getSystemTheme() const buttonClasses = 'bg-transparent flex-0 hover:bg-primary/10 dark:hover:bg-primary/10' const pathLogomarkSvg = `${isDesktop() ? '.' : ''}/zma-logomark${ theme === Themes.Light ? '-dark' : '' }.svg` const [searchParams, setSearchParams] = useSearchParams() // We also ignore this param on desktop, as it is redundant const hasAskToOpenParam = !isDesktop() && searchParams.has(ASK_TO_OPEN_QUERY_PARAM) /** * This function removes the query param to ask to open in desktop app * and then navigates to the same route but with our custom protocol * `zoo-studio:` instead of `https://${BASE_URL}`, to trigger the user's * desktop app to open. */ function onOpenInDesktopApp() { const newSearchParams = new URLSearchParams(globalThis.location.search) newSearchParams.delete(ASK_TO_OPEN_QUERY_PARAM) const newURL = `${ZOO_STUDIO_PROTOCOL}${globalThis.location.pathname.replace( '/', '' )}${searchParams.size > 0 ? `?${newSearchParams.toString()}` : ''}` globalThis.location.href = newURL } /** * Just remove the query param to ask to open in desktop app * and continue to the web app. */ function continueToWebApp() { searchParams.delete(ASK_TO_OPEN_QUERY_PARAM) setSearchParams(searchParams) } return hasAskToOpenParam ? (

Launching{' '} Zoo Modeling App

Choose where to open this link...

Open in desktop app Download desktop app
Continue to web app
) : ( props.children ) }