diff --git a/src/js/gui.js b/src/js/gui.js index 9d359d41..ad19f73a 100644 --- a/src/js/gui.js +++ b/src/js/gui.js @@ -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 }; diff --git a/src/js/utils/checkBrowserCompatibilty.js b/src/js/utils/checkBrowserCompatibilty.js index 92a6affa..1213074c 100644 --- a/src/js/utils/checkBrowserCompatibilty.js +++ b/src/js/utils/checkBrowserCompatibilty.js @@ -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) {