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 => {
|
.then(data => {
|
||||||
if (data.queued) {
|
if (data.queued) {
|
||||||
console.log('Action queued:', action);
|
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 {
|
} else {
|
||||||
console.error('Failed to queue action:', data);
|
console.error('Failed to queue action:', data);
|
||||||
}
|
}
|
||||||
@@ -30,11 +36,17 @@ window.queueOfflineAction = function(action, payload) {
|
|||||||
list.push(pendingAction);
|
list.push(pendingAction);
|
||||||
localforage.setItem('pendingOffline', list);
|
localforage.setItem('pendingOffline', list);
|
||||||
console.log('Action stored offline:', action);
|
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 => {
|
}).catch(err => {
|
||||||
console.error('Error storing offline action:', err);
|
console.error('Error storing offline action:', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Function to store offline progress update (for backward compatibility)
|
// Function to store offline progress update (for backward compatibility)
|
||||||
window.offlineProgressUpdate = function(phaseId, progress, comment, location) {
|
window.offlineProgressUpdate = function(phaseId, progress, comment, location) {
|
||||||
|
|||||||
Reference in New Issue
Block a user