main.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { createApp } from 'vue'
  3. import '#mobile/styles/main.css'
  4. import { initializeAppName } from '#shared/composables/useAppName.ts'
  5. import { useForceDesktop } from '#shared/composables/useForceDesktop.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 { initializeForm, initializeFormFields } from '#mobile/form/index.ts'
  16. import { initializeGlobalComponentStyles } from '#mobile/initializer/initializeGlobalComponentStyles.ts'
  17. import initializeGlobalDirectives from '#mobile/initializer/initializeGlobalDirectives.ts'
  18. import { initializeMobileIcons } from '#mobile/initializer/initializeMobileIcons.ts'
  19. import { initializeMobileVisuals } from '#mobile/initializer/mobileVisuals.ts'
  20. import initializeRouter from '#mobile/router/index.ts'
  21. import initializeApolloClient from '#mobile/server/apollo/index.ts'
  22. import App from './AppMobile.vue'
  23. import { ensureAfterAuth } from './pages/authentication/after-auth/composable/useAfterAuthPlugins.ts'
  24. const { forceDesktopLocalStorage } = useForceDesktop()
  25. // If the user explicitly switched to the desktop app the last time around,
  26. // redirect them automatically, before hoisting the app.
  27. if (forceDesktopLocalStorage.value) window.location.href = '/'
  28. export default async function mountApp(): Promise<void> {
  29. const app = createApp(App)
  30. initializeAppName('mobile')
  31. initializeApolloClient(app)
  32. const router = initializeRouter(app)
  33. Object.defineProperty(window, 'Router', { value: router, configurable: true })
  34. initializeStore(app)
  35. initializeMobileIcons()
  36. initializeForm(app)
  37. initializeFormFields()
  38. initializeGlobalComponentStyles()
  39. initializeGlobalComponents(app)
  40. initializeGlobalProperties(app)
  41. initializeGlobalDirectives(app)
  42. initializeMobileVisuals()
  43. initializeStoreSubscriptions()
  44. initializeAbstracts({
  45. durations: { normal: { enter: 300, leave: 200 } },
  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. 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. }