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 f49fca366e - Show all commits

View File

@ -5,7 +5,33 @@ function getOS() {
// Init variable OS default // Init variable OS default
var OS = "windows"; var OS = "windows";
function getOSWinVersion() { 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() {
if (navigator.appVersion.indexOf("Win") != -1) { if (navigator.appVersion.indexOf("Win") != -1) {
if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 &&
navigator.userAgent.indexOf('Windows NT 5.1') == -1 && navigator.userAgent.indexOf('Windows NT 5.1') == -1 &&
@ -95,26 +121,22 @@ function getOS() {
} }
function initSync() { function initSync() {
getOSWinVersion(); getOSWinVersionSync();
getOSMacVersion(); getOSMacVersion();
getOSLinuxVersion(); getOSLinuxVersion();
getOSiPadVersion(); getOSiPadVersion();
getOSFreeBSDVersion(); getOSFreeBSDVersion();
console.log('initSync');
} }
function initAsync() { function initAsync() {
navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"])
.then(function(ua) { .then(function(ua) {
// TODO: create function getOSWinVersionAsync // TODO: make function getOSWinVersionAsync run sequentially
// getOSWinVersionAsync(); getOSWinVersionAsync();
getOSMacVersion(); getOSMacVersion();
getOSLinuxVersion(); getOSLinuxVersion();
getOSiPadVersion(); getOSiPadVersion();
getOSFreeBSDVersion(); getOSFreeBSDVersion();
console.log('initAsync');
}) })
} }