feat(update-notification): implement update notification system for new versions
- Added a service worker message handler to check for updates and notify users. - Created `UpdateNotification` component to display update prompts with options to reload or dismiss. - Introduced `UpdateNotificationProvider` to manage update state and notifications globally. - Implemented `useUpdateChecker` hook for periodic update checks and user notification management. - Updated localization files to include new strings related to update notifications. - Enhanced service worker functionality to support hard reloads and update checks.
This commit is contained in:
@@ -198,6 +198,17 @@ export class ServiceWorkerManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
async checkForUpdates(): Promise<boolean> {
|
||||
try {
|
||||
const response = await this.sendMessage('CHECK_FOR_UPDATES');
|
||||
return response.hasUpdates;
|
||||
} catch (error) {
|
||||
console.error('Failed to check for updates:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Force update service worker
|
||||
async forceUpdate(): Promise<void> {
|
||||
if (!this.registration) return;
|
||||
@@ -212,6 +223,27 @@ export class ServiceWorkerManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Perform hard reload (clear cache and reload)
|
||||
async hardReload(): Promise<void> {
|
||||
try {
|
||||
// Clear all caches first
|
||||
await this.clearCache();
|
||||
|
||||
// Force update the service worker
|
||||
if (this.registration) {
|
||||
await this.registration.update();
|
||||
await this.sendMessage('SKIP_WAITING');
|
||||
}
|
||||
|
||||
// Perform hard reload by clearing browser cache
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
console.error('Failed to perform hard reload:', error);
|
||||
// Fallback to regular reload
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if app is running offline
|
||||
isOffline(): boolean {
|
||||
return !navigator.onLine;
|
||||
@@ -268,6 +300,8 @@ export function useServiceWorker() {
|
||||
swManager,
|
||||
clearCache: () => swManager?.clearCache(),
|
||||
forceUpdate: () => swManager?.forceUpdate(),
|
||||
hardReload: () => swManager?.hardReload(),
|
||||
checkForUpdates: () => swManager?.checkForUpdates(),
|
||||
getVersion: () => swManager?.getVersion(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user