main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 listsModule from './modules/lists.js'
  8. import usersModule from './modules/users.js'
  9. import apiModule from './modules/api.js'
  10. import configModule from './modules/config.js'
  11. import serverSideConfigModule from './modules/serverSideConfig.js'
  12. import serverSideStorageModule from './modules/serverSideStorage.js'
  13. import shoutModule from './modules/shout.js'
  14. import oauthModule from './modules/oauth.js'
  15. import authFlowModule from './modules/auth_flow.js'
  16. import mediaViewerModule from './modules/media_viewer.js'
  17. import oauthTokensModule from './modules/oauth_tokens.js'
  18. import reportsModule from './modules/reports.js'
  19. import pollsModule from './modules/polls.js'
  20. import postStatusModule from './modules/postStatus.js'
  21. import editStatusModule from './modules/editStatus.js'
  22. import statusHistoryModule from './modules/statusHistory.js'
  23. import chatsModule from './modules/chats.js'
  24. import announcementsModule from './modules/announcements.js'
  25. import { createI18n } from 'vue-i18n'
  26. import createPersistedState from './lib/persisted_state.js'
  27. import pushNotifications from './lib/push_notifications_plugin.js'
  28. import messages from './i18n/messages.js'
  29. import afterStoreSetup from './boot/after_store.js'
  30. const currentLocale = (window.navigator.language || 'en').split('-')[0]
  31. const i18n = createI18n({
  32. // By default, use the browser locale, we will update it if neccessary
  33. locale: 'en',
  34. fallbackLocale: 'en',
  35. messages: messages.default
  36. })
  37. messages.setLanguage(i18n, currentLocale)
  38. const persistedStateOptions = {
  39. paths: [
  40. 'serverSideStorage.cache',
  41. 'config',
  42. 'users.lastLoginName',
  43. 'oauth'
  44. ]
  45. };
  46. (async () => {
  47. let storageError = false
  48. const plugins = [pushNotifications]
  49. try {
  50. const persistedState = await createPersistedState(persistedStateOptions)
  51. plugins.push(persistedState)
  52. } catch (e) {
  53. console.error(e)
  54. storageError = true
  55. }
  56. const store = createStore({
  57. modules: {
  58. i18n: {
  59. getters: {
  60. i18n: () => i18n.global
  61. }
  62. },
  63. interface: interfaceModule,
  64. instance: instanceModule,
  65. // TODO refactor users/statuses modules, they depend on each other
  66. users: usersModule,
  67. statuses: statusesModule,
  68. lists: listsModule,
  69. api: apiModule,
  70. config: configModule,
  71. serverSideConfig: serverSideConfigModule,
  72. serverSideStorage: serverSideStorageModule,
  73. shout: shoutModule,
  74. oauth: oauthModule,
  75. authFlow: authFlowModule,
  76. mediaViewer: mediaViewerModule,
  77. oauthTokens: oauthTokensModule,
  78. reports: reportsModule,
  79. polls: pollsModule,
  80. postStatus: postStatusModule,
  81. editStatus: editStatusModule,
  82. statusHistory: statusHistoryModule,
  83. chats: chatsModule,
  84. announcements: announcementsModule
  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