From 14110f48a68e6015f878f872717d45a23909cbff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 14:34:14 +0100 Subject: [PATCH 01/15] Refactor: Js function getOS to named functions --- themes/bthree/assets/js/get_os.js | 133 ++++++++++++++++++------------ 1 file changed, 78 insertions(+), 55 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index c88f0b9..f5513e3 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -2,74 +2,97 @@ * https://code.videolan.org/VideoLAN.org/websites/-/blob/master/www.videolan.org/include/os-specific.php */ function getOS() { - var OS = "windows"; //Default + // Init variable OS default + var OS = "windows"; - if (navigator.appVersion.indexOf("Win") != -1) { - if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && - navigator.userAgent.indexOf('Windows NT 5.1') == -1 && - (navigator.userAgent.indexOf('Win64') > -1 || - navigator.platform == 'Win64' || - navigator.userAgent.indexOf('x86_64') > -1 || - navigator.userAgent.indexOf('x86_64') > -1 || - navigator.userAgent.indexOf('amd64') > -1 || - navigator.userAgent.indexOf('AMD64') > -1 || - navigator.userAgent.indexOf('WOW64') > -1 - )) { - OS = "windows-64"; - } else { - if (window.external && window.external.getHostEnvironmentValue && window.external.getHostEnvironmentValue('os-architecture').indexOf("ARM64") !== -1) { - OS = "windows-arm"; + function getOSWinVersion() { + if (navigator.appVersion.indexOf("Win") != -1) { + if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && + navigator.userAgent.indexOf('Windows NT 5.1') == -1 && + (navigator.userAgent.indexOf('Win64') > -1 || + navigator.platform == 'Win64' || + navigator.userAgent.indexOf('x86_64') > -1 || + navigator.userAgent.indexOf('x86_64') > -1 || + navigator.userAgent.indexOf('amd64') > -1 || + navigator.userAgent.indexOf('AMD64') > -1 || + navigator.userAgent.indexOf('WOW64') > -1 + )) { + OS = "windows-64"; } else { - try { - var canvas = document.createElement('canvas'); - var gl = canvas.getContext('webgl'); + if (window.external && window.external.getHostEnvironmentValue && window.external.getHostEnvironmentValue('os-architecture').indexOf("ARM64") !== -1) { + OS = "windows-arm"; + } else { + try { + var canvas = document.createElement('canvas'); + var gl = canvas.getContext('webgl'); - var debugInfo = gl.getExtension('WEBGL_debug_renderer_info'); - var renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL); - if (renderer.indexOf("Qualcomm") !== -1) - OS = "windows-arm"; + var debugInfo = gl.getExtension('WEBGL_debug_renderer_info'); + var renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL); + if (renderer.indexOf("Qualcomm") !== -1) + OS = "windows-arm"; + } catch (e) {} + } + } + } + } + + function getOSMacVersion() { + //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) {} } } } - //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) {} + function getOSLinuxVersion() { + 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.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"; + + function getOSiPadVersion() { + if (navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1) { + OS = "ios"; + } } - if (navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1) { - OS = "ios"; + function getOSFreeBSDVersion() { + if (navigator.platform.indexOf("freebsd") != -1) OS = "freebsd"; + if (navigator.platform.indexOf("FreeBSD") != -1) OS = "freebsd"; } - if (navigator.platform.indexOf("freebsd") != -1) OS = "freebsd"; - if (navigator.platform.indexOf("FreeBSD") != -1) OS = "freebsd"; + + function init() { + getOSWinVersion(); + getOSMacVersion(); + getOSLinuxVersion(); + getOSiPadVersion(); + getOSFreeBSDVersion(); + } + + init(); return OS; } -- 2.30.2 From 2be80e052685e84441138a1455285085beb15e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 14:39:01 +0100 Subject: [PATCH 02/15] UI: Add js function getOS conditionals for navigator.userAgentData browser support base --- themes/bthree/assets/js/get_os.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index f5513e3..a9d41bb 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -5,6 +5,13 @@ function getOS() { // Init variable OS default var OS = "windows"; + // Check if the browser method 'navigator.userAgentData' is supported + if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') { + console.log('navigator.userAgentData.getHighEntropyValues is supported'); + } else { + console.log('navigator.userAgentData.getHighEntropyValues is not supported'); + } + function getOSWinVersion() { if (navigator.appVersion.indexOf("Win") != -1) { if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && -- 2.30.2 From 176cfa7d89d576a6f226a30ccf5254d637291e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 14:46:30 +0100 Subject: [PATCH 03/15] UI: Create js function initAsync base --- themes/bthree/assets/js/get_os.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index a9d41bb..dcd12b5 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -99,6 +99,18 @@ function getOS() { getOSFreeBSDVersion(); } + function initAsync() { + navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) + .then(function(ua) { + // TODO: create function getOSWinVersionAsync + // getOSWinVersionAsync(); + getOSMacVersion(); + getOSLinuxVersion(); + getOSiPadVersion(); + getOSFreeBSDVersion(); + }) + } + init(); return OS; -- 2.30.2 From 8f8b84f6eb3770818306dc93aae3c84c9289a711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 14:50:16 +0100 Subject: [PATCH 04/15] UI: Create js function getOS conditional functions init for async --- themes/bthree/assets/js/get_os.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index dcd12b5..6bc8ba7 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -5,13 +5,6 @@ function getOS() { // Init variable OS default var OS = "windows"; - // Check if the browser method 'navigator.userAgentData' is supported - if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') { - console.log('navigator.userAgentData.getHighEntropyValues is supported'); - } else { - console.log('navigator.userAgentData.getHighEntropyValues is not supported'); - } - function getOSWinVersion() { if (navigator.appVersion.indexOf("Win") != -1) { if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && @@ -91,12 +84,24 @@ function getOS() { if (navigator.platform.indexOf("FreeBSD") != -1) OS = "freebsd"; } + // Create functions init function init() { + // Check if the browser method 'navigator.userAgentData' is supported + if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') { + initAsync(); + } else { + initSync(); + } + } + + function initSync() { getOSWinVersion(); getOSMacVersion(); getOSLinuxVersion(); getOSiPadVersion(); getOSFreeBSDVersion(); + + console.log('initSync'); } function initAsync() { @@ -108,6 +113,8 @@ function getOS() { getOSLinuxVersion(); getOSiPadVersion(); getOSFreeBSDVersion(); + + console.log('initAsync'); }) } -- 2.30.2 From f49fca366e5c3f508c81effe88a9fffdf7347024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 15:00:44 +0100 Subject: [PATCH 05/15] UI: Create function getOSWinVersionAsync base --- themes/bthree/assets/js/get_os.js | 38 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index 6bc8ba7..047aaca 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -5,7 +5,33 @@ function getOS() { // Init variable OS default var OS = "windows"; - function getOSWinVersion() { + function getOSWinVersionAsync() { + /* 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 + */ + navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) + .then(ua => { + if (navigator.userAgentData.platform === "Windows") { + if (ua.architecture === 'x86') { + if (ua.bitness === '64') { + console.log("x86_64"); + } + else if (ua.bitness === '32') { + console.log("x86"); + } + } + if (ua.architecture === 'arm') { + OS = "windows-arm"; + } else { + if (ua.bitness === '64') { + OS = "windows-64"; + } + } + } + }); + } + + function getOSWinVersionSync() { if (navigator.appVersion.indexOf("Win") != -1) { if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && navigator.userAgent.indexOf('Windows NT 5.1') == -1 && @@ -95,26 +121,22 @@ function getOS() { } function initSync() { - getOSWinVersion(); + getOSWinVersionSync(); getOSMacVersion(); getOSLinuxVersion(); getOSiPadVersion(); getOSFreeBSDVersion(); - - console.log('initSync'); } function initAsync() { navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) .then(function(ua) { - // TODO: create function getOSWinVersionAsync - // getOSWinVersionAsync(); + // TODO: make function getOSWinVersionAsync run sequentially + getOSWinVersionAsync(); getOSMacVersion(); getOSLinuxVersion(); getOSiPadVersion(); getOSFreeBSDVersion(); - - console.log('initAsync'); }) } -- 2.30.2 From b55a6cf7bd426d370648f99c9077e7a05b1b085d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 15:17:44 +0100 Subject: [PATCH 06/15] Refactor: Convert js getOS function getOSWinVersionAsync to initAsync --- themes/bthree/assets/js/get_os.js | 75 +++++++++++++++---------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index 047aaca..a0f2f78 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -5,33 +5,7 @@ function getOS() { // Init variable OS default var OS = "windows"; - function getOSWinVersionAsync() { - /* 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 - */ - navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) - .then(ua => { - if (navigator.userAgentData.platform === "Windows") { - if (ua.architecture === 'x86') { - if (ua.bitness === '64') { - console.log("x86_64"); - } - else if (ua.bitness === '32') { - console.log("x86"); - } - } - if (ua.architecture === 'arm') { - OS = "windows-arm"; - } else { - if (ua.bitness === '64') { - OS = "windows-64"; - } - } - } - }); - } - - function getOSWinVersionSync() { + function getOSWinVersionSync() { if (navigator.appVersion.indexOf("Win") != -1) { if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && navigator.userAgent.indexOf('Windows NT 5.1') == -1 && @@ -120,6 +94,41 @@ function getOS() { } } + // Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers) + function initAsync() { + /* 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 + */ + navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) + .then(ua => { + // Check if the platform is Windows + if (navigator.userAgentData.platform === "Windows") { + if (ua.architecture === 'x86') { + if (ua.bitness === '64') { + console.log("x86_64"); + } + else if (ua.bitness === '32') { + console.log("x86"); + } + } + if (ua.architecture === 'arm') { + OS = "windows-arm"; + } else { + if (ua.bitness === '64') { + OS = "windows-64"; + } + } + } else { + // Check other platforms + getOSMacVersion(); + getOSLinuxVersion(); + getOSiPadVersion(); + getOSFreeBSDVersion(); + } + }); + } + + // Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers) function initSync() { getOSWinVersionSync(); getOSMacVersion(); @@ -128,18 +137,6 @@ function getOS() { getOSFreeBSDVersion(); } - function initAsync() { - navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) - .then(function(ua) { - // TODO: make function getOSWinVersionAsync run sequentially - getOSWinVersionAsync(); - getOSMacVersion(); - getOSLinuxVersion(); - getOSiPadVersion(); - getOSFreeBSDVersion(); - }) - } - init(); return OS; -- 2.30.2 From f71d879688e2eb20af34a040b772447768684d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 15:24:59 +0100 Subject: [PATCH 07/15] Cleanup: Remove js function getOS unused conditionals --- themes/bthree/assets/js/get_os.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index a0f2f78..a43c99a 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -103,14 +103,6 @@ function getOS() { .then(ua => { // Check if the platform is Windows if (navigator.userAgentData.platform === "Windows") { - if (ua.architecture === 'x86') { - if (ua.bitness === '64') { - console.log("x86_64"); - } - else if (ua.bitness === '32') { - console.log("x86"); - } - } if (ua.architecture === 'arm') { OS = "windows-arm"; } else { -- 2.30.2 From 0c97fd86c79071dd9dd2b47f2a651406d5595f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 15:26:33 +0100 Subject: [PATCH 08/15] Fix: Move variable OS initialization default to init functions --- themes/bthree/assets/js/get_os.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index a43c99a..3d16dad 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -2,9 +2,6 @@ * https://code.videolan.org/VideoLAN.org/websites/-/blob/master/www.videolan.org/include/os-specific.php */ function getOS() { - // Init variable OS default - var OS = "windows"; - function getOSWinVersionSync() { if (navigator.appVersion.indexOf("Win") != -1) { if (navigator.userAgent.indexOf('Windows NT 5.0') == -1 && @@ -101,6 +98,9 @@ function getOS() { */ navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) .then(ua => { + // Init variable OS default + var OS = "windows"; + // Check if the platform is Windows if (navigator.userAgentData.platform === "Windows") { if (ua.architecture === 'arm') { @@ -122,6 +122,9 @@ function getOS() { // Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers) function initSync() { + // Init variable OS default + var OS = "windows"; + getOSWinVersionSync(); getOSMacVersion(); getOSLinuxVersion(); -- 2.30.2 From 85c93e8d83ff72369fc4a69264b1fbe0ecd56758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 15:30:09 +0100 Subject: [PATCH 09/15] Fix: Move js getOS return functions to unique initialization functions --- themes/bthree/assets/js/get_os.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index 3d16dad..82a80b8 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -117,6 +117,8 @@ function getOS() { getOSiPadVersion(); getOSFreeBSDVersion(); } + + return OS; }); } @@ -130,9 +132,9 @@ function getOS() { getOSLinuxVersion(); getOSiPadVersion(); getOSFreeBSDVersion(); + + return OS; } init(); - - return OS; } -- 2.30.2 From 3d284bbd0062b0e313b1db263a8e83cbc0508ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 16:33:06 +0100 Subject: [PATCH 10/15] Refactor: Simplify js by cleanup of unneded named function and resolve sync return issues --- themes/bthree/assets/js/get_os.js | 195 ++++++++++++++---------------- 1 file changed, 93 insertions(+), 102 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index 82a80b8..9016c59 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -2,7 +2,97 @@ * https://code.videolan.org/VideoLAN.org/websites/-/blob/master/www.videolan.org/include/os-specific.php */ function getOS() { - function getOSWinVersionSync() { + // Init variable OS default + var 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 + function init() { + // Check if the browser method 'navigator.userAgentData' is supported + if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') { + return 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() { + /* 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 + */ + navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) + .then(ua => { + // Init variable OS default + var OS = "windows"; + + // 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; + }); + } + + // 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.userAgent.indexOf('Windows NT 5.0') == -1 && navigator.userAgent.indexOf('Windows NT 5.1') == -1 && @@ -30,111 +120,12 @@ function getOS() { } catch (e) {} } } - } - } - - function getOSMacVersion() { - //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) {} - } - } - } - - function getOSLinuxVersion() { - 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"; - } - } - - function getOSiPadVersion() { - if (navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1) { - OS = "ios"; - } - } - - function getOSFreeBSDVersion() { - if (navigator.platform.indexOf("freebsd") != -1) OS = "freebsd"; - if (navigator.platform.indexOf("FreeBSD") != -1) OS = "freebsd"; - } - - // Create functions init - function init() { - // Check if the browser method 'navigator.userAgentData' is supported - if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') { - initAsync(); } else { - initSync(); + OS = getOSPlaformVersion(); } - } - - // Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers) - function initAsync() { - /* 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 - */ - navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) - .then(ua => { - // Init variable OS default - var OS = "windows"; - - // 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 - getOSMacVersion(); - getOSLinuxVersion(); - getOSiPadVersion(); - getOSFreeBSDVersion(); - } - - return OS; - }); - } - - // Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers) - function initSync() { - // Init variable OS default - var OS = "windows"; - - getOSWinVersionSync(); - getOSMacVersion(); - getOSLinuxVersion(); - getOSiPadVersion(); - getOSFreeBSDVersion(); return OS; } - init(); + return init(); } -- 2.30.2 From 29255611341ad51504cb3ab909c096cc4a6bf958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Wed, 6 Nov 2024 17:32:36 +0100 Subject: [PATCH 11/15] WIP: Fix js getOS function async initAsync not returning a value --- themes/bthree/assets/js/get_os.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index 9016c59..b541c78 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -56,7 +56,16 @@ function getOS() { function init() { // Check if the browser method 'navigator.userAgentData' is supported if (navigator.userAgentData && typeof navigator.userAgentData.getHighEntropyValues == 'function') { - return initAsync(); + return (async function() { + try { + var value = await initAsync(); + + console.log(value); + + // TODO: fix return returning undefined + return value; + } catch (error) {} + })(); } else { return initSync(); } @@ -65,14 +74,17 @@ function getOS() { // TODO: fix function async initAsync // Create function initAsync for browsers that support navigator.userAgentData (e.g. Chromium-based browsers) function initAsync() { - /* 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 - */ - navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]) - .then(ua => { + return (async function() { + 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 + */ + // 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') { @@ -88,7 +100,8 @@ function getOS() { } return OS; - }); + } catch (e) {} + })(); } // Create function initSync for browsers that don't support navigator.userAgentData (e.g. Gecko-based browsers) -- 2.30.2 From ecd108a6b981f6175d38a2978f98e172ed9b4166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Thu, 7 Nov 2024 11:01:55 +0100 Subject: [PATCH 12/15] WIP: Fix js getOS function async promise chains and calling methods --- themes/bthree/assets/js/get_os.js | 66 +++++++++------------- themes/bthree/page-download.php | 91 +++++++++++++++++-------------- 2 files changed, 77 insertions(+), 80 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index b541c78..e988158 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -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(); } diff --git a/themes/bthree/page-download.php b/themes/bthree/page-download.php index d5d3ead..1bac89e 100644 --- a/themes/bthree/page-download.php +++ b/themes/bthree/page-download.php @@ -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 () { -- 2.30.2 From dfda0ac999c4e4a1eb9066b31b08735737a28da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Thu, 7 Nov 2024 11:47:46 +0100 Subject: [PATCH 13/15] Refactor: Change variable declarations var to let in async functions --- themes/bthree/assets/js/get_os.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/bthree/assets/js/get_os.js b/themes/bthree/assets/js/get_os.js index e988158..7598e24 100644 --- a/themes/bthree/assets/js/get_os.js +++ b/themes/bthree/assets/js/get_os.js @@ -6,7 +6,7 @@ */ async function getOS() { // Init variable OS default - var OS = "windows"; + let OS = "windows"; function getOSPlaformVersion() { //MacOS, MacOS X, macOS @@ -72,7 +72,7 @@ async function getOS() { * 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"]); + let ua = await navigator.userAgentData.getHighEntropyValues(["architecture", "bitness"]); // Check if the platform is Windows if (navigator.userAgentData.platform === "Windows") { -- 2.30.2 From bae001710027b3c3845b582ac654462267680a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Fri, 8 Nov 2024 11:19:09 +0100 Subject: [PATCH 14/15] UI: Add template page-download js conditional windows-arm download btn display Part of #104136 --- themes/bthree/page-download.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/themes/bthree/page-download.php b/themes/bthree/page-download.php index 1bac89e..08704e2 100644 --- a/themes/bthree/page-download.php +++ b/themes/bthree/page-download.php @@ -337,9 +337,13 @@ $analytics_event_name = 'Downloads+Blender'; if (os == 'windows') { showPlatformWarning('This Windows version might not be supported.'); } + + /* 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. */ else if (os.startsWith('linux') || os.startsWith('freebsd')) { -- 2.30.2 From e6f033f00e310df74b72093f8372e58f5d6c6eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Lente?= Date: Fri, 8 Nov 2024 11:20:47 +0100 Subject: [PATCH 15/15] Cleanup: Remove template page-download js console logging Part of #104136 --- themes/bthree/page-download.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/themes/bthree/page-download.php b/themes/bthree/page-download.php index 08704e2..7f77840 100644 --- a/themes/bthree/page-download.php +++ b/themes/bthree/page-download.php @@ -330,9 +330,6 @@ $analytics_event_name = 'Downloads+Blender'; (async function() { os = await getOS(); - // TODO: remove console.log - console.log('OS: ' + os); - /* Windows. */ if (os == 'windows') { showPlatformWarning('This Windows version might not be supported.'); -- 2.30.2