// PWA Install Prompt Manager for SecureBit.chat // Enhanced Security Edition v4.01.212 class PWAInstallPrompt { constructor() { this.deferredPrompt = null; this.isInstalled = false; this.installButton = null; this.installBanner = null; this.dismissedCount = 0; this.maxDismissals = 3; this.init(); } init() { console.log('💿 PWA Install Prompt initializing...'); this.checkInstallationStatus(); this.setupEventListeners(); this.createInstallButton(); this.loadInstallPreferences(); console.log('✅ PWA Install Prompt initialized'); } checkInstallationStatus() { // Check if app is already installed if (window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone === true) { this.isInstalled = true; console.log('📱 App is already installed as PWA'); document.body.classList.add('pwa-installed'); return true; } // Check for iOS Safari specific installation if (this.isIOSSafari()) { this.isInstalled = window.navigator.standalone === true; } document.body.classList.add(this.isInstalled ? 'pwa-installed' : 'pwa-browser'); return this.isInstalled; } setupEventListeners() { // Capture the install prompt event window.addEventListener('beforeinstallprompt', (event) => { console.log('💿 Install prompt event captured'); event.preventDefault(); this.deferredPrompt = event; if (!this.isInstalled && this.shouldShowPrompt()) { this.showInstallOptions(); } }); // Handle successful installation window.addEventListener('appinstalled', () => { console.log('✅ PWA installed successfully'); this.isInstalled = true; this.hideInstallPrompts(); this.showInstallSuccess(); this.saveInstallPreference('installed', true); // Update UI for installed state document.body.classList.remove('pwa-browser'); document.body.classList.add('pwa-installed'); }); // Handle iOS installation detection if (this.isIOSSafari()) { window.addEventListener('visibilitychange', () => { if (document.hidden) return; setTimeout(() => { if (window.navigator.standalone && !this.isInstalled) { this.isInstalled = true; this.hideInstallPrompts(); this.showInstallSuccess(); } }, 1000); }); } } createInstallButton() { // Create floating install button this.installButton = document.createElement('button'); this.installButton.id = 'pwa-install-button'; this.installButton.className = 'hidden fixed bottom-6 right-6 bg-gradient-to-r from-orange-500 to-orange-600 hover:from-orange-600 hover:to-orange-700 text-white px-6 py-3 rounded-full shadow-lg transition-all duration-300 z-50 flex items-center space-x-3 group'; this.installButton.innerHTML = ` Install App
`; this.installButton.addEventListener('click', () => { this.handleInstallClick(); }); document.body.appendChild(this.installButton); } createInstallBanner() { if (this.installBanner) return; this.installBanner = document.createElement('div'); this.installBanner.id = 'pwa-install-banner'; this.installBanner.className = 'pwa-install-banner fixed bottom-0 left-0 right-0 transform translate-y-full transition-transform duration-300 z-40'; this.installBanner.innerHTML = `To install this app, look for the install option in your browser menu or address bar. Different browsers have different install methods.