main.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { createApp } from 'vue'
  3. import '#desktop/styles/main.css'
  4. import { useSessionStore } from '#shared/stores/session.ts'
  5. import initializeStoreSubscriptions from '#shared/initializer/storeSubscriptions.ts'
  6. import { useApplicationStore } from '#shared/stores/application.ts'
  7. import { useLocaleStore } from '#shared/stores/locale.ts'
  8. import { useAppTheme } from '#shared/stores/theme.ts'
  9. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  10. import initializeStore from '#shared/stores/index.ts'
  11. import initializeGlobalComponents from '#shared/initializer/globalComponents.ts'
  12. import { initializeAppName } from '#shared/composables/useAppName.ts'
  13. import initializeGlobalProperties from '#shared/initializer/globalProperties.ts'
  14. import { initializeDesktopIcons } from '#desktop/initializer/initializeDesktopIcons.ts'
  15. import { initializeGlobalComponentStyles } from '#desktop/initializer/initializeGlobalComponentStyles.ts'
  16. import initializeApolloClient from '#desktop/server/apollo/index.ts'
  17. import initializeRouter from '#desktop/router/index.ts'
  18. import { initializeForm, initializeFormFields } from '#desktop/form/index.ts'
  19. import { ensureAfterAuth } from './pages/authentication/after-auth/composable/useAfterAuthPlugins.ts'
  20. import App from './AppDesktop.vue'
  21. export const mountApp = async () => {
  22. const app = createApp(App)
  23. initializeApolloClient(app)
  24. const router = initializeRouter(app)
  25. initializeStore(app)
  26. initializeDesktopIcons()
  27. initializeForm(app)
  28. initializeFormFields()
  29. initializeGlobalComponentStyles()
  30. initializeGlobalComponents(app)
  31. initializeAppName('desktop')
  32. initializeGlobalProperties(app)
  33. initializeStoreSubscriptions()
  34. const session = useSessionStore()
  35. const authentication = useAuthenticationStore()
  36. // If the session is invalid, clear the already set authentication flag from storage.
  37. if (!(await session.checkSession()) && authentication.authenticated) {
  38. authentication.authenticated = false
  39. }
  40. const application = useApplicationStore()
  41. const initalizeAfterSessionCheck: Array<Promise<unknown>> = [
  42. application.getConfig(),
  43. ]
  44. if (session.id) {
  45. authentication.authenticated = true
  46. initalizeAfterSessionCheck.push(session.getCurrentUser())
  47. }
  48. await Promise.all(initalizeAfterSessionCheck)
  49. if (session.id) session.initialized = true
  50. const locale = useLocaleStore()
  51. if (!locale.localeData) {
  52. await locale.setLocale()
  53. }
  54. // sync theme so the store is initialized and user (if exists) and DOM have the same value
  55. useAppTheme().syncTheme()
  56. if (VITE_TEST_MODE) {
  57. await import('#shared/initializer/initializeFakeTimer.ts')
  58. }
  59. app.mount('#app')
  60. if (session.afterAuth) {
  61. await ensureAfterAuth(router, session.afterAuth)
  62. }
  63. }