UI: Implement JavaScript getOS function Windows platform architecture detection #104136

Merged
Márton Lente merged 15 commits from get-os-win-arm into main 2024-11-08 12:03:41 +01:00
Showing only changes of commit b55a6cf7bd - Show all commits

View File

@ -5,33 +5,7 @@ function getOS() {
// Init variable OS default
var OS = "windows";
function getOSWinVersionAsync() {
/* Code modified from Microsoft's website.
* https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#sample-code-for-detecting-arm-or-x86
*/
navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"])
.then(ua => {
if (navigator.userAgentData.platform === "Windows") {
if (ua.architecture === 'x86') {
if (ua.bitness === '64') {
console.log("x86_64");
}
else if (ua.bitness === '32') {
console.log("x86");
}
}
if (ua.architecture === 'arm') {
OS = "windows-arm";
} else {
if (ua.bitness === '64') {
OS = "windows-64";
}
}
}
});
}
function getOSWinVersionSync() {
function getOSWinVersionSync() {
if (navigator.appVersion.indexOf("Win") != -1) {
if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 &&
navigator.userAgent.indexOf('Windows NT 5.1') == -1 &&
@ -120,6 +94,41 @@ function getOS() {
}
}
// Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers)
function initAsync() {
/* Code modified from Microsoft's website.
* https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#sample-code-for-detecting-arm-or-x86
*/
navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"])
.then(ua => {
// Check if the platform is Windows
if (navigator.userAgentData.platform === "Windows") {
if (ua.architecture === 'x86') {
if (ua.bitness === '64') {
console.log("x86_64");
}
else if (ua.bitness === '32') {
console.log("x86");
}
}
if (ua.architecture === 'arm') {
OS = "windows-arm";
} else {
if (ua.bitness === '64') {
OS = "windows-64";
}
}
} else {
// Check other platforms
getOSMacVersion();
getOSLinuxVersion();
getOSiPadVersion();
getOSFreeBSDVersion();
}
});
}
// Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers)
function initSync() {
getOSWinVersionSync();
getOSMacVersion();
@ -128,18 +137,6 @@ function getOS() {
getOSFreeBSDVersion();
}
function initAsync() {
navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"])
.then(function(ua) {
// TODO: make function getOSWinVersionAsync run sequentially
getOSWinVersionAsync();
getOSMacVersion();
getOSLinuxVersion();
getOSiPadVersion();
getOSFreeBSDVersion();
})
}
init();
return OS;