AppMobile.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { onBeforeUnmount, onMounted, watch } from 'vue'
  4. import { useRouter } from 'vue-router'
  5. import CommonImageViewer from '#shared/components/CommonImageViewer/CommonImageViewer.vue'
  6. import CommonNotifications from '#shared/components/CommonNotifications/CommonNotifications.vue'
  7. import DynamicInitializer from '#shared/components/DynamicInitializer/DynamicInitializer.vue'
  8. import useAuthenticationChanges from '#shared/composables/authentication/useAuthenticationUpdates.ts'
  9. import useFormKitConfig from '#shared/composables/form/useFormKitConfig.ts'
  10. import useAppMaintenanceCheck from '#shared/composables/useAppMaintenanceCheck.ts'
  11. import useMetaTitle from '#shared/composables/useMetaTitle.ts'
  12. import usePushMessages from '#shared/composables/usePushMessages.ts'
  13. import { useApplicationStore } from '#shared/stores/application.ts'
  14. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  15. import { useLocaleStore } from '#shared/stores/locale.ts'
  16. import { useSessionStore } from '#shared/stores/session.ts'
  17. import { registerSW } from '#shared/sw/register.ts'
  18. import emitter from '#shared/utils/emitter.ts'
  19. import CommonConfirmation from '#mobile/components/CommonConfirmation/CommonConfirmation.vue'
  20. import { useTicketOverviewsStore } from './entities/ticket/stores/ticketOverviews.ts'
  21. const router = useRouter()
  22. const authentication = useAuthenticationStore()
  23. const session = useSessionStore()
  24. useMetaTitle().initializeMetaTitle()
  25. const application = useApplicationStore()
  26. onMounted(() => {
  27. // If Zammad was not properly set up yet, redirect to desktop front end.
  28. if (!application.config.system_init_done) {
  29. window.location.pathname = '/'
  30. } else {
  31. application.setLoaded()
  32. }
  33. })
  34. const updateServiceWorker = registerSW({
  35. path: '/mobile/sw.js',
  36. scope: '/mobile/',
  37. })
  38. useAppMaintenanceCheck({ onNeedRefresh: () => updateServiceWorker(true) })
  39. usePushMessages()
  40. // Add a check for authenticated changes (e.g. login/logout in a other
  41. // browser tab or maintenance mode switch).
  42. useAuthenticationChanges()
  43. // We need to trigger a manual translation update for the form related strings.
  44. const formConfig = useFormKitConfig()
  45. useLocaleStore().$subscribe(() => {
  46. formConfig.locale = 'staticLocale'
  47. })
  48. // The handling for invalid sessions. The event will be emitted, when from the server a "NotAuthorized"
  49. // response is received.
  50. emitter.on('sessionInvalid', async () => {
  51. if (authentication.authenticated) {
  52. await authentication.clearAuthentication()
  53. router.replace({
  54. name: 'Login',
  55. query: {
  56. invalidatedSession: '1',
  57. },
  58. })
  59. }
  60. })
  61. // Initialize the ticket overview store after a valid session is present on
  62. // the app level, so that the query keeps alive.
  63. watch(
  64. () => session.initialized,
  65. (newValue, oldValue) => {
  66. if (!oldValue && newValue) {
  67. useTicketOverviewsStore()
  68. }
  69. },
  70. { immediate: true },
  71. )
  72. onBeforeUnmount(() => {
  73. emitter.off('sessionInvalid')
  74. })
  75. // Do not animate transitions in the test mode.
  76. const transition = VITE_TEST_MODE
  77. ? undefined
  78. : {
  79. enterActiveClass: 'duration-300 ease-out',
  80. enterFromClass: 'opacity-0 translate-y-3/4',
  81. enterToClass: 'opacity-100 translate-y-0',
  82. leaveActiveClass: 'duration-200 ease-in',
  83. leaveFromClass: 'opacity-100 translate-y-0',
  84. leaveToClass: 'opacity-0 translate-y-3/4',
  85. }
  86. </script>
  87. <template>
  88. <template v-if="application.loaded">
  89. <CommonNotifications />
  90. <CommonConfirmation />
  91. <Teleport to="body">
  92. <CommonImageViewer />
  93. </Teleport>
  94. </template>
  95. <div
  96. v-if="application.loaded"
  97. class="h-full min-w-full bg-black font-sans text-sm text-white antialiased"
  98. >
  99. <RouterView />
  100. </div>
  101. <DynamicInitializer name="dialog" :transition="transition" />
  102. </template>