Defer hidden dashboard startup work

This commit is contained in:
James Smith
2026-03-19 09:19:36 +00:00
parent aaed831420
commit 5905aa6415
5 changed files with 146 additions and 98 deletions

View File

@@ -2,12 +2,13 @@
* Updater Module - GitHub update checking and notification system
*/
const Updater = {
// State
_checkInterval: null,
_toastElement: null,
_modalElement: null,
_updateData: null,
const Updater = {
// State
_checkInterval: null,
_startupCheckTimer: null,
_toastElement: null,
_modalElement: null,
_updateData: null,
// Configuration
CHECK_INTERVAL_MS: 6 * 60 * 60 * 1000, // 6 hours in milliseconds
@@ -15,18 +16,31 @@ const Updater = {
/**
* Initialize the updater module
*/
init() {
// Create toast container if it doesn't exist
this._ensureToastContainer();
// Check for updates on page load
this.checkForUpdates();
// Set up periodic checks
this._checkInterval = setInterval(() => {
this.checkForUpdates();
}, this.CHECK_INTERVAL_MS);
},
init() {
// Create toast container if it doesn't exist
this._ensureToastContainer();
const enabled = localStorage.getItem('intercept_update_check_enabled') !== 'false';
if (!enabled) {
this.destroy();
return;
}
// Defer the first check so the active dashboard can finish loading first.
if (!this._startupCheckTimer) {
this._startupCheckTimer = setTimeout(() => {
this._startupCheckTimer = null;
this.checkForUpdates();
}, 15000);
}
// Set up periodic checks
if (!this._checkInterval) {
this._checkInterval = setInterval(() => {
this.checkForUpdates();
}, this.CHECK_INTERVAL_MS);
}
},
/**
* Ensure toast container exists in DOM
@@ -505,11 +519,15 @@ const Updater = {
/**
* Clean up on page unload
*/
destroy() {
if (this._checkInterval) {
clearInterval(this._checkInterval);
this._checkInterval = null;
}
destroy() {
if (this._startupCheckTimer) {
clearTimeout(this._startupCheckTimer);
this._startupCheckTimer = null;
}
if (this._checkInterval) {
clearInterval(this._checkInterval);
this._checkInterval = null;
}
this.hideToast();
this.hideModal();
}