App.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div id="q-app">
  3. <router-view :key="$route.path" />
  4. </div>
  5. </template>
  6. <script>
  7. import process from 'process'
  8. // import { Plugins } from '@capacitor/core'
  9. // const { Network } = Plugins
  10. import { defineComponent } from 'vue'
  11. import { APIGateway } from 'src/api/APIGateway'
  12. export default defineComponent({
  13. name: 'App',
  14. data: () => ({
  15. refreshing: false,
  16. registration: null,
  17. updateExists: false
  18. }),
  19. // created () {
  20. // this.setServiceWorker()
  21. // this.checkInternetConnection()
  22. // },
  23. // mounted () {
  24. // this.checkWebVersion()
  25. // },
  26. methods: {
  27. checkWebVersion () {
  28. const webAppVersion = '1.0.0'
  29. APIGateway.version.getLastVersion()
  30. .then((version) => {
  31. const isLastVersion = version.web.last_version === webAppVersion
  32. if (!isLastVersion) {
  33. window.location.reload()
  34. }
  35. })
  36. },
  37. // async checkInternetConnection () {
  38. // Network.addListener('networkStatusChange', (status) => {
  39. // // alert("Network status changed" + status)
  40. // // window.location.reload()
  41. // console.log('Network status changed', status)
  42. // })
  43. //
  44. // // Get the current network status
  45. // const status = await Network.getStatus()
  46. // console.log('status', status)
  47. // },
  48. setServiceWorker () {
  49. // Listen for our custom event from the SW registration
  50. if (!process.browser) {
  51. return
  52. }
  53. document.addEventListener('swUpdated', this.updateAvailable, { once: true })
  54. if (navigator && navigator.serviceWorker) {
  55. // Prevent multiple refreshes
  56. navigator.serviceWorker.addEventListener('controllerchange', () => {
  57. if (this.refreshing) return
  58. this.refreshing = true
  59. // Here the actual reload of the page occurs
  60. // window.location.reload()
  61. })
  62. }
  63. },
  64. updateAvailable (event) {
  65. this.registration = event.detail
  66. this.updateExists = true
  67. }
  68. }
  69. })
  70. </script>