CI / Build & Test (push) Successful in 2m52s
- Snapshot and restore latency badge values across innerHTML re-renders so badges never flash back to "…ms" on the 2-second state refresh cycle - Add CSS transition (color 0.4s ease) and in-flight opacity dim (.pinging) to .latency-badge for smooth color changes - Decouple latency pinging from the state refresh cycle — pings now run on their own independent interval instead of being triggered by refresh() - Add two new settings under a "Latency Ping" section in Settings: - Enable Latency Ping toggle (latencyPingEnabled, default: true) - Ping Interval in seconds (latencyPingIntervalMs, default: 5s) - Restart ping interval immediately on settings save so changes take effect without a page reload
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
/**
|
|
* Dashboard entry point. Guards against loading outside the dashboard context,
|
|
* initialises navigation and all page event handlers, then starts the 2-second
|
|
* refresh cycle.
|
|
* Depends on: all other dashboard modules (loaded before this file)
|
|
*/
|
|
|
|
/**
|
|
* Guard: only run when loaded as the actual dashboard page.
|
|
*/
|
|
if (!document.getElementById('page-dashboard') && !document.querySelector('.sidebar-logo')) {
|
|
throw new Error('dashboard scripts loaded outside dashboard context — aborting');
|
|
}
|
|
|
|
/**
|
|
* Initialise the dashboard: set the version string, wire up navigation and all
|
|
* page event handlers, run the first state refresh, and start the 2-second polling interval.
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async function init() {
|
|
log('Dashboard initializing…');
|
|
|
|
try {
|
|
const manifest = chrome.runtime.getManifest();
|
|
const versionEl = $('sidebarVersion');
|
|
if (versionEl && manifest.version) {
|
|
versionEl.textContent = 'v' + manifest.version + ' · hole.sail';
|
|
}
|
|
} catch (_) {}
|
|
|
|
setupNavigation();
|
|
setupEvents();
|
|
setupCertValidator();
|
|
setupSshEvents();
|
|
setupRdpEvents();
|
|
setupBackupEvents();
|
|
await refresh();
|
|
|
|
// Main state-refresh interval (fixed 2 s)
|
|
const _refreshInterval = setInterval(refresh, 2000);
|
|
|
|
// Latency-ping interval — driven by settings.latencyPingIntervalMs.
|
|
// Re-created whenever settings change so the interval stays in sync.
|
|
let _pingInterval = null;
|
|
function _restartPingInterval() {
|
|
if (_pingInterval) clearInterval(_pingInterval);
|
|
_pingInterval = null;
|
|
if (settings.latencyPingEnabled === false) return;
|
|
const ms = (settings.latencyPingIntervalMs > 0 ? settings.latencyPingIntervalMs : 5000);
|
|
_pingInterval = setInterval(_pingLatencyBadges, ms);
|
|
}
|
|
_restartPingInterval();
|
|
|
|
// Expose restart so settings.js can call it after saving
|
|
window._restartPingInterval = _restartPingInterval;
|
|
|
|
window.addEventListener('beforeunload', () => {
|
|
clearInterval(_refreshInterval);
|
|
if (_pingInterval) clearInterval(_pingInterval);
|
|
}, { once: true });
|
|
}
|
|
|
|
init();
|