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 (3302B)


  1. /* global process */
  2. import { createStore } from 'vuex'
  3. import { createPinia } from 'pinia'
  4. import 'custom-event-polyfill'
  5. import './lib/event_target_polyfill.js'
  6. import vuexModules from './modules/index.js'
  7. import { createI18n } from 'vue-i18n'
  8. import createPersistedState from './lib/persisted_state.js'
  9. import pushNotifications from './lib/push_notifications_plugin.js'
  10. import messages from './i18n/messages.js'
  11. import afterStoreSetup from './boot/after_store.js'
  12. const currentLocale = (window.navigator.language || 'en').split('-')[0]
  13. const i18n = createI18n({
  14. // By default, use the browser locale, we will update it if neccessary
  15. locale: 'en',
  16. fallbackLocale: 'en',
  17. messages: messages.default
  18. })
  19. messages.setLanguage(i18n.global, currentLocale)
  20. const persistedStateOptions = {
  21. paths: [
  22. 'serverSideStorage.cache',
  23. 'config',
  24. 'users.lastLoginName',
  25. 'oauth'
  26. ]
  27. };
  28. (async () => {
  29. const isFox = Math.floor(Math.random() * 2) > 0 ? '_fox' : ''
  30. const splashError = (i18n, e) => {
  31. const throbber = document.querySelector('#throbber')
  32. throbber.addEventListener('animationend', () => {
  33. document.querySelector('#mascot').src = `/static/pleromatan_orz${isFox}.png`
  34. })
  35. throbber.classList.add('dead')
  36. document.querySelector('#status').textContent = i18n.global.t('splash.error')
  37. console.error('PleromaFE failed to initialize: ', e)
  38. document.querySelector('#statusError').textContent = e
  39. document.querySelector('#statusStack').textContent = e.stack
  40. document.querySelector('#statusError').style = 'display: block'
  41. document.querySelector('#statusStack').style = 'display: block'
  42. }
  43. window.splashError = e => splashError(i18n, e)
  44. window.splashUpdate = key => {
  45. if (document.querySelector('#status')) {
  46. document.querySelector('#status').textContent = i18n.global.t(key)
  47. }
  48. }
  49. try {
  50. let storageError
  51. const plugins = [pushNotifications]
  52. const pinia = createPinia()
  53. try {
  54. const persistedState = await createPersistedState(persistedStateOptions)
  55. plugins.push(persistedState)
  56. } catch (e) {
  57. console.error('Storage error', e)
  58. storageError = e
  59. }
  60. document.querySelector('#mascot').src = `/static/pleromatan_apology${isFox}_small.webp`
  61. document.querySelector('#status').removeAttribute('class')
  62. document.querySelector('#status').textContent = i18n.global.t('splash.loading')
  63. document.querySelector('#splash-credit').textContent = i18n.global.t('update.art_by', { linkToArtist: 'pipivovott' })
  64. const store = createStore({
  65. modules: vuexModules,
  66. plugins,
  67. options: {
  68. devtools: process.env.NODE_ENV !== 'production'
  69. },
  70. strict: false // Socket modifies itself, let's ignore this for now.
  71. // strict: process.env.NODE_ENV !== 'production'
  72. })
  73. window.vuex = store
  74. // Temporarily passing pinia and vuex stores along with storageError result until migration is fully complete.
  75. return await afterStoreSetup({ pinia, store, storageError, i18n })
  76. } catch (e) {
  77. splashError(i18n, e)
  78. }
  79. })()
  80. // These are inlined by webpack's DefinePlugin
  81. /* eslint-disable */
  82. window.___pleromafe_mode = process.env
  83. window.___pleromafe_commit_hash = COMMIT_HASH
  84. window.___pleromafe_dev_overrides = DEV_OVERRIDES