UI: Implement JavaScript getOS function Windows platform architecture detection #104136
@ -1,7 +1,10 @@
|
||||
/* Code modified from VLC's website.
|
||||
* https://code.videolan.org/VideoLAN.org/websites/-/blob/master/www.videolan.org/include/os-specific.php
|
||||
*/
|
||||
function getOS() {
|
||||
/*
|
||||
* Function 'getOS' must be asynchronous to support the async browser method 'navigator.userAgentData.getHighEntropyValues' and nested promise chains.
|
||||
*/
|
||||
async function getOS() {
|
||||
// Init variable OS default
|
||||
var OS = "windows";
|
||||
|
||||
@ -53,32 +56,18 @@ function getOS() {
|
||||
}
|
||||
|
||||
// Create functions init
|
||||
function init() {
|
||||
async function init() {
|
||||
// Check if the browser method 'navigator.userAgentData' is supported
|
||||
if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') {
|
||||
return (async function() {
|
||||
try {
|
||||
var value = await initAsync();
|
||||
|
||||
console.log(value);
|
||||
|
||||
// TODO: fix return returning undefined
|
||||
return value;
|
||||
} catch (error) {}
|
||||
})();
|
||||
return await initAsync();
|
||||
} else {
|
||||
return initSync();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: fix function async initAsync
|
||||
// Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers)
|
||||
function initAsync() {
|
||||
return (async function() {
|
||||
async function initAsync() {
|
||||
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
|
||||
*/
|
||||
@ -101,7 +90,6 @@ function getOS() {
|
||||
|
||||
return OS;
|
||||
} catch (e) {}
|
||||
})();
|
||||
}
|
||||
|
||||
// Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers)
|
||||
@ -140,5 +128,5 @@ function getOS() {
|
||||
return OS;
|
||||
}
|
||||
|
||||
return init();
|
||||
return await init();
|
||||
}
|
||||
|
@ -324,7 +324,14 @@ $analytics_event_name = 'Downloads+Blender';
|
||||
let downloadButtons = document.getElementsByClassName('dl-os-windows');
|
||||
|
||||
/* Get the current operating system. See get_os.js */
|
||||
let os = getOS();
|
||||
let os;
|
||||
|
||||
/* Call async IIFE to await async function 'getOS' */
|
||||
(async function() {
|
||||
os = await getOS();
|
||||
|
||||
// TODO: remove console.log
|
||||
console.log('OS: ' + os);
|
||||
|
||||
/* Windows. */
|
||||
if (os == 'windows') {
|
||||
@ -376,6 +383,8 @@ $analytics_event_name = 'Downloads+Blender';
|
||||
/* Style the other platforms button, so we can highlight alternative builds on the same platform. */
|
||||
$('#menu-other-platforms').addClass('dl-other-list-os-' + os);
|
||||
$('.dl-header-other').addClass('current-os-' + os);
|
||||
})();
|
||||
|
||||
|
||||
/* Click anywhere on the page to hide these popups. */
|
||||
$(document).click(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user