feat: Register background sync for offline actions when queued or stored
This commit is contained in:
+13
-1
@@ -16,6 +16,12 @@ window.queueOfflineAction = function(action, payload) {
|
||||
.then(data => {
|
||||
if (data.queued) {
|
||||
console.log('Action queued:', action);
|
||||
// Register background sync to process the queue
|
||||
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
|
||||
return navigator.serviceWorker.ready.then(registration => {
|
||||
return registration.sync.register('offline-sync');
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.error('Failed to queue action:', data);
|
||||
}
|
||||
@@ -30,11 +36,17 @@ window.queueOfflineAction = function(action, payload) {
|
||||
list.push(pendingAction);
|
||||
localforage.setItem('pendingOffline', list);
|
||||
console.log('Action stored offline:', action);
|
||||
// Register background sync for when we come back online
|
||||
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
|
||||
return navigator.serviceWorker.ready.then(registration => {
|
||||
return registration.sync.register('offline-sync');
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('Error storing offline action:', err);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Function to store offline progress update (for backward compatibility)
|
||||
window.offlineProgressUpdate = function(phaseId, progress, comment, location) {
|
||||
|
||||
Reference in New Issue
Block a user