Skip to content

Commit

Permalink
Merge pull request #452 from pkarw/master
Browse files Browse the repository at this point in the history
Check for online queue
  • Loading branch information
pkarw authored Dec 20, 2017
2 parents 98ea221 + 1e69d1f commit ff03ba4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
17 changes: 17 additions & 0 deletions src/client-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,20 @@ EventBus.$on('sync/PROCESS_QUEUE', data => {

EventBus.$emit('order/PROCESS_QUEUE', { config: config }) // process checkout queue
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue

/**
* Process order queue when we're back onlin
*/
function checkiIsOnline () {
EventBus.$emit('network.status', { online: navigator.onLine })
console.log('Are we online: ' + navigator.onLine)

if (navigator.onLine) {
EventBus.$emit('order/PROCESS_QUEUE', { config: config }) // process checkout queue
EventBus.$emit('sync/PROCESS_QUEUE', { config: config }) // process checkout queue
}
}

window.addEventListener('online', checkiIsOnline)
window.addEventListener('offline', checkiIsOnline)

23 changes: 0 additions & 23 deletions src/service-worker-registration.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import config from './config.json'
import * as types from './store/mutation-types'
import EventBus from 'src/event-bus'

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js', { scope: '/' }).then(function () {
if (navigator.serviceWorker.controller) {
Expand All @@ -11,22 +7,3 @@ if ('serviceWorker' in navigator) {
}
})
}

/**
* Process order queue when we're back onlin
*/
function checkiIsOnline () {
EventBus.$emit('network.status', { online: navigator.onLine })
console.log('Are we online: ' + navigator.onLine)

if (navigator.onLine) {
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({ config: config, command: types.ORDER_PROCESS_QUEUE })
navigator.serviceWorker.controller.postMessage({ config: config, command: types.SYNC_PROCESS_QUEUE })
}
}
}

window.addEventListener('online', checkiIsOnline)
window.addEventListener('offline', checkiIsOnline)

0 comments on commit ff03ba4

Please sign in to comment.