main.js 3.0 KB

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