Error on "Open in desktop" click if URL is too long on Windows (#6768)

* pierremtb/issue6200-toast-error-if-windows-and-length-over-2046

* Add test for web
This commit is contained in:
Pierre Jacquier
2025-05-08 16:22:36 -04:00
committed by GitHub
parent c8747bd55a
commit a7f5c56ba1
2 changed files with 59 additions and 1 deletions

View File

@ -9,6 +9,8 @@ import {
} from '@src/lib/constants'
import { isDesktop } from '@src/lib/isDesktop'
import { Themes, getSystemTheme } from '@src/lib/theme'
import toast from 'react-hot-toast'
import { platform } from '@src/lib/utils'
/**
* This component is a handler that checks if a certain query parameter
@ -35,11 +37,24 @@ export const OpenInDesktopAppHandler = (props: React.PropsWithChildren) => {
*/
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()}` : ''}`
// TODO: find a way to workaround this limitation, modeling-app#6200
// Electron issue: https://github.com/electron/electron/issues/40776
// This 2046 value comes from https://issues.chromium.org/issues/41322340#comment3
// and empirical testing on Chrome and Windows 11
const MAX_URL_LENGTH = 2046
if (platform() === 'windows' && newURL.length > MAX_URL_LENGTH) {
toast.error(
'The URL is too long to open in the desktop app on Windows. Try another platform or use the web app.'
)
return
}
newSearchParams.delete(ASK_TO_OPEN_QUERY_PARAM)
globalThis.location.href = newURL
}