diff --git a/src/pwa/install-prompt.js b/src/pwa/install-prompt.js
index 92e5212..5f0b951 100644
--- a/src/pwa/install-prompt.js
+++ b/src/pwa/install-prompt.js
@@ -14,7 +14,15 @@ class PWAInstallPrompt {
init() {
console.log('💿 PWA Install Prompt initializing...');
+ // Сначала проверяем статус установки
this.checkInstallationStatus();
+
+ // Если уже установлено, не инициализируем остальное
+ if (this.isInstalled) {
+ console.log('💿 App already installed, skipping initialization');
+ return;
+ }
+
this.setupEventListeners();
this.createInstallButton();
this.loadInstallPreferences();
@@ -28,16 +36,26 @@ class PWAInstallPrompt {
}
checkInstallationStatus() {
+ console.log('🔍 Checking PWA installation status...');
+
// Проверяем различные способы определения установки PWA
const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
const isIOSStandalone = window.navigator.standalone === true;
const hasInstallPreference = this.loadInstallPreferences().installed;
+ console.log('🔍 PWA Installation Check:', {
+ isStandalone,
+ isIOSStandalone,
+ hasInstallPreference,
+ userAgent: navigator.userAgent.slice(0, 100)
+ });
+
// Проверяем, установлено ли приложение
if (isStandalone || isIOSStandalone || hasInstallPreference) {
this.isInstalled = true;
console.log('📱 App is already installed as PWA');
document.body.classList.add('pwa-installed');
+ document.body.classList.remove('pwa-browser');
// Скрываем все промпты установки
this.hideInstallPrompts();
@@ -52,7 +70,9 @@ class PWAInstallPrompt {
}
// Если не установлено, добавляем соответствующие классы
+ this.isInstalled = false;
document.body.classList.add('pwa-browser');
+ document.body.classList.remove('pwa-installed');
if (this.isIOSSafari()) {
document.body.classList.add('ios-safari');
@@ -74,7 +94,7 @@ class PWAInstallPrompt {
this.isInstalled = true;
this.hideInstallPrompts();
this.showInstallSuccess();
- document.body.classList.remove('pwa-browser');
+ document.body.classList.remove('pwa-browser', 'ios-safari');
document.body.classList.add('pwa-installed', 'ios-pwa');
// Сохраняем предпочтение установки
@@ -93,6 +113,11 @@ class PWAInstallPrompt {
setTimeout(checkStandalone, 1000);
}
});
+
+ // Проверяем при фокусе окна
+ window.addEventListener('focus', () => {
+ setTimeout(checkStandalone, 500);
+ });
}
setupEventListeners() {
@@ -101,9 +126,14 @@ class PWAInstallPrompt {
event.preventDefault();
this.deferredPrompt = event;
+ // Повторно проверяем статус установки
+ if (this.checkInstallationStatus()) {
+ return; // Если установлено, не показываем промпт
+ }
+
// Показываем промпт только если приложение не установлено
if (!this.isInstalled && this.shouldShowPrompt()) {
- this.showInstallOptions();
+ setTimeout(() => this.showInstallOptions(), 1000);
}
});
@@ -114,40 +144,49 @@ class PWAInstallPrompt {
this.showInstallSuccess();
this.saveInstallPreference('installed', true);
- document.body.classList.remove('pwa-browser');
+ document.body.classList.remove('pwa-browser', 'ios-safari');
document.body.classList.add('pwa-installed');
});
- // Дополнительная проверка для iOS
- if (this.isIOSSafari()) {
- let wasStandalone = window.navigator.standalone;
+ // Дополнительная проверка для всех устройств при изменении видимости
+ window.addEventListener('visibilitychange', () => {
+ if (document.hidden) return;
- window.addEventListener('visibilitychange', () => {
- if (document.hidden) return;
+ setTimeout(() => {
+ const wasInstalled = this.isInstalled;
+ this.checkInstallationStatus();
- 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');
-
- // Сохраняем предпочтение установки
- this.saveInstallPreference('installed', true);
- }
-
- wasStandalone = isStandalone;
- }, 1000);
- });
- }
+ // Если статус изменился с "не установлено" на "установлено"
+ if (!wasInstalled && this.isInstalled) {
+ console.log('✅ PWA installation detected on visibility change');
+ this.hideInstallPrompts();
+ this.showInstallSuccess();
+ }
+ }, 1000);
+ });
+
+ // Проверяем при фокусе окна
+ window.addEventListener('focus', () => {
+ setTimeout(() => {
+ const wasInstalled = this.isInstalled;
+ this.checkInstallationStatus();
+
+ if (!wasInstalled && this.isInstalled) {
+ console.log('✅ PWA installation detected on window focus');
+ this.hideInstallPrompts();
+ this.showInstallSuccess();
+ }
+ }, 500);
+ });
}
createInstallButton() {
- this.installButton = document.createElement('button');
+ // Если уже установлено, не создаем кнопку
+ if (this.isInstalled) {
+ return;
+ }
+
+ this.installButton = document.createElement('div');
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';
@@ -158,17 +197,33 @@ class PWAInstallPrompt {
${buttonText}
+
`;
- this.installButton.addEventListener('click', () => {
- this.handleInstallClick();
+ // Обработчик для установки
+ this.installButton.addEventListener('click', (e) => {
+ if (!e.target.classList.contains('close-btn')) {
+ this.handleInstallClick();
+ }
+ });
+
+ // Обработчик для закрытия
+ const closeBtn = this.installButton.querySelector('.close-btn');
+ closeBtn.addEventListener('click', (e) => {
+ e.stopPropagation();
+ this.dismissInstallPrompt();
});
document.body.appendChild(this.installButton);
}
createInstallBanner() {
- if (this.installBanner) return;
+ // Если уже установлено, не создаем баннер
+ if (this.isInstalled || this.installBanner) {
+ return;
+ }
this.installBanner = document.createElement('div');
this.installBanner.id = 'pwa-install-banner';
@@ -190,8 +245,8 @@ class PWAInstallPrompt {
Install
-