Skip to content

Commit fe72268

Browse files
authored
Update OS check (#4456)
* Update OS check * Add MacOS
1 parent 5af6896 commit fe72268

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/js/gui.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import MSP from "./msp";
33
import Switchery from "switchery-latest";
44
import jBox from "jbox";
55
import $ from "jquery";
6+
import { getOS } from "./utils/checkBrowserCompatibilty";
67

78
const TABS = {};
89

@@ -47,7 +48,7 @@ class GuiControl {
4748
this.allowedTabs = this.defaultAllowedTabsWhenDisconnected;
4849

4950
// check which operating system is user running
50-
this.operating_system = GUI_checkOperatingSystem();
51+
this.operating_system = getOS();
5152
}
5253
// Timer managing methods
5354
// name = string
@@ -480,10 +481,6 @@ class GuiControl {
480481
}
481482
}
482483

483-
function GUI_checkOperatingSystem() {
484-
return navigator?.userAgentData?.platform || "Android";
485-
}
486-
487484
const GUI = new GuiControl();
488485

489486
export { TABS };

src/js/utils/checkBrowserCompatibilty.js

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
import { Capacitor } from "@capacitor/core";
22

3+
// Detects OS using modern userAgentData API with fallback to legacy platform
4+
// Returns standardized OS name string or "unknown"
5+
export function getOS() {
6+
let os = "unknown";
7+
const userAgent = window.navigator.userAgent;
8+
const platform = window.navigator?.userAgentData?.platform || window.navigator.platform;
9+
const macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K", "MacOS"];
10+
const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"];
11+
const iosPlatforms = ["iPhone", "iPad", "iPod"];
12+
13+
if (macosPlatforms.includes(platform)) {
14+
os = "MacOS";
15+
} else if (iosPlatforms.includes(platform)) {
16+
os = "iOS";
17+
} else if (windowsPlatforms.includes(platform)) {
18+
os = "Windows";
19+
} else if (/Android/.test(userAgent)) {
20+
os = "Android";
21+
} else if (/Linux/.test(platform)) {
22+
os = "Linux";
23+
} else if (/CrOS/.test(platform)) {
24+
os = "ChromeOS";
25+
}
26+
27+
return os;
28+
}
29+
330
export function isChromiumBrowser() {
431
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
532
if (!navigator.userAgentData) {

0 commit comments

Comments
 (0)