UI: Implement JavaScript getOS function Windows platform architecture detection #104136
@ -1,9 +1,99 @@
|
|||||||
/* 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() {
|
/*
|
||||||
var OS = "windows"; //Default
|
* 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
|
||||||
|
let OS = "windows";
|
||||||
|
|
||||||
|
function getOSPlaformVersion() {
|
||||||
|
//MacOS, MacOS X, macOS
|
||||||
|
if (navigator.appVersion.indexOf("Mac") != -1) {
|
||||||
|
if (navigator.platform.indexOf("MacPPC") != -1 || navigator.platform.indexOf("PowerPC") != -1) {
|
||||||
|
OS = "macos-PPC";
|
||||||
|
} else if (navigator.userAgent.indexOf("OS X 10.5") != -1 ||
|
||||||
|
navigator.userAgent.indexOf("OS X 10.6") != -1) {
|
||||||
|
OS = "macos-32";
|
||||||
|
} else {
|
||||||
|
OS = "macos";
|
||||||
|
try {
|
||||||
|
var glcontext = document.createElement("canvas").getContext("webgl");
|
||||||
|
var debugrenderer = glcontext ? glcontext.getExtension('WEBGL_debug_renderer_info') : null;
|
||||||
|
var renderername = debugrenderer && glcontext.getParameter(debugrenderer.UNMASKED_RENDERER_WEBGL) || "";
|
||||||
|
if (renderername.match(/Apple M/) || renderername.match(/Apple GPU/)) {
|
||||||
|
OS = "macos-apple-silicon";
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linux
|
||||||
|
if (navigator.platform.indexOf("Linux") != -1) {
|
||||||
|
if ((navigator.userAgent.indexOf("Ubuntu") != -1) ||
|
||||||
|
(navigator.userAgent.indexOf("ubuntu") != -1)) OS = "linux-ubuntu";
|
||||||
|
else if (navigator.userAgent.indexOf("Debian") != -1) OS = "linux-debian";
|
||||||
|
else if (navigator.userAgent.indexOf("Android") != -1) OS = "linux-android";
|
||||||
|
else if (navigator.userAgent.indexOf("Mandriva") != -1) OS = "linux-mandriva";
|
||||||
|
else if (navigator.userAgent.indexOf("Red Hat") != -1) OS = "linux-redhat";
|
||||||
|
else if (navigator.userAgent.indexOf("Fedora") != -1) OS = "linux-fedora";
|
||||||
|
else if (navigator.userAgent.indexOf("SUSE") != -1) OS = "linux-suse";
|
||||||
|
else if (navigator.userAgent.indexOf("Gentoo") != -1) OS = "linux-gentoo";
|
||||||
|
else OS = "linux";
|
||||||
|
}
|
||||||
|
|
||||||
|
// iOS
|
||||||
|
if (navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1) {
|
||||||
|
OS = "ios";
|
||||||
|
}
|
||||||
|
|
||||||
|
// FreeBSD
|
||||||
|
if (navigator.platform.indexOf("freebsd") != -1) OS = "freebsd";
|
||||||
|
if (navigator.platform.indexOf("FreeBSD") != -1) OS = "freebsd";
|
||||||
|
|
||||||
|
return OS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create functions init
|
||||||
|
async function init() {
|
||||||
|
// Check if the browser method 'navigator.userAgentData' is supported
|
||||||
|
if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') {
|
||||||
|
return await initAsync();
|
||||||
|
} else {
|
||||||
|
return initSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers)
|
||||||
|
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
|
||||||
|
let 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 {
|
||||||
|
// Check other platforms
|
||||||
|
OS = getOSPlaformVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
return OS;
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers)
|
||||||
|
function initSync() {
|
||||||
if (navigator.appVersion.indexOf("Win") != -1) {
|
if (navigator.appVersion.indexOf("Win") != -1) {
|
||||||
if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 &&
|
if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 &&
|
||||||
navigator.userAgent.indexOf('Windows NT 5.1') == -1 &&
|
navigator.userAgent.indexOf('Windows NT 5.1') == -1 &&
|
||||||
@ -31,45 +121,12 @@ function getOS() {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//MacOS, MacOS X, macOS
|
|
||||||
if (navigator.appVersion.indexOf("Mac") != -1) {
|
|
||||||
if (navigator.platform.indexOf("MacPPC") != -1 || navigator.platform.indexOf("PowerPC") != -1) {
|
|
||||||
OS = "macos-PPC";
|
|
||||||
} else if (navigator.userAgent.indexOf("OS X 10.5") != -1 ||
|
|
||||||
navigator.userAgent.indexOf("OS X 10.6") != -1) {
|
|
||||||
OS = "macos-32";
|
|
||||||
} else {
|
} else {
|
||||||
OS = "macos";
|
OS = getOSPlaformVersion();
|
||||||
try {
|
|
||||||
var glcontext = document.createElement("canvas").getContext("webgl");
|
|
||||||
var debugrenderer = glcontext ? glcontext.getExtension('WEBGL_debug_renderer_info') : null;
|
|
||||||
var renderername = debugrenderer && glcontext.getParameter(debugrenderer.UNMASKED_RENDERER_WEBGL) || "";
|
|
||||||
if (renderername.match(/Apple M/) || renderername.match(/Apple GPU/)) {
|
|
||||||
OS = "macos-apple-silicon";
|
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (navigator.platform.indexOf("Linux") != -1) {
|
|
||||||
if ((navigator.userAgent.indexOf("Ubuntu") != -1) ||
|
|
||||||
(navigator.userAgent.indexOf("ubuntu") != -1)) OS = "linux-ubuntu";
|
|
||||||
else if (navigator.userAgent.indexOf("Debian") != -1) OS = "linux-debian";
|
|
||||||
else if (navigator.userAgent.indexOf("Android") != -1) OS = "linux-android";
|
|
||||||
else if (navigator.userAgent.indexOf("Mandriva") != -1) OS = "linux-mandriva";
|
|
||||||
else if (navigator.userAgent.indexOf("Red Hat") != -1) OS = "linux-redhat";
|
|
||||||
else if (navigator.userAgent.indexOf("Fedora") != -1) OS = "linux-fedora";
|
|
||||||
else if (navigator.userAgent.indexOf("SUSE") != -1) OS = "linux-suse";
|
|
||||||
else if (navigator.userAgent.indexOf("Gentoo") != -1) OS = "linux-gentoo";
|
|
||||||
else OS = "linux";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1) {
|
|
||||||
OS = "ios";
|
|
||||||
}
|
|
||||||
if (navigator.platform.indexOf("freebsd") != -1) OS = "freebsd";
|
|
||||||
if (navigator.platform.indexOf("FreeBSD") != -1) OS = "freebsd";
|
|
||||||
|
|
||||||
return OS;
|
return OS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return await init();
|
||||||
|
}
|
||||||
|
@ -324,15 +324,23 @@ $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();
|
||||||
|
|
||||||
/* Windows. */
|
/* Windows. */
|
||||||
if (os == 'windows') {
|
if (os == 'windows') {
|
||||||
showPlatformWarning('This Windows version might not be supported.');
|
showPlatformWarning('This Windows version might not be supported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Windows Arm. */
|
||||||
else if (os == 'windows-arm') {
|
else if (os == 'windows-arm') {
|
||||||
showPlatformWarning('Blender is not available for Windows ARM architecture yet.');
|
/* Set the Download button platform to Windows Arm. */
|
||||||
|
downloadButtons = document.getElementsByClassName('dl-os-windows-arm');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Linux. */
|
/* Linux. */
|
||||||
else if (os.startsWith('linux') || os.startsWith('freebsd')) {
|
else if (os.startsWith('linux') || os.startsWith('freebsd')) {
|
||||||
|
|
||||||
@ -376,6 +384,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