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