class ClientUpdateManager { constructor() { this.updatePopupVisible = false; this.init(); } init() { window.electronAPI.onUpdatePopup((updateInfo) => { this.showUpdatePopup(updateInfo); }); this.checkForUpdatesOnDemand(); } showUpdatePopup(updateInfo) { if (this.updatePopupVisible) return; this.updatePopupVisible = true; const popupHTML = `

NEW UPDATE AVAILABLE

Current Version: ${updateInfo.currentVersion}
New Version: ${updateInfo.newVersion}
A new version of Hytale F2P Launcher is available.
Please download the latest version to continue using the launcher.
`; document.body.insertAdjacentHTML('beforeend', popupHTML); this.blockInterface(); const downloadBtn = document.getElementById('update-download-btn'); if (downloadBtn) { downloadBtn.addEventListener('click', async (e) => { e.preventDefault(); e.stopPropagation(); downloadBtn.disabled = true; downloadBtn.innerHTML = 'Opening GitHub...'; try { await window.electronAPI.openDownloadPage(); console.log('✅ Download page opened, launcher will close...'); downloadBtn.innerHTML = 'Launcher closing...'; } catch (error) { console.error('❌ Error opening download page:', error); downloadBtn.disabled = false; downloadBtn.innerHTML = 'Download Update'; } }); } const overlay = document.getElementById('update-popup-overlay'); if (overlay) { overlay.addEventListener('click', (e) => { if (e.target === overlay) { e.preventDefault(); e.stopPropagation(); return false; } }); } console.log('🔔 Update popup displayed with new style'); } blockInterface() { const mainContent = document.querySelector('.flex.w-full.h-screen'); if (mainContent) { mainContent.classList.add('interface-blocked'); } document.body.classList.add('no-select'); document.addEventListener('keydown', this.blockKeyEvents.bind(this), true); document.addEventListener('contextmenu', this.blockContextMenu.bind(this), true); console.log('🚫 Interface blocked for update'); } blockKeyEvents(event) { if (event.target.closest('#update-popup-overlay')) { if ((event.key === 'Enter' || event.key === ' ') && event.target.id === 'update-download-btn') { return; } if (event.key !== 'Tab') { event.preventDefault(); event.stopPropagation(); } return; } event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); return false; } blockContextMenu(event) { if (!event.target.closest('#update-popup-overlay')) { event.preventDefault(); event.stopPropagation(); return false; } } async checkForUpdatesOnDemand() { try { const updateInfo = await window.electronAPI.checkForUpdates(); if (updateInfo.updateAvailable) { this.showUpdatePopup(updateInfo); } return updateInfo; } catch (error) { console.error('Error checking for updates:', error); return { updateAvailable: false, error: error.message }; } } } document.addEventListener('DOMContentLoaded', () => { window.updateManager = new ClientUpdateManager(); }); window.ClientUpdateManager = ClientUpdateManager;