Implement Web Push Notifications system
- Add push_notifications.py module for managing subscriptions and sending notifications - Create Flask API endpoints for subscription management (/api/push/*) - Integrate push sending with existing notification system (_create_notification) - Create frontend JavaScript library (push-notifications.js) for client-side subscription - Update base.html template with manifest link and Service Worker registration - Add manifest.json and service-worker.js for PWA support - Add pywebpush dependency to requirements.txt - Create generate-vapid-keys.sh script for VAPID key generation - Add comprehensive documentation (WEB_PUSH_NOTIFICATIONS.md) Features: - Subscribe/unsubscribe users from push notifications - Store subscriptions in MongoDB with automatic indexing - Send push to individual users or all admins - Notification deduplication and versioning - Service Worker handles offline caching and push events - Full PWA support for mobile app installation - VAPID authentication for secure push communication
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css', v=ASSET_VERSION) }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/planned_appointments.css', v=ASSET_VERSION) }}">
|
||||
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
||||
<link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
(function () {
|
||||
@@ -1752,5 +1753,28 @@
|
||||
<!-- Mobile compatibility scripts -->
|
||||
<script src="{{ url_for('static', filename='js/mobile_compatibility.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/ios_fixes.js') }}"></script>
|
||||
|
||||
<!-- Service Worker Registration for Push Notifications -->
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Register service worker for push notifications and offline support
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('{{ url_for("static", filename="service-worker.js") }}')
|
||||
.then(function(registration) {
|
||||
console.log('Service Worker registered successfully:', registration);
|
||||
|
||||
// Check if we have permission for push notifications
|
||||
if ('Notification' in window && Notification.permission === 'granted') {
|
||||
console.log('Push notifications already enabled');
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.warn('Service Worker registration failed:', error);
|
||||
});
|
||||
} else {
|
||||
console.log('Service Workers not supported in this browser');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user