Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit ff03ba4

Browse files
authored
Merge pull request #452 from pkarw/master
Check for online queue
2 parents 98ea221 + 1e69d1f commit ff03ba4

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

src/client-entry.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,20 @@ EventBus.$on('sync/PROCESS_QUEUE', data => {
191191

192192
EventBus.$emit('order/PROCESS_QUEUE', { config: config }) // process checkout queue
193193
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue
194+
195+
/**
196+
* Process order queue when we're back onlin
197+
*/
198+
function checkiIsOnline () {
199+
EventBus.$emit('network.status', { online: navigator.onLine })
200+
console.log('Are we online: ' + navigator.onLine)
201+
202+
if (navigator.onLine) {
203+
EventBus.$emit('order/PROCESS_QUEUE', { config: config }) // process checkout queue
204+
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue
205+
}
206+
}
207+
208+
window.addEventListener('online', checkiIsOnline)
209+
window.addEventListener('offline', checkiIsOnline)
210+

src/service-worker-registration.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import config from './config.json'
2-
import * as types from './store/mutation-types'
3-
import EventBus from 'src/event-bus'
4-
51
if ('serviceWorker' in navigator) {
62
navigator.serviceWorker.register('/service-worker.js', { scope: '/' }).then(function () {
73
if (navigator.serviceWorker.controller) {
@@ -11,22 +7,3 @@ if ('serviceWorker' in navigator) {
117
}
128
})
139
}
14-
15-
/**
16-
* Process order queue when we're back onlin
17-
*/
18-
function checkiIsOnline () {
19-
EventBus.$emit('network.status', { online: navigator.onLine })
20-
console.log('Are we online: ' + navigator.onLine)
21-
22-
if (navigator.onLine) {
23-
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
24-
navigator.serviceWorker.controller.postMessage({ config: config, command: types.ORDER_PROCESS_QUEUE })
25-
navigator.serviceWorker.controller.postMessage({ config: config, command: types.SYNC_PROCESS_QUEUE })
26-
}
27-
}
28-
}
29-
30-
window.addEventListener('online', checkiIsOnline)
31-
window.addEventListener('offline', checkiIsOnline)
32-

0 commit comments

Comments
 (0)