logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

main.js (5527B)


  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 notificationsModule from './modules/notifications.js'
  8. import listsModule from './modules/lists.js'
  9. import usersModule from './modules/users.js'
  10. import apiModule from './modules/api.js'
  11. import configModule from './modules/config.js'
  12. import profileConfigModule from './modules/profileConfig.js'
  13. import serverSideStorageModule from './modules/serverSideStorage.js'
  14. import adminSettingsModule from './modules/adminSettings.js'
  15. import shoutModule from './modules/shout.js'
  16. import oauthModule from './modules/oauth.js'
  17. import authFlowModule from './modules/auth_flow.js'
  18. import mediaViewerModule from './modules/media_viewer.js'
  19. import oauthTokensModule from './modules/oauth_tokens.js'
  20. import reportsModule from './modules/reports.js'
  21. import pollsModule from './modules/polls.js'
  22. import postStatusModule from './modules/postStatus.js'
  23. import editStatusModule from './modules/editStatus.js'
  24. import statusHistoryModule from './modules/statusHistory.js'
  25. import draftsModule from './modules/drafts.js'
  26. import chatsModule from './modules/chats.js'
  27. import announcementsModule from './modules/announcements.js'
  28. import bookmarkFoldersModule from './modules/bookmark_folders.js'
  29. import { createI18n } from 'vue-i18n'
  30. import createPersistedState from './lib/persisted_state.js'
  31. import pushNotifications from './lib/push_notifications_plugin.js'
  32. import messages from './i18n/messages.js'
  33. import afterStoreSetup from './boot/after_store.js'
  34. const currentLocale = (window.navigator.language || 'en').split('-')[0]
  35. const i18n = createI18n({
  36. // By default, use the browser locale, we will update it if neccessary
  37. locale: 'en',
  38. fallbackLocale: 'en',
  39. messages: messages.default
  40. })
  41. messages.setLanguage(i18n.global, currentLocale)
  42. const persistedStateOptions = {
  43. paths: [
  44. 'serverSideStorage.cache',
  45. 'config',
  46. 'users.lastLoginName',
  47. 'oauth'
  48. ]
  49. };
  50. (async () => {
  51. const isFox = Math.floor(Math.random() * 2) > 0 ? '_fox' : ''
  52. const splashError = (i18n, e) => {
  53. const throbber = document.querySelector('#throbber')
  54. throbber.addEventListener('animationend', () => {
  55. document.querySelector('#mascot').src = `/static/pleromatan_orz${isFox}.png`
  56. })
  57. throbber.classList.add('dead')
  58. document.querySelector('#status').textContent = i18n.global.t('splash.error')
  59. console.error('PleromaFE failed to initialize: ', e)
  60. document.querySelector('#statusError').textContent = e
  61. document.querySelector('#statusStack').textContent = e.stack
  62. document.querySelector('#statusError').style = 'display: block'
  63. document.querySelector('#statusStack').style = 'display: block'
  64. }
  65. window.splashError = e => splashError(i18n, e)
  66. window.splashUpdate = key => {
  67. if (document.querySelector('#status')) {
  68. document.querySelector('#status').textContent = i18n.global.t(key)
  69. }
  70. }
  71. try {
  72. let storageError
  73. const plugins = [pushNotifications]
  74. try {
  75. const persistedState = await createPersistedState(persistedStateOptions)
  76. plugins.push(persistedState)
  77. } catch (e) {
  78. console.error('Storage error', e)
  79. storageError = e
  80. }
  81. document.querySelector('#mascot').src = `/static/pleromatan_apology${isFox}.png`
  82. document.querySelector('#status').removeAttribute('class')
  83. document.querySelector('#status').textContent = i18n.global.t('splash.loading')
  84. document.querySelector('#splash-credit').textContent = i18n.global.t('update.art_by', { linkToArtist: 'pipivovott' })
  85. const store = createStore({
  86. modules: {
  87. i18n: {
  88. getters: {
  89. i18n: () => i18n.global
  90. }
  91. },
  92. interface: interfaceModule,
  93. instance: instanceModule,
  94. // TODO refactor users/statuses modules, they depend on each other
  95. users: usersModule,
  96. statuses: statusesModule,
  97. notifications: notificationsModule,
  98. lists: listsModule,
  99. api: apiModule,
  100. config: configModule,
  101. profileConfig: profileConfigModule,
  102. serverSideStorage: serverSideStorageModule,
  103. adminSettings: adminSettingsModule,
  104. shout: shoutModule,
  105. oauth: oauthModule,
  106. authFlow: authFlowModule,
  107. mediaViewer: mediaViewerModule,
  108. oauthTokens: oauthTokensModule,
  109. reports: reportsModule,
  110. polls: pollsModule,
  111. postStatus: postStatusModule,
  112. editStatus: editStatusModule,
  113. statusHistory: statusHistoryModule,
  114. drafts: draftsModule,
  115. chats: chatsModule,
  116. announcements: announcementsModule,
  117. bookmarkFolders: bookmarkFoldersModule
  118. },
  119. plugins,
  120. options: {
  121. devtools: process.env.NODE_ENV !== 'production'
  122. },
  123. strict: false // Socket modifies itself, let's ignore this for now.
  124. // strict: process.env.NODE_ENV !== 'production'
  125. })
  126. if (storageError) {
  127. store.dispatch('pushGlobalNotice', { messageKey: 'errors.storage_unavailable', level: 'error' })
  128. }
  129. return await afterStoreSetup({ store, i18n })
  130. } catch (e) {
  131. splashError(i18n, e)
  132. }
  133. })()
  134. // These are inlined by webpack's DefinePlugin
  135. /* eslint-disable */
  136. window.___pleromafe_mode = process.env
  137. window.___pleromafe_commit_hash = COMMIT_HASH
  138. window.___pleromafe_dev_overrides = DEV_OVERRIDES