UI: Implement JavaScript getOS function Windows platform architecture detection #104136
@ -56,7 +56,16 @@ function getOS() {
|
|||||||
function init() {
|
function init() {
|
||||||
// Check if the browser method 'navigator.userAgentData' is supported
|
// Check if the browser method 'navigator.userAgentData' is supported
|
||||||
if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') {
|
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 {
|
} else {
|
||||||
return initSync();
|
return initSync();
|
||||||
}
|
}
|
||||||
@ -65,14 +74,17 @@ function getOS() {
|
|||||||
// TODO: fix function async initAsync
|
// TODO: fix function async initAsync
|
||||||
// Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers)
|
// Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers)
|
||||||
function initAsync() {
|
function initAsync() {
|
||||||
/* Code modified from Microsoft's website.
|
return (async function() {
|
||||||
* https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#sample-code-for-detecting-arm-or-x86
|
try {
|
||||||
*/
|
|
||||||
navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"])
|
|
||||||
.then(ua => {
|
|
||||||
// Init variable OS default
|
// Init variable OS default
|
||||||
var OS = "windows";
|
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
|
// Check if the platform is Windows
|
||||||
if (navigator.userAgentData.platform === "Windows") {
|
if (navigator.userAgentData.platform === "Windows") {
|
||||||
if (ua.architecture === 'arm') {
|
if (ua.architecture === 'arm') {
|
||||||
@ -88,7 +100,8 @@ function getOS() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return OS;
|
return OS;
|
||||||
});
|
} catch (e) {}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers)
|
// Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers)
|
||||||
|
Loading…
Reference in New Issue
Block a user