diff --git a/.changeset/grumpy-lies-grin.md b/.changeset/grumpy-lies-grin.md new file mode 100644 index 0000000000..b6197a78c6 --- /dev/null +++ b/.changeset/grumpy-lies-grin.md @@ -0,0 +1,5 @@ +--- +"website": minor +--- + +feat:Fix OS detection for cross-browser compatibility diff --git a/.gitignore b/.gitignore index 3534f37c56..153c754847 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ __tmp/* *.pyi py.typed .ipynb_checkpoints/ +.python-version # JS build gradio/templates/* diff --git a/js/_website/src/lib/components/search/search.svelte b/js/_website/src/lib/components/search/search.svelte index 9db8c272ae..a344afecbc 100644 --- a/js/_website/src/lib/components/search/search.svelte +++ b/js/_website/src/lib/components/search/search.svelte @@ -44,16 +44,25 @@ el.focus(); } - function get_os() { + function get_os(): string { // @ts-ignore - userAgentData is not yet in the TS types as it is currently experimental - return navigator.userAgentData.platform ?? navigator.userAgent; + if (typeof navigator !== "undefined") { + const userAgent = navigator.userAgent.toLowerCase(); + if (userAgent.indexOf("win") > -1) return "Windows"; + if (userAgent.indexOf("mac") > -1) return "MacOS"; + if (userAgent.indexOf("linux") > -1) return "Linux"; + if (userAgent.indexOf("android") > -1) return "Android"; + if (userAgent.indexOf("iphone") > -1 || userAgent.indexOf("ipad") > -1) + return "iOS"; + } + return "Unknown"; } let meta_key = "⌘"; $: if (browser && navigator) { let os = get_os(); - meta_key = os.includes("Mac") || os.includes("mac") ? "⌘" : "CTRL+"; + meta_key = os === "MacOS" || os === "iOS" ? "⌘" : "CTRL+"; } function handle_key_down(e: KeyboardEvent): void {