main.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 initializeStoreSubscriptions from '#shared/initializer/storeSubscriptions.ts'
  9. import { useApplicationStore } from '#shared/stores/application.ts'
  10. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  11. import initializeStore from '#shared/stores/index.ts'
  12. import { useLocaleStore } from '#shared/stores/locale.ts'
  13. import { useSessionStore } from '#shared/stores/session.ts'
  14. import { twoFactorConfigurationPluginLookup } from '#desktop/entities/two-factor-configuration/plugins/index.ts'
  15. import { initializeForm, initializeFormFields } from '#desktop/form/index.ts'
  16. import { initializeDesktopIcons } from '#desktop/initializer/initializeDesktopIcons.ts'
  17. import { initializeGlobalComponentStyles } from '#desktop/initializer/initializeGlobalComponentStyles.ts'
  18. import initializeGlobalDirectives from '#desktop/initializer/initializeGlobalDirectives.ts'
  19. import { ensureAfterAuth } from '#desktop/pages/authentication/after-auth/composable/useAfterAuthPlugins.ts'
  20. import initializeRouter from '#desktop/router/index.ts'
  21. import initializeApolloClient from '#desktop/server/apollo/index.ts'
  22. import { useThemeStore } from '#desktop/stores/theme.ts'
  23. import App from './AppDesktop.vue'
  24. export const mountApp = async () => {
  25. const app = createApp(App)
  26. initializeAppName('desktop')
  27. initializeApolloClient(app)
  28. const router = initializeRouter(app)
  29. initializeStore(app)
  30. initializeDesktopIcons()
  31. initializeForm(app)
  32. initializeFormFields()
  33. initializeGlobalComponentStyles()
  34. initializeGlobalComponents(app)
  35. initializeGlobalProperties(app)
  36. initializeGlobalDirectives(app)
  37. initializeStoreSubscriptions()
  38. initializeTwoFactorPlugins(twoFactorConfigurationPluginLookup)
  39. const session = useSessionStore()
  40. const authentication = useAuthenticationStore()
  41. // If the session is invalid, clear the already set authentication flag from storage.
  42. if (!(await session.checkSession()) && authentication.authenticated) {
  43. authentication.authenticated = false
  44. }
  45. const application = useApplicationStore()
  46. const initalizeAfterSessionCheck: Array<Promise<unknown>> = [
  47. application.getConfig(),
  48. ]
  49. if (session.id) {
  50. authentication.authenticated = true
  51. initalizeAfterSessionCheck.push(session.getCurrentUser())
  52. }
  53. await Promise.all(initalizeAfterSessionCheck)
  54. if (session.id) session.initialized = true
  55. const locale = useLocaleStore()
  56. if (!locale.localeData) {
  57. await locale.setLocale()
  58. }
  59. // sync theme so the store is initialized and user (if exists) and DOM have the same value
  60. useThemeStore().syncTheme()
  61. if (VITE_TEST_MODE) {
  62. await import('#shared/initializer/initializeFakeTimer.ts')
  63. }
  64. app.mount('#app')
  65. if (session.afterAuth) {
  66. await ensureAfterAuth(router, session.afterAuth)
  67. }
  68. }