UI: Implement JavaScript getOS function Windows platform architecture detection #104136
@ -56,7 +56,16 @@ function getOS() {
|
||||
function init() {
|
||||
// Check if the browser method 'navigator.userAgentData' is supported
|
||||
if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') {
|
||||
return initAsync();
|
||||
return (async function() {
|
||||
try {
|
||||
var value = await initAsync();
|
||||
|
||||
console.log(value);
|
||||
|
||||
// TODO: fix return returning undefined
|
||||
return value;
|
||||
} catch (error) {}
|
||||
})();
|
||||
} else {
|
||||
return initSync();
|
||||
}
|
||||
@ -65,14 +74,17 @@ function getOS() {
|
||||
// TODO: fix function async initAsync
|
||||
// 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 => {
|
||||
return (async function() {
|
||||
try {
|
||||
// Init variable OS default
|
||||
var OS = "windows";
|
||||
|
||||
/* 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
|
||||
*/
|
||||
// Wait for and get the high entropy values from async method
|
||||
var ua = await navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]);
|
||||
|
||||
// Check if the platform is Windows
|
||||
if (navigator.userAgentData.platform === "Windows") {
|
||||
if (ua.architecture === 'arm') {
|
||||
@ -88,7 +100,8 @@ function getOS() {
|
||||
}
|
||||
|
||||
return OS;
|
||||
});
|
||||
} catch (e) {}
|
||||
})();
|
||||
}
|
||||
|
||||
// Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers)
|
||||
|
Loading…
Reference in New Issue
Block a user