diff --git a/UI/assets/js/main.js b/UI/assets/js/main.js index 9cb0991..24b726f 100644 --- a/UI/assets/js/main.js +++ b/UI/assets/js/main.js @@ -36,6 +36,8 @@ var href = $(this).attr('href'); // Not a panel link? Bail. + if (typeof href === 'undefined') + return; if (href.charAt(0) != '#' || $panels.filter(href).length == 0) return; diff --git a/UI/index.html b/UI/index.html index 1ec11dc..e8e48cb 100644 --- a/UI/index.html +++ b/UI/index.html @@ -20,9 +20,9 @@ diff --git a/UI/renderer.js b/UI/renderer.js index cd0ecc4..8ee6623 100644 --- a/UI/renderer.js +++ b/UI/renderer.js @@ -313,7 +313,6 @@ function refreshPattern(data) modalLoading.remove(); //Move to the Live tab window.location.hash = '#live'; - enableRPM(); initComplete = true; } @@ -463,6 +462,7 @@ function animateGauges() { var RPMInterval = 0; function enableRPM() { + console.log("Enabling RPM reads"); if(RPMInterval == 0) { RPMInterval = setInterval(updateRPM, 100); @@ -529,6 +529,19 @@ async function checkForUpdates() } +function liveShowHide(mutationsList, observer) { + mutationsList.forEach(mutation => { + if (mutation.attributeName === 'style') { + if (mutation.target.style.display === 'none') { + disableRPM(); + } + else { + enableRPM(); + } + } + }) +} + window.onload = function () { refreshSerialPorts(); @@ -537,6 +550,13 @@ window.onload = function () checkForUpdates(); //animateGauges(); + //Enable and disabled retrieval of RPM when viewing live panel + const liveShowHideObserver = new MutationObserver(liveShowHide); + liveShowHideObserver.observe( + document.getElementById('live'), + { attributes: true } + ); + usb.on('attach', refreshSerialPorts); usb.on('detach', refreshSerialPorts); };