1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 16:55:24 +03:00

Update OS check (#4456)

* Update OS check

* Add MacOS
This commit is contained in:
Mark Haslinghuis 2025-05-02 22:22:16 +02:00 committed by GitHub
parent 5af689616f
commit fe72268dbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 5 deletions

View file

@ -3,6 +3,7 @@ import MSP from "./msp";
import Switchery from "switchery-latest";
import jBox from "jbox";
import $ from "jquery";
import { getOS } from "./utils/checkBrowserCompatibilty";
const TABS = {};
@ -47,7 +48,7 @@ class GuiControl {
this.allowedTabs = this.defaultAllowedTabsWhenDisconnected;
// check which operating system is user running
this.operating_system = GUI_checkOperatingSystem();
this.operating_system = getOS();
}
// Timer managing methods
// name = string
@ -480,10 +481,6 @@ class GuiControl {
}
}
function GUI_checkOperatingSystem() {
return navigator?.userAgentData?.platform || "Android";
}
const GUI = new GuiControl();
export { TABS };

View file

@ -1,5 +1,32 @@
import { Capacitor } from "@capacitor/core";
// Detects OS using modern userAgentData API with fallback to legacy platform
// Returns standardized OS name string or "unknown"
export function getOS() {
let os = "unknown";
const userAgent = window.navigator.userAgent;
const platform = window.navigator?.userAgentData?.platform || window.navigator.platform;
const macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K", "MacOS"];
const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"];
const iosPlatforms = ["iPhone", "iPad", "iPod"];
if (macosPlatforms.includes(platform)) {
os = "MacOS";
} else if (iosPlatforms.includes(platform)) {
os = "iOS";
} else if (windowsPlatforms.includes(platform)) {
os = "Windows";
} else if (/Android/.test(userAgent)) {
os = "Android";
} else if (/Linux/.test(platform)) {
os = "Linux";
} else if (/CrOS/.test(platform)) {
os = "ChromeOS";
}
return os;
}
export function isChromiumBrowser() {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
if (!navigator.userAgentData) {