AppDesktop.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { onBeforeMount, onBeforeUnmount, 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 { initializeDefaultObjectAttributes } from '#shared/entities/object-attributes/composables/useObjectAttributes.ts'
  14. import { useApplicationStore } from '#shared/stores/application.ts'
  15. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  16. import { useLocaleStore } from '#shared/stores/locale.ts'
  17. import { useSessionStore } from '#shared/stores/session.ts'
  18. import emitter from '#shared/utils/emitter.ts'
  19. import { initializeConfirmationDialog } from '#desktop/components/CommonConfirmationDialog/initializeConfirmationDialog.ts'
  20. import { useUserCurrentTaskbarTabsStore } from '#desktop/entities/user/current/stores/taskbarTabs.ts'
  21. const router = useRouter()
  22. const authentication = useAuthenticationStore()
  23. const session = useSessionStore()
  24. useMetaTitle().initializeMetaTitle()
  25. const application = useApplicationStore()
  26. onBeforeMount(() => {
  27. application.setLoaded()
  28. })
  29. useAppMaintenanceCheck()
  30. usePushMessages()
  31. // Add a check for authenticated changes (e.g. login/logout in a other
  32. // browser tab or maintenance mode switch).
  33. useAuthenticationChanges()
  34. // We need to trigger a manual translation update for the form related strings.
  35. const formConfig = useFormKitConfig()
  36. useLocaleStore().$subscribe(() => {
  37. formConfig.locale = 'staticLocale'
  38. })
  39. // The handling for invalid sessions. The event will be emitted, when from the server a "NotAuthorized"
  40. // response is received.
  41. emitter.on('sessionInvalid', async () => {
  42. if (authentication.authenticated) {
  43. await authentication.clearAuthentication()
  44. router.replace({
  45. name: 'Login',
  46. query: {
  47. invalidatedSession: '1',
  48. },
  49. })
  50. }
  51. })
  52. initializeConfirmationDialog()
  53. // Initialize the user taskbar tabs store after a valid session is present on
  54. // the app level, so that the query keeps alive.
  55. watch(
  56. () => session.initialized,
  57. (newValue, oldValue) => {
  58. if (!newValue || oldValue) return
  59. useUserCurrentTaskbarTabsStore()
  60. initializeDefaultObjectAttributes()
  61. },
  62. { immediate: true },
  63. )
  64. onBeforeUnmount(() => {
  65. emitter.off('sessionInvalid')
  66. })
  67. </script>
  68. <template>
  69. <template v-if="application.loaded">
  70. <CommonNotifications />
  71. <Teleport to="body">
  72. <CommonImageViewer />
  73. </Teleport>
  74. <RouterView />
  75. <DynamicInitializer name="dialog" />
  76. <DynamicInitializer name="flyout" />
  77. </template>
  78. </template>