// Logs Page Logic async function loadLogs() { const terminal = document.getElementById('logsTerminal'); if (!terminal) return; terminal.innerHTML = '
Loading logs...
'; try { const logs = await window.electronAPI.getRecentLogs(500); // Fetch last 500 lines if (logs) { // Escape HTML to prevent XSS and preserve format const safeLogs = logs.replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); terminal.innerHTML = `
${safeLogs}
`; // Auto scroll to bottom terminal.scrollTop = terminal.scrollHeight; } else { terminal.innerHTML = '
No logs found.
'; } } catch (error) { console.error('Failed to load logs:', error); terminal.innerHTML = `
Error loading logs: ${error.message}
`; } } async function refreshLogs() { const btn = document.querySelector('button[onclick="refreshLogs()"] i'); if (btn) btn.classList.add('fa-spin'); await loadLogs(); if (btn) setTimeout(() => btn.classList.remove('fa-spin'), 500); } async function copyLogs() { const terminal = document.getElementById('logsTerminal'); if (!terminal) return; const content = terminal.innerText; if (!content) return; try { await navigator.clipboard.writeText(content); const btn = document.querySelector('button[onclick="copyLogs()"]'); const originalText = btn.innerHTML; btn.innerHTML = ' Copied!'; setTimeout(() => { btn.innerHTML = originalText; }, 2000); } catch (err) { console.error('Failed to copy logs:', err); } } async function openLogsFolder() { await window.electronAPI.openLogsFolder(); } function openLogs() { // Navigation is handled by sidebar logic, but we can trigger a refresh window.LauncherUI.showPage('logs-page'); window.LauncherUI.setActiveNav('logs'); refreshLogs(); } // Expose functions globally window.refreshLogs = refreshLogs; window.copyLogs = copyLogs; window.openLogsFolder = openLogsFolder; window.openLogs = openLogs; // Auto-load logs when the page becomes active const logsObserver = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.target.classList.contains('active') && mutation.target.id === 'logs-page') { loadLogs(); } }); }); document.addEventListener('DOMContentLoaded', () => { const logsPage = document.getElementById('logs-page'); if (logsPage) { logsObserver.observe(logsPage, { attributes: true, attributeFilter: ['class'] }); } });