main.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.component('FAIcon', FontAwesomeIcon)
  38. Vue.component('FALayers', FontAwesomeLayers)
  39. const i18n = new VueI18n({
  40. // By default, use the browser locale, we will update it if neccessary
  41. locale: 'en',
  42. fallbackLocale: 'en',
  43. messages: messages.default
  44. })
  45. messages.setLanguage(i18n, currentLocale)
  46. const persistedStateOptions = {
  47. paths: [
  48. 'config',
  49. 'users.lastLoginName',
  50. 'oauth'
  51. ]
  52. };
  53. (async () => {
  54. let storageError = false
  55. const plugins = [pushNotifications]
  56. try {
  57. const persistedState = await createPersistedState(persistedStateOptions)
  58. plugins.push(persistedState)
  59. } catch (e) {
  60. console.error(e)
  61. storageError = true
  62. }
  63. const store = new Vuex.Store({
  64. modules: {
  65. i18n: {
  66. getters: {
  67. i18n: () => i18n
  68. }
  69. },
  70. interface: interfaceModule,
  71. instance: instanceModule,
  72. statuses: statusesModule,
  73. users: usersModule,
  74. api: apiModule,
  75. config: configModule,
  76. shout: shoutModule,
  77. oauth: oauthModule,
  78. authFlow: authFlowModule,
  79. mediaViewer: mediaViewerModule,
  80. oauthTokens: oauthTokensModule,
  81. reports: reportsModule,
  82. polls: pollsModule,
  83. postStatus: postStatusModule,
  84. chats: chatsModule
  85. },
  86. plugins,
  87. strict: false // Socket modifies itself, let's ignore this for now.
  88. // strict: process.env.NODE_ENV !== 'production'
  89. })
  90. if (storageError) {
  91. store.dispatch('pushGlobalNotice', { messageKey: 'errors.storage_unavailable', level: 'error' })
  92. }
  93. afterStoreSetup({ store, i18n })
  94. })()
  95. // These are inlined by webpack's DefinePlugin
  96. /* eslint-disable */
  97. window.___pleromafe_mode = process.env
  98. window.___pleromafe_commit_hash = COMMIT_HASH
  99. window.___pleromafe_dev_overrides = DEV_OVERRIDES