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:
15
index.html
15
index.html
@@ -4206,6 +4206,21 @@ window.PWAUtils = {
|
|||||||
window.pwaInstallPrompt.checkInstallationStatus();
|
window.pwaInstallPrompt.checkInstallationStatus();
|
||||||
console.log('🔄 PWA Installation status reset');
|
console.log('🔄 PWA Installation status reset');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Метод для отмены отложенного промпта
|
||||||
|
cancelDelayedPrompt: () => {
|
||||||
|
if (window.pwaInstallPrompt) {
|
||||||
|
return window.pwaInstallPrompt.cancelDelayedPrompt();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Метод для перезапуска отложенного промпта
|
||||||
|
rescheduleDelayedPrompt: () => {
|
||||||
|
if (window.pwaInstallPrompt) {
|
||||||
|
window.pwaInstallPrompt.rescheduleDelayedPrompt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class PWAInstallPrompt {
|
|||||||
this.dismissedCount = 0;
|
this.dismissedCount = 0;
|
||||||
this.maxDismissals = 3;
|
this.maxDismissals = 3;
|
||||||
this.installationChecked = false;
|
this.installationChecked = false;
|
||||||
|
this.delayedPromptTimeout = null;
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
@@ -24,6 +25,9 @@ class PWAInstallPrompt {
|
|||||||
this.startInstallationMonitoring();
|
this.startInstallationMonitoring();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Автоматический показ через 10 секунд для новых пользователей
|
||||||
|
this.scheduleDelayedPrompt();
|
||||||
|
|
||||||
console.log('✅ PWA Install Prompt initialized');
|
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() {
|
setupEventListeners() {
|
||||||
window.addEventListener('beforeinstallprompt', (event) => {
|
window.addEventListener('beforeinstallprompt', (event) => {
|
||||||
console.log('💿 Install prompt event captured');
|
console.log('💿 Install prompt event captured');
|
||||||
@@ -223,6 +244,13 @@ class PWAInstallPrompt {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Отменяем отложенный промпт, так как показываем промпт сейчас
|
||||||
|
if (this.delayedPromptTimeout) {
|
||||||
|
clearTimeout(this.delayedPromptTimeout);
|
||||||
|
this.delayedPromptTimeout = null;
|
||||||
|
console.log('⏰ Delayed install prompt cancelled - showing prompt now');
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isIOSSafari()) {
|
if (this.isIOSSafari()) {
|
||||||
this.showInstallButton();
|
this.showInstallButton();
|
||||||
} else if (this.isMobileDevice()) {
|
} else if (this.isMobileDevice()) {
|
||||||
@@ -285,6 +313,13 @@ class PWAInstallPrompt {
|
|||||||
hideInstallPrompts() {
|
hideInstallPrompts() {
|
||||||
console.log('💿 Hiding all install prompts');
|
console.log('💿 Hiding all install prompts');
|
||||||
|
|
||||||
|
// Отменяем отложенный промпт
|
||||||
|
if (this.delayedPromptTimeout) {
|
||||||
|
clearTimeout(this.delayedPromptTimeout);
|
||||||
|
this.delayedPromptTimeout = null;
|
||||||
|
console.log('⏰ Delayed install prompt cancelled');
|
||||||
|
}
|
||||||
|
|
||||||
if (this.installButton) {
|
if (this.installButton) {
|
||||||
this.installButton.classList.add('hidden');
|
this.installButton.classList.add('hidden');
|
||||||
console.log('💿 Install button hidden');
|
console.log('💿 Install button hidden');
|
||||||
@@ -650,6 +685,24 @@ class PWAInstallPrompt {
|
|||||||
console.log('💿 Install dismissals reset');
|
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
|
// Method for setting service worker registration
|
||||||
setServiceWorkerRegistration(registration) {
|
setServiceWorkerRegistration(registration) {
|
||||||
this.swRegistration = registration;
|
this.swRegistration = registration;
|
||||||
|
|||||||
Reference in New Issue
Block a user