🐛 Fix PWA install prompt showing after installation

Fixed critical bug where PWA install message continued showing after app installation

-  Enhanced PWA installation status detection
-  Fixed install prompt logic to hide after installation
-  Improved Service Worker update handling
-  Added proper installation state management
-  Enhanced iOS Safari PWA detection
-  Added installation preferences storage

- Added installationChecked flag for better state management
- Enhanced checkInstallationStatus() method with multiple detection methods
- Improved shouldShowPrompt() logic to prevent showing after installation
- Added periodic installation monitoring for iOS devices
- Enhanced Service Worker activation event handling
- Added PWAUtils.checkInstallationStatus() utility method

- public/src/pwa/install-prompt.js (major refactor)
- public/index.html (PWA logic improvements)
- public/sw.js (Service Worker enhancements)

- PWA install message no longer shows after successful installation
- Only update notifications are shown for installed PWAs
- Proper distinction between install prompts and update notifications

Version: Enhanced Security Edition v4.01.413
This commit is contained in:
lockbitchat
2025-08-23 17:21:32 -04:00
parent 235e3e06cb
commit 434301fe6f
7 changed files with 286 additions and 50 deletions

51
sw.js
View File

@@ -1,5 +1,5 @@
// SecureBit.chat Service Worker
// Enhanced Security Edition v4.01.412
// Enhanced Security Edition v4.01.413
const CACHE_NAME = 'securebit-v4.0.3';
const STATIC_CACHE = 'securebit-static-v4.0.3';
@@ -96,32 +96,41 @@ self.addEventListener('install', (event) => {
);
});
// Activate event - clean up old caches
// Activate event - clean up old caches and notify about updates
self.addEventListener('activate', (event) => {
console.log('🚀 Service Worker activating...');
event.waitUntil(
caches.keys()
.then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== STATIC_CACHE &&
cacheName !== DYNAMIC_CACHE &&
cacheName !== CACHE_NAME) {
console.log('🗑️ Deleting old cache:', cacheName);
return caches.delete(cacheName);
}
})
);
})
.then(() => {
console.log('✅ Service Worker activated');
// Claim all clients immediately
return self.clients.claim();
})
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
// Remove old caches
if (cacheName !== STATIC_CACHE && cacheName !== DYNAMIC_CACHE && cacheName !== CACHE_NAME) {
console.log(`🗑️ Removing old cache: ${cacheName}`);
return caches.delete(cacheName);
}
})
);
}).then(() => {
console.log('✅ Service Worker activated and old caches cleaned');
// Notify all clients about the update
return self.clients.claim().then(() => {
self.clients.matchAll().then(clients => {
clients.forEach(client => {
client.postMessage({
type: 'SW_ACTIVATED',
timestamp: Date.now()
});
});
});
});
})
);
});
// Удаляем дублирующийся код activate event
// Fetch event - handle requests with security-aware caching
self.addEventListener('fetch', (event) => {
const url = new URL(event.request.url);
@@ -352,4 +361,4 @@ self.addEventListener('unhandledrejection', (event) => {
console.error('❌ Service Worker unhandled rejection:', event.reason);
});
console.log('🔧 SecureBit.chat Service Worker loaded - Enhanced Security Edition v4.01.412');
console.log('🔧 SecureBit.chat Service Worker loaded - Enhanced Security Edition v4.01.413');