App.vue 1.9 KB

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