App.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. computed: {
  20. accessToken () {
  21. return this.$store.getters['Auth/accessToken']
  22. }
  23. },
  24. // created () {
  25. // this.setServiceWorker()
  26. // this.checkInternetConnection()
  27. // },
  28. // mounted () {
  29. // this.checkWebVersion()
  30. // },
  31. methods: {
  32. checkWebVersion () {
  33. const webAppVersion = '1.0.0'
  34. APIGateway.version.getLastVersion()
  35. .then((version) => {
  36. const isLastVersion = version.web.last_version === webAppVersion
  37. if (!isLastVersion) {
  38. window.location.reload()
  39. }
  40. })
  41. },
  42. // async checkInternetConnection () {
  43. // Network.addListener('networkStatusChange', (status) => {
  44. // // alert("Network status changed" + status)
  45. // // window.location.reload()
  46. // console.log('Network status changed', status)
  47. // })
  48. //
  49. // // Get the current network status
  50. // const status = await Network.getStatus()
  51. // console.log('status', status)
  52. // },
  53. setServiceWorker () {
  54. // Listen for our custom event from the SW registration
  55. if (!process.browser) {
  56. return
  57. }
  58. document.addEventListener('swUpdated', this.updateAvailable, { once: true })
  59. if (navigator && navigator.serviceWorker) {
  60. // Prevent multiple refreshes
  61. navigator.serviceWorker.addEventListener('controllerchange', () => {
  62. if (this.refreshing) return
  63. this.refreshing = true
  64. // Here the actual reload of the page occurs
  65. // window.location.reload()
  66. })
  67. }
  68. },
  69. updateAvailable (event) {
  70. this.registration = event.detail
  71. this.updateExists = true
  72. }
  73. }
  74. })
  75. </script>