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,13 +74,16 @@ 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() {
|
||||||
|
return (async function() {
|
||||||
|
try {
|
||||||
|
// Init variable OS default
|
||||||
|
var OS = "windows";
|
||||||
|
|
||||||
/* Code modified from Microsoft's website.
|
/* 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
|
* 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"])
|
// Wait for and get the high entropy values from async method
|
||||||
.then(ua => {
|
var ua = await navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]);
|
||||||
// Init variable OS default
|
|
||||||
var OS = "windows";
|
|
||||||
|
|
||||||
// Check if the platform is Windows
|
// Check if the platform is Windows
|
||||||
if (navigator.userAgentData.platform === "Windows") {
|
if (navigator.userAgentData.platform === "Windows") {
|
||||||
@ -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