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,55 +56,40 @@ 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 {
|
/* Code modified from Microsoft's website.
|
||||||
// Init variable OS default
|
* https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#sample-code-for-detecting-arm-or-x86
|
||||||
var OS = "windows";
|
*/
|
||||||
|
// Wait for and get the high entropy values from async method
|
||||||
|
var ua = await navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]);
|
||||||
|
|
||||||
/* Code modified from Microsoft's website.
|
// Check if the platform is Windows
|
||||||
* https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#sample-code-for-detecting-arm-or-x86
|
if (navigator.userAgentData.platform === "Windows") {
|
||||||
*/
|
if (ua.architecture === 'arm') {
|
||||||
// Wait for and get the high entropy values from async method
|
OS = "windows-arm";
|
||||||
var ua = await navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]);
|
|
||||||
|
|
||||||
// Check if the platform is Windows
|
|
||||||
if (navigator.userAgentData.platform === "Windows") {
|
|
||||||
if (ua.architecture === 'arm') {
|
|
||||||
OS = "windows-arm";
|
|
||||||
} else {
|
|
||||||
if (ua.bitness === '64') {
|
|
||||||
OS = "windows-64";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Check other platforms
|
if (ua.bitness === '64') {
|
||||||
OS = getOSPlaformVersion();
|
OS = "windows-64";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Check other platforms
|
||||||
|
OS = getOSPlaformVersion();
|
||||||
|
}
|
||||||
|
|
||||||
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,58 +324,67 @@ $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;
|
||||||
|
|
||||||
/* Windows. */
|
/* Call async IIFE to await async function 'getOS' */
|
||||||
if (os == 'windows') {
|
(async function() {
|
||||||
showPlatformWarning('This Windows version might not be supported.');
|
os = await getOS();
|
||||||
}
|
|
||||||
else if (os == 'windows-arm') {
|
|
||||||
showPlatformWarning('Blender is not available for Windows ARM architecture yet.');
|
|
||||||
}
|
|
||||||
/* Linux. */
|
|
||||||
else if (os.startsWith('linux') || os.startsWith('freebsd')) {
|
|
||||||
|
|
||||||
/* Set the Download button platform to Linux. */
|
// TODO: remove console.log
|
||||||
downloadButtons = document.getElementsByClassName('dl-os-linux');
|
console.log('OS: ' + os);
|
||||||
|
|
||||||
if (os == 'freebsd') {
|
/* Windows. */
|
||||||
showPlatformWarning('There are no official builds for FreeBSD yet.');
|
if (os == 'windows') {
|
||||||
|
showPlatformWarning('This Windows version might not be supported.');
|
||||||
}
|
}
|
||||||
}
|
else if (os == 'windows-arm') {
|
||||||
/* macOS. */
|
showPlatformWarning('Blender is not available for Windows ARM architecture yet.');
|
||||||
else if (os.startsWith('macos') || os.startsWith('ios')) {
|
}
|
||||||
|
/* Linux. */
|
||||||
|
else if (os.startsWith('linux') || os.startsWith('freebsd')) {
|
||||||
|
|
||||||
/* Set the Download button platform to macOS. */
|
/* Set the Download button platform to Linux. */
|
||||||
downloadButtons = document.getElementsByClassName('dl-os-macos');
|
downloadButtons = document.getElementsByClassName('dl-os-linux');
|
||||||
|
|
||||||
if (os == 'macos-apple-silicon') {
|
if (os == 'freebsd') {
|
||||||
downloadButtons = document.getElementsByClassName('dl-os-macos-apple-silicon');
|
showPlatformWarning('There are no official builds for FreeBSD yet.');
|
||||||
|
|
||||||
/* Safari does not have a reliable way to detect if the system is Intel or Apple Silicon,
|
|
||||||
* Show Download buttons for both systems for the time being until navigator.gpu is supported. */
|
|
||||||
let is_safari = navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Chrome') <= -1;
|
|
||||||
|
|
||||||
if (is_safari) {
|
|
||||||
downloadButtons = document.querySelectorAll('[class^="dl-header-cta dl-os-macos"]');
|
|
||||||
}
|
}
|
||||||
} else if (os == 'macos-32' || os == 'macos-PPC') {
|
|
||||||
showPlatformWarning('This macOS version might not be supported.');
|
|
||||||
}
|
}
|
||||||
else if (os == 'ios') {
|
/* macOS. */
|
||||||
showPlatformWarning('Blender is not available for iOS yet.');
|
else if (os.startsWith('macos') || os.startsWith('ios')) {
|
||||||
|
|
||||||
|
/* Set the Download button platform to macOS. */
|
||||||
|
downloadButtons = document.getElementsByClassName('dl-os-macos');
|
||||||
|
|
||||||
|
if (os == 'macos-apple-silicon') {
|
||||||
|
downloadButtons = document.getElementsByClassName('dl-os-macos-apple-silicon');
|
||||||
|
|
||||||
|
/* Safari does not have a reliable way to detect if the system is Intel or Apple Silicon,
|
||||||
|
* Show Download buttons for both systems for the time being until navigator.gpu is supported. */
|
||||||
|
let is_safari = navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Chrome') <= -1;
|
||||||
|
|
||||||
|
if (is_safari) {
|
||||||
|
downloadButtons = document.querySelectorAll('[class^="dl-header-cta dl-os-macos"]');
|
||||||
|
}
|
||||||
|
} else if (os == 'macos-32' || os == 'macos-PPC') {
|
||||||
|
showPlatformWarning('This macOS version might not be supported.');
|
||||||
|
}
|
||||||
|
else if (os == 'ios') {
|
||||||
|
showPlatformWarning('Blender is not available for iOS yet.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Show the Download button for the current OS. */
|
/* Show the Download button for the current OS. */
|
||||||
for (var i = 0; i < downloadButtons.length; i++) {
|
for (var i = 0; i < downloadButtons.length; i++) {
|
||||||
downloadButtons[i].style.display = 'block';
|
downloadButtons[i].style.display = 'block';
|
||||||
downloadButtons[i].classList.add('active');
|
downloadButtons[i].classList.add('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
})();
|
||||||
|
|
||||||
/* 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. */
|
/* Click anywhere on the page to hide these popups. */
|
||||||
$(document).click(function () {
|
$(document).click(function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user