main.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 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 { initializeForm, initializeFormFields } from '#mobile/form/index.ts'
  15. import { initializeGlobalComponentStyles } from '#mobile/initializer/initializeGlobalComponentStyles.ts'
  16. import { initializeMobileIcons } from '#mobile/initializer/initializeMobileIcons.ts'
  17. import { initializeMobileVisuals } from '#mobile/initializer/mobileVisuals.ts'
  18. import initializeRouter from '#mobile/router/index.ts'
  19. import initializeApolloClient from '#mobile/server/apollo/index.ts'
  20. import App from './AppMobile.vue'
  21. import { ensureAfterAuth } from './pages/authentication/after-auth/composable/useAfterAuthPlugins.ts'
  22. const { forceDesktopLocalStorage } = useForceDesktop()
  23. // If the user explicitly switched to the desktop app the last time around,
  24. // redirect them automatically, before hoisting the app.
  25. if (forceDesktopLocalStorage.value) window.location.href = '/'
  26. export default async function mountApp(): Promise<void> {
  27. const app = createApp(App)
  28. initializeAppName('mobile')
  29. initializeApolloClient(app)
  30. const router = initializeRouter(app)
  31. Object.defineProperty(window, 'Router', { value: router, configurable: true })
  32. initializeStore(app)
  33. initializeMobileIcons()
  34. initializeForm(app)
  35. initializeFormFields()
  36. initializeGlobalComponentStyles()
  37. initializeGlobalComponents(app)
  38. initializeGlobalProperties(app)
  39. initializeMobileVisuals()
  40. initializeStoreSubscriptions()
  41. const session = useSessionStore()
  42. const authentication = useAuthenticationStore()
  43. // If the session is invalid, clear the already set authentication flag from storage.
  44. if (!(await session.checkSession()) && authentication.authenticated) {
  45. authentication.authenticated = false
  46. }
  47. const application = useApplicationStore()
  48. const initalizeAfterSessionCheck: Array<Promise<unknown>> = [
  49. application.getConfig(),
  50. ]
  51. if (session.id) {
  52. authentication.authenticated = true
  53. initalizeAfterSessionCheck.push(session.getCurrentUser())
  54. }
  55. await Promise.all(initalizeAfterSessionCheck)
  56. if (session.id) session.initialized = true
  57. const locale = useLocaleStore()
  58. if (!locale.localeData) {
  59. await locale.setLocale()
  60. }
  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. }