Elite Academy
Sizin için hazırlanıyor...
// Handle "Add to Home Screen" prompt let deferredPrompt; window.addEventListener('beforeinstallprompt', (e) => { console.log('beforeinstallprompt fired'); e.preventDefault(); deferredPrompt = e; // Store for later use by Flutter app window.deferredInstallPrompt = e; }); // Track successful installs window.addEventListener('appinstalled', (evt) => { console.log('App was installed successfully'); deferredPrompt = null; }); // Notification Permission Helper window.requestNotificationPermission = async function () { if (!('Notification' in window)) { console.log('This browser does not support notifications'); return 'unsupported'; } if (Notification.permission === 'granted') { return 'granted'; } if (Notification.permission === 'denied') { return 'denied'; } const permission = await Notification.requestPermission(); return permission; }; // Show Install Prompt Helper window.showInstallPrompt = async function () { if (!deferredPrompt) { console.log('Install prompt not available'); return false; } deferredPrompt.prompt(); const { outcome } = await deferredPrompt.userChoice; console.log('Install prompt outcome:', outcome); deferredPrompt = null; return outcome === 'accepted'; }; // Check if app is installed window.isAppInstalled = function () { return window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone === true; }; // Cache article for offline reading window.cacheArticleForOffline = async function (articleUrl, articleData) { if ('serviceWorker' in navigator && navigator.serviceWorker.controller) { navigator.serviceWorker.controller.postMessage({ type: 'CACHE_ARTICLE', articleUrl: articleUrl, articleData: articleData }); return true; } return false; };