main.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. export const mountApp = async () => {
  27. const app = createApp(App)
  28. initializeAppName('desktop')
  29. initializeApolloClient(app)
  30. const router = initializeRouter(app)
  31. initializeStore(app)
  32. initializeDesktopIcons()
  33. initializeForm(app)
  34. initializeFormFields()
  35. initializeGlobalComponentStyles()
  36. initializeGlobalComponents(app)
  37. initializeGlobalProperties(app)
  38. initializeGlobalDirectives(app)
  39. initializeStoreSubscriptions()
  40. initializeDesktopVisuals()
  41. initializeTwoFactorPlugins(twoFactorConfigurationPluginLookup)
  42. initializeAbstracts({
  43. durations: {
  44. normal: { enter: 300, leave: 200 },
  45. },
  46. }) // :TODO move this argument to own config?
  47. const session = useSessionStore()
  48. const authentication = useAuthenticationStore()
  49. // If the session is invalid, clear the already set authentication flag from storage.
  50. if (!(await session.checkSession()) && authentication.authenticated) {
  51. authentication.authenticated = false
  52. }
  53. const application = useApplicationStore()
  54. const initalizeAfterSessionCheck: Array<Promise<unknown>> = [
  55. application.getConfig(),
  56. ]
  57. if (session.id) {
  58. authentication.authenticated = true
  59. initalizeAfterSessionCheck.push(session.getCurrentUser())
  60. }
  61. await Promise.all(initalizeAfterSessionCheck)
  62. if (session.id) session.initialized = true
  63. const locale = useLocaleStore()
  64. if (!locale.localeData) {
  65. await locale.setLocale()
  66. }
  67. // sync theme so the store is initialized and user (if exists) and DOM have the same value
  68. useThemeStore().syncTheme()
  69. if (VITE_TEST_MODE) {
  70. await import('#shared/initializer/initializeFakeTimer.ts')
  71. }
  72. app.mount('#app')
  73. if (session.afterAuth) {
  74. await ensureAfterAuth(router, session.afterAuth)
  75. }
  76. }