mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
Fix OS detection for cross-browser compatibility (#8784)
* chore: add .python-version to .gitignore * fix(get_os): ensure compatibility across all browsers * format * chore: add ts ignore comment again * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
This commit is contained in:
parent
6073736651
commit
2cc813a287
5
.changeset/grumpy-lies-grin.md
Normal file
5
.changeset/grumpy-lies-grin.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"website": minor
|
||||
---
|
||||
|
||||
feat:Fix OS detection for cross-browser compatibility
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,6 +12,7 @@ __tmp/*
|
||||
*.pyi
|
||||
py.typed
|
||||
.ipynb_checkpoints/
|
||||
.python-version
|
||||
|
||||
# JS build
|
||||
gradio/templates/*
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user