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(); if (this.isIOSSafari() && !this.isInstalled && this.shouldShowPrompt()) { setTimeout(() => { this.showIOSInstallInstructions(); }, 3000); } console.log('✅ PWA Install Prompt initialized'); } checkInstallationStatus() { 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; } if (this.isIOSSafari()) { this.isInstalled = window.navigator.standalone === true; if (this.isInstalled) { console.log('📱 iOS PWA detected'); document.body.classList.add('pwa-installed', 'ios-pwa'); } } document.body.classList.add(this.isInstalled ? 'pwa-installed' : 'pwa-browser'); if (this.isIOSSafari()) { document.body.classList.add('ios-safari'); } return this.isInstalled; } setupEventListeners() { window.addEventListener('beforeinstallprompt', (event) => { console.log('💿 Install prompt event captured'); event.preventDefault(); this.deferredPrompt = event; if (!this.isInstalled && this.shouldShowPrompt()) { this.showInstallOptions(); } }); window.addEventListener('appinstalled', () => { console.log('✅ PWA installed successfully'); this.isInstalled = true; this.hideInstallPrompts(); this.showInstallSuccess(); this.saveInstallPreference('installed', true); document.body.classList.remove('pwa-browser'); document.body.classList.add('pwa-installed'); }); if (this.isIOSSafari()) { let wasStandalone = window.navigator.standalone; window.addEventListener('visibilitychange', () => { if (document.hidden) return; setTimeout(() => { const isStandalone = window.navigator.standalone; if (isStandalone && !wasStandalone && !this.isInstalled) { console.log('✅ iOS PWA installation detected'); this.isInstalled = true; this.hideInstallPrompts(); this.showInstallSuccess(); document.body.classList.remove('pwa-browser'); document.body.classList.add('pwa-installed', 'ios-pwa'); } wasStandalone = isStandalone; }, 1000); }); } } createInstallButton() { 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'; const buttonText = this.isIOSSafari() ? 'Install App' : 'Install App'; const buttonIcon = this.isIOSSafari() ? 'fas fa-share' : 'fas fa-download'; this.installButton.innerHTML = ` ${buttonText}
`; 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 = `After installation, open SecureBit from your home screen for the best experience.
To install this app, look for the install option in your browser menu or address bar. Different browsers have different install methods.