main.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: { normal: { enter: 300, leave: 200 } },
  44. }) // :TODO move this argument to own config?
  45. const session = useSessionStore()
  46. const authentication = useAuthenticationStore()
  47. // If the session is invalid, clear the already set authentication flag from storage.
  48. if (!(await session.checkSession()) && authentication.authenticated) {
  49. authentication.authenticated = false
  50. }
  51. const application = useApplicationStore()
  52. const initalizeAfterSessionCheck: Array<Promise<unknown>> = [
  53. application.getConfig(),
  54. ]
  55. if (session.id) {
  56. authentication.authenticated = true
  57. initalizeAfterSessionCheck.push(session.getCurrentUser())
  58. }
  59. await Promise.all(initalizeAfterSessionCheck)
  60. if (session.id) session.initialized = true
  61. const locale = useLocaleStore()
  62. if (!locale.localeData) {
  63. await locale.setLocale()
  64. }
  65. // sync theme so the store is initialized and user (if exists) and DOM have the same value
  66. useThemeStore().syncTheme()
  67. if (VITE_TEST_MODE) {
  68. await import('#shared/initializer/initializeFakeTimer.ts')
  69. }
  70. app.mount('#app')
  71. if (session.afterAuth) {
  72. await ensureAfterAuth(router, session.afterAuth)
  73. }
  74. }