/* ============================================================ Driver Booster Pro - Application Logic Driver Navigator Style: tabs, driver rows, action buttons ============================================================ */ var App = { state: { sysInfo:null, drivers:null, updates:null }, init: function() { this.setupTabs(); this.setupFilters(); this.refreshSysInfo(); this.refreshIcons(); }, refreshIcons: function() { if (window.lucide) lucide.createIcons(); }, // ---- Tab Navigation ---- setupTabs: function() { var self = this; document.querySelectorAll('.toolbar-tab').forEach(function(tab) { tab.addEventListener('click', function() { var id = tab.dataset.tab; document.querySelectorAll('.toolbar-tab').forEach(function(t){ t.classList.remove('active'); }); tab.classList.add('active'); document.querySelectorAll('.tab-page').forEach(function(p){ p.classList.remove('active'); }); var target = document.getElementById('tab-' + id); if (target) target.classList.add('active'); }); }); }, // ---- Filter Pills ---- setupFilters: function() { var self = this; document.querySelectorAll('.pill').forEach(function(btn) { btn.addEventListener('click', function() { document.querySelectorAll('.pill').forEach(function(b){ b.classList.remove('active'); }); btn.classList.add('active'); self.filterDrivers(btn.dataset.filter); }); }); }, filterDrivers: function(f) { document.querySelectorAll('.drv-row').forEach(function(row) { var show = f === 'all' || (f === 'outdated' && row.classList.contains('outdated')) || (f === 'error' && row.classList.contains('error')) || (f === 'signed' && row.dataset.signed === 'true'); row.style.display = show ? '' : 'none'; }); }, // ---- Loading ---- showLoading: function(text) { document.getElementById('loading-text').textContent = text; document.getElementById('loading-overlay').style.display = 'flex'; this.refreshIcons(); }, hideLoading: function() { document.getElementById('loading-overlay').style.display = 'none'; }, // ---- System Info ---- refreshSysInfo: function() { var self = this; this.showLoading('Collecting system information...'); fetch('/api/sysinfo').then(function(r){ return r.json(); }).then(function(info) { self.state.sysInfo = info; self.renderSysInfo(info); self.hideLoading(); }).catch(function(e) { console.error(e); self.hideLoading(); }); }, renderSysInfo: function(d) { this.set('sys-name', d.computerName); this.set('sys-os', d.osName); this.set('sys-version', d.osVersion); this.set('sys-build', d.osBuild); this.set('sys-arch', d.architecture); this.set('sys-cpu', d.cpuName); this.set('sys-cores', d.cpuCores); this.set('sys-ram-total', d.totalRam); this.set('sys-ram-used', d.usedRam); this.set('sys-ram-free', d.freeRam); this.set('sys-ram-pct', (d.ramPercent||0)+'%'); this.set('sys-disk-total', d.diskTotal); this.set('sys-disk-used', d.diskUsed); this.set('sys-disk-free', d.diskFree); this.set('sys-disk-pct', (d.diskPercent||0)+'%'); var rb = document.getElementById('sys-ram-bar'); var db = document.getElementById('sys-disk-bar'); if(rb) rb.style.width = (d.ramPercent||0)+'%'; if(db) db.style.width = (d.diskPercent||0)+'%'; }, // ---- Driver Scan ---- scanDrivers: function() { var self = this; this.showLoading('Scanning drivers... This may take a moment.'); // Switch to drivers tab document.querySelectorAll('.toolbar-tab').forEach(function(t){ t.classList.remove('active'); }); document.querySelector('[data-tab="drivers"]').classList.add('active'); document.querySelectorAll('.tab-page').forEach(function(p){ p.classList.remove('active'); }); document.getElementById('tab-drivers').classList.add('active'); // Update steps this.setStep(2); fetch('/api/drivers/scan').then(function(r){ return r.json(); }).then(function(result) { self.state.drivers = result; self.renderDrivers(result); self.updateScanStats(result); self.hideLoading(); }).catch(function(e) { console.error(e); self.hideLoading(); }); }, updateScanStats: function(r) { this.set('scan-stat-total', r.totalCount); this.set('scan-stat-outdated', r.outdatedCount); this.set('scan-stat-errors', r.errorCount); }, renderDrivers: function(result) { document.getElementById('driver-result-count').style.display = 'block'; document.getElementById('driver-filter-strip').style.display = 'flex'; this.set('drv-total-2', result.totalCount); this.set('drv-outdated-2', result.outdatedCount); this.set('drv-time-2', result.scanTime); var list = document.getElementById('driver-list'); if (!result.drivers || result.drivers.length === 0) { list.innerHTML = '
No drivers found
' + this.esc(result.error) + '
Your system is fully up to date!