main.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Vuex from 'vuex'
  4. import 'custom-event-polyfill'
  5. import './lib/event_target_polyfill.js'
  6. import interfaceModule from './modules/interface.js'
  7. import instanceModule from './modules/instance.js'
  8. import statusesModule from './modules/statuses.js'
  9. import usersModule from './modules/users.js'
  10. import apiModule from './modules/api.js'
  11. import configModule from './modules/config.js'
  12. import shoutModule from './modules/shout.js'
  13. import oauthModule from './modules/oauth.js'
  14. import authFlowModule from './modules/auth_flow.js'
  15. import mediaViewerModule from './modules/media_viewer.js'
  16. import oauthTokensModule from './modules/oauth_tokens.js'
  17. import reportsModule from './modules/reports.js'
  18. import pollsModule from './modules/polls.js'
  19. import postStatusModule from './modules/postStatus.js'
  20. import chatsModule from './modules/chats.js'
  21. import VueI18n from 'vue-i18n'
  22. import createPersistedState from './lib/persisted_state.js'
  23. import pushNotifications from './lib/push_notifications_plugin.js'
  24. import messages from './i18n/messages.js'
  25. import VueClickOutside from 'v-click-outside'
  26. import PortalVue from 'portal-vue'
  27. import VBodyScrollLock from './directives/body_scroll_lock'
  28. import { FontAwesomeIcon, FontAwesomeLayers } from '@fortawesome/vue-fontawesome'
  29. import afterStoreSetup from './boot/after_store.js'
  30. const currentLocale = (window.navigator.language || 'en').split('-')[0]
  31. Vue.use(Vuex)
  32. Vue.use(VueRouter)
  33. Vue.use(VueI18n)
  34. Vue.use(VueClickOutside)
  35. Vue.use(PortalVue)
  36. Vue.use(VBodyScrollLock)
  37. Vue.config.ignoredElements = ['pinch-zoom']
  38. Vue.component('FAIcon', FontAwesomeIcon)
  39. Vue.component('FALayers', FontAwesomeLayers)
  40. const i18n = new VueI18n({
  41. // By default, use the browser locale, we will update it if neccessary
  42. locale: 'en',
  43. fallbackLocale: 'en',
  44. messages: messages.default
  45. })
  46. messages.setLanguage(i18n, currentLocale)
  47. const persistedStateOptions = {
  48. paths: [
  49. 'config',
  50. 'users.lastLoginName',
  51. 'oauth'
  52. ]
  53. };
  54. (async () => {
  55. let storageError = false
  56. const plugins = [pushNotifications]
  57. try {
  58. const persistedState = await createPersistedState(persistedStateOptions)
  59. plugins.push(persistedState)
  60. } catch (e) {
  61. console.error(e)
  62. storageError = true
  63. }
  64. const store = new Vuex.Store({
  65. modules: {
  66. i18n: {
  67. getters: {
  68. i18n: () => i18n
  69. }
  70. },
  71. interface: interfaceModule,
  72. instance: instanceModule,
  73. statuses: statusesModule,
  74. users: usersModule,
  75. api: apiModule,
  76. config: configModule,
  77. shout: shoutModule,
  78. oauth: oauthModule,
  79. authFlow: authFlowModule,
  80. mediaViewer: mediaViewerModule,
  81. oauthTokens: oauthTokensModule,
  82. reports: reportsModule,
  83. polls: pollsModule,
  84. postStatus: postStatusModule,
  85. chats: chatsModule
  86. },
  87. plugins,
  88. strict: false // Socket modifies itself, let's ignore this for now.
  89. // strict: process.env.NODE_ENV !== 'production'
  90. })
  91. if (storageError) {
  92. store.dispatch('pushGlobalNotice', { messageKey: 'errors.storage_unavailable', level: 'error' })
  93. }
  94. afterStoreSetup({ store, i18n })
  95. })()
  96. // These are inlined by webpack's DefinePlugin
  97. /* eslint-disable */
  98. window.___pleromafe_mode = process.env
  99. window.___pleromafe_commit_hash = COMMIT_HASH
  100. window.___pleromafe_dev_overrides = DEV_OVERRIDES