From 0f720567c3bf2099dcf684ee25ea684c44a9f3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Bra=C3=B1a?= Date: Wed, 27 May 2026 09:29:44 +0200 Subject: [PATCH] feat: Register background sync for offline actions when queued or stored --- resources/js/app.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/js/app.js b/resources/js/app.js index 486a9e2..5c20874 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -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) {