main.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { createApp } from 'vue'
  3. import '#desktop/styles/main.css'
  4. import { initializeAppName } from '#shared/composables/useAppName.ts'
  5. import { initializeTwoFactorPlugins } from '#shared/entities/two-factor/composables/initializeTwoFactorPlugins.ts'
  6. import initializeGlobalComponents from '#shared/initializer/globalComponents.ts'
  7. import initializeGlobalProperties from '#shared/initializer/globalProperties.ts'
  8. import { initializeAbstracts } from '#shared/initializer/initializeAbstracts.ts'
  9. import initializeStoreSubscriptions from '#shared/initializer/storeSubscriptions.ts'
  10. import { useApplicationStore } from '#shared/stores/application.ts'
  11. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  12. import initializeStore from '#shared/stores/index.ts'
  13. import { useLocaleStore } from '#shared/stores/locale.ts'
  14. import { useSessionStore } from '#shared/stores/session.ts'
  15. import { twoFactorConfigurationPluginLookup } from '#desktop/entities/two-factor-configuration/plugins/index.ts'
  16. import { initializeForm, initializeFormFields } from '#desktop/form/index.ts'
  17. import { initializeDesktopVisuals } from '#desktop/initializer/desktopVisuals.ts'
  18. import { initializeDesktopIcons } from '#desktop/initializer/initializeDesktopIcons.ts'
  19. import { initializeGlobalComponentStyles } from '#desktop/initializer/initializeGlobalComponentStyles.ts'
  20. import initializeGlobalDirectives from '#desktop/initializer/initializeGlobalDirectives.ts'
  21. import { ensureAfterAuth } from '#desktop/pages/authentication/after-auth/composable/useAfterAuthPlugins.ts'
  22. import initializeRouter from '#desktop/router/index.ts'
  23. import initializeApolloClient from '#desktop/server/apollo/index.ts'
  24. import { useThemeStore } from '#desktop/stores/theme.ts'
  25. import App from './AppDesktop.vue'
  26. import { setCurrentApp } from './currentApp.ts'
  27. export const mountApp = async () => {
  28. const app = createApp(App)
  29. // Remember the current created app.
  30. setCurrentApp(app)
  31. initializeAppName('desktop')
  32. initializeApolloClient(app)
  33. const router = initializeRouter(app)
  34. initializeStore(app)
  35. initializeDesktopIcons()
  36. initializeForm(app)
  37. initializeFormFields()
  38. initializeGlobalComponentStyles()
  39. initializeGlobalComponents(app)
  40. initializeGlobalProperties(app)
  41. initializeGlobalDirectives(app)
  42. initializeStoreSubscriptions()
  43. initializeDesktopVisuals()
  44. initializeTwoFactorPlugins(twoFactorConfigurationPluginLookup)
  45. initializeAbstracts({
  46. durations: {
  47. normal: { enter: 300, leave: 200 },
  48. },
  49. }) // :TODO move this argument to own config?
  50. const session = useSessionStore()
  51. const authentication = useAuthenticationStore()
  52. // If the session is invalid, clear the already set authentication flag from storage.
  53. if (!(await session.checkSession()) && authentication.authenticated) {
  54. authentication.authenticated = false
  55. }
  56. const application = useApplicationStore()
  57. const initalizeAfterSessionCheck: Array<Promise<unknown>> = [
  58. application.getConfig(),
  59. ]
  60. if (session.id) {
  61. authentication.authenticated = true
  62. initalizeAfterSessionCheck.push(session.getCurrentUser())
  63. }
  64. await Promise.all(initalizeAfterSessionCheck)
  65. if (session.id) session.initialized = true
  66. const locale = useLocaleStore()
  67. if (!locale.localeData) {
  68. await locale.setLocale()
  69. }
  70. // sync theme so the store is initialized and user (if exists) and DOM have the same value
  71. useThemeStore().syncTheme()
  72. if (VITE_TEST_MODE) {
  73. await import('#shared/initializer/initializeFakeTimer.ts')
  74. }
  75. app.mount('#app')
  76. if (session.afterAuth) {
  77. await ensureAfterAuth(router, session.afterAuth)
  78. }
  79. }