|
@@ -1582,8 +1582,12 @@ function attachFullScreenListeners() {
|
|
|
|
|
|
|
|
let lastPreviewedFile = null; // Track the last previewed file
|
|
let lastPreviewedFile = null; // Track the last previewed file
|
|
|
|
|
|
|
|
|
|
+let updateInterval = null;
|
|
|
|
|
+
|
|
|
async function updateCurrentlyPlaying() {
|
|
async function updateCurrentlyPlaying() {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ if (!document.hasFocus()) return; // Stop execution if the page is not visible
|
|
|
|
|
+
|
|
|
const response = await fetch('/status');
|
|
const response = await fetch('/status');
|
|
|
const data = await response.json();
|
|
const data = await response.json();
|
|
|
|
|
|
|
@@ -1609,7 +1613,7 @@ async function updateCurrentlyPlaying() {
|
|
|
// Update pattern preview only if the file is different
|
|
// Update pattern preview only if the file is different
|
|
|
if (current_playing_file !== lastPreviewedFile) {
|
|
if (current_playing_file !== lastPreviewedFile) {
|
|
|
previewPattern(fileName, 'currently-playing-container');
|
|
previewPattern(fileName, 'currently-playing-container');
|
|
|
- lastPreviewedFile = current_playing_file; // Update the last previewed file
|
|
|
|
|
|
|
+ lastPreviewedFile = current_playing_file;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Update the filename display
|
|
// Update the filename display
|
|
@@ -1620,8 +1624,7 @@ async function updateCurrentlyPlaying() {
|
|
|
const progressBar = document.getElementById('play_progress');
|
|
const progressBar = document.getElementById('play_progress');
|
|
|
const progressText = document.getElementById('play_progress_text');
|
|
const progressText = document.getElementById('play_progress_text');
|
|
|
if (execution_progress) {
|
|
if (execution_progress) {
|
|
|
- const progressPercentage =
|
|
|
|
|
- (execution_progress[0] / execution_progress[1]) * 100;
|
|
|
|
|
|
|
+ const progressPercentage = (execution_progress[0] / execution_progress[1]) * 100;
|
|
|
progressBar.value = progressPercentage;
|
|
progressBar.value = progressPercentage;
|
|
|
progressText.textContent = `${Math.round(progressPercentage)}%`;
|
|
progressText.textContent = `${Math.round(progressPercentage)}%`;
|
|
|
} else {
|
|
} else {
|
|
@@ -1640,6 +1643,21 @@ async function updateCurrentlyPlaying() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Function to start or stop updates based on visibility
|
|
|
|
|
+function handleVisibilityChange() {
|
|
|
|
|
+ if (document.hasFocus()) {
|
|
|
|
|
+ // User is active, start updating
|
|
|
|
|
+ if (!updateInterval) {
|
|
|
|
|
+ updateCurrentlyPlaying(); // Run immediately
|
|
|
|
|
+ updateInterval = setInterval(updateCurrentlyPlaying, 5000); // Update every 5s
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // User is inactive, stop updating
|
|
|
|
|
+ clearInterval(updateInterval);
|
|
|
|
|
+ updateInterval = null;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function toggleSettings() {
|
|
function toggleSettings() {
|
|
|
const settingsContainer = document.getElementById('settings-container');
|
|
const settingsContainer = document.getElementById('settings-container');
|
|
|
if (settingsContainer) {
|
|
if (settingsContainer) {
|
|
@@ -1793,6 +1811,8 @@ function switchTab(tabName) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
|
|
|
+
|
|
|
// Initialization
|
|
// Initialization
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
const activeTab = getCookie('activeTab') || 'patterns'; // Default to 'patterns' tab
|
|
const activeTab = getCookie('activeTab') || 'patterns'; // Default to 'patterns' tab
|
|
@@ -1806,5 +1826,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
checkForUpdates();
|
|
checkForUpdates();
|
|
|
|
|
|
|
|
// Periodically check for currently playing status
|
|
// Periodically check for currently playing status
|
|
|
- setInterval(updateCurrentlyPlaying, 3000);
|
|
|
|
|
|
|
+ if (document.hasFocus()) {
|
|
|
|
|
+ updateInterval = setInterval(updateCurrentlyPlaying, 5000);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|