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,55 +56,40 @@ 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() {
|
||||
try {
|
||||
// Init variable OS default
|
||||
var OS = "windows";
|
||||
async function initAsync() {
|
||||
try {
|
||||
/* 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"]);
|
||||
|
||||
/* 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
|
||||
if (navigator.userAgentData.platform === "Windows") {
|
||||
if (ua.architecture === 'arm') {
|
||||
OS = "windows-arm";
|
||||
} else {
|
||||
if (ua.bitness === '64') {
|
||||
OS = "windows-64";
|
||||
}
|
||||
}
|
||||
// Check if the platform is Windows
|
||||
if (navigator.userAgentData.platform === "Windows") {
|
||||
if (ua.architecture === 'arm') {
|
||||
OS = "windows-arm";
|
||||
} else {
|
||||
// Check other platforms
|
||||
OS = getOSPlaformVersion();
|
||||
if (ua.bitness === '64') {
|
||||
OS = "windows-64";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check other platforms
|
||||
OS = getOSPlaformVersion();
|
||||
}
|
||||
|
||||
return OS;
|
||||
} catch (e) {}
|
||||
})();
|
||||
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,58 +324,67 @@ $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;
|
||||
|
||||
/* Windows. */
|
||||
if (os == 'windows') {
|
||||
showPlatformWarning('This Windows version might not be supported.');
|
||||
}
|
||||
else if (os == 'windows-arm') {
|
||||
showPlatformWarning('Blender is not available for Windows ARM architecture yet.');
|
||||
}
|
||||
/* Linux. */
|
||||
else if (os.startsWith('linux') || os.startsWith('freebsd')) {
|
||||
/* Call async IIFE to await async function 'getOS' */
|
||||
(async function() {
|
||||
os = await getOS();
|
||||
|
||||
/* Set the Download button platform to Linux. */
|
||||
downloadButtons = document.getElementsByClassName('dl-os-linux');
|
||||
// TODO: remove console.log
|
||||
console.log('OS: ' + os);
|
||||
|
||||
if (os == 'freebsd') {
|
||||
showPlatformWarning('There are no official builds for FreeBSD yet.');
|
||||
/* Windows. */
|
||||
if (os == 'windows') {
|
||||
showPlatformWarning('This Windows version might not be supported.');
|
||||
}
|
||||
}
|
||||
/* macOS. */
|
||||
else if (os.startsWith('macos') || os.startsWith('ios')) {
|
||||
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 macOS. */
|
||||
downloadButtons = document.getElementsByClassName('dl-os-macos');
|
||||
/* Set the Download button platform to Linux. */
|
||||
downloadButtons = document.getElementsByClassName('dl-os-linux');
|
||||
|
||||
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"]');
|
||||
if (os == 'freebsd') {
|
||||
showPlatformWarning('There are no official builds for FreeBSD yet.');
|
||||
}
|
||||
} 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.');
|
||||
/* macOS. */
|
||||
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. */
|
||||
for (var i = 0; i < downloadButtons.length; i++) {
|
||||
downloadButtons[i].style.display = 'block';
|
||||
downloadButtons[i].classList.add('active');
|
||||
}
|
||||
/* Show the Download button for the current OS. */
|
||||
for (var i = 0; i < downloadButtons.length; i++) {
|
||||
downloadButtons[i].style.display = 'block';
|
||||
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. */
|
||||
$(document).click(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user