Add 10-second auto PWA install prompt
- New users now see install prompt automatically after 10 seconds - Smart cancellation prevents duplicate prompts - Added PWAUtils methods for delayed prompt management - Enhanced user onboarding experience - Respects installation status and user preferences
This commit is contained in:
@@ -7,6 +7,7 @@ class PWAInstallPrompt {
|
||||
this.dismissedCount = 0;
|
||||
this.maxDismissals = 3;
|
||||
this.installationChecked = false;
|
||||
this.delayedPromptTimeout = null;
|
||||
|
||||
this.init();
|
||||
}
|
||||
@@ -24,6 +25,9 @@ class PWAInstallPrompt {
|
||||
this.startInstallationMonitoring();
|
||||
}
|
||||
|
||||
// Автоматический показ через 10 секунд для новых пользователей
|
||||
this.scheduleDelayedPrompt();
|
||||
|
||||
console.log('✅ PWA Install Prompt initialized');
|
||||
}
|
||||
|
||||
@@ -95,6 +99,23 @@ class PWAInstallPrompt {
|
||||
});
|
||||
}
|
||||
|
||||
scheduleDelayedPrompt() {
|
||||
// Автоматический показ промпта через 10 секунд для новых пользователей
|
||||
this.delayedPromptTimeout = setTimeout(() => {
|
||||
console.log('⏰ Checking if delayed install prompt should be shown...');
|
||||
|
||||
// Проверяем, нужно ли показывать промпт
|
||||
if (!this.isInstalled && this.shouldShowPrompt()) {
|
||||
console.log('💿 Showing delayed install prompt after 10 seconds');
|
||||
this.showInstallOptions();
|
||||
} else {
|
||||
console.log('💿 Delayed install prompt not shown - app is installed or dismissed');
|
||||
}
|
||||
}, 10000); // 10 секунд
|
||||
|
||||
console.log('⏰ Delayed install prompt scheduled for 10 seconds');
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
window.addEventListener('beforeinstallprompt', (event) => {
|
||||
console.log('💿 Install prompt event captured');
|
||||
@@ -223,6 +244,13 @@ class PWAInstallPrompt {
|
||||
return;
|
||||
}
|
||||
|
||||
// Отменяем отложенный промпт, так как показываем промпт сейчас
|
||||
if (this.delayedPromptTimeout) {
|
||||
clearTimeout(this.delayedPromptTimeout);
|
||||
this.delayedPromptTimeout = null;
|
||||
console.log('⏰ Delayed install prompt cancelled - showing prompt now');
|
||||
}
|
||||
|
||||
if (this.isIOSSafari()) {
|
||||
this.showInstallButton();
|
||||
} else if (this.isMobileDevice()) {
|
||||
@@ -285,6 +313,13 @@ class PWAInstallPrompt {
|
||||
hideInstallPrompts() {
|
||||
console.log('💿 Hiding all install prompts');
|
||||
|
||||
// Отменяем отложенный промпт
|
||||
if (this.delayedPromptTimeout) {
|
||||
clearTimeout(this.delayedPromptTimeout);
|
||||
this.delayedPromptTimeout = null;
|
||||
console.log('⏰ Delayed install prompt cancelled');
|
||||
}
|
||||
|
||||
if (this.installButton) {
|
||||
this.installButton.classList.add('hidden');
|
||||
console.log('💿 Install button hidden');
|
||||
@@ -649,6 +684,24 @@ class PWAInstallPrompt {
|
||||
this.saveInstallPreference('dismissed', 0);
|
||||
console.log('💿 Install dismissals reset');
|
||||
}
|
||||
|
||||
// Метод для отмены отложенного промпта
|
||||
cancelDelayedPrompt() {
|
||||
if (this.delayedPromptTimeout) {
|
||||
clearTimeout(this.delayedPromptTimeout);
|
||||
this.delayedPromptTimeout = null;
|
||||
console.log('⏰ Delayed install prompt manually cancelled');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Метод для перезапуска отложенного промпта
|
||||
rescheduleDelayedPrompt() {
|
||||
this.cancelDelayedPrompt();
|
||||
this.scheduleDelayedPrompt();
|
||||
console.log('⏰ Delayed install prompt rescheduled');
|
||||
}
|
||||
|
||||
// Method for setting service worker registration
|
||||
setServiceWorkerRegistration(registration) {
|
||||
|
||||
Reference in New Issue
Block a user