pleroma-fe/src/main.js

131 lines
4.6 KiB
JavaScript
Raw Normal View History

2025-02-04 15:23:21 +02:00
/* global process */
import { createStore } from 'vuex'
2023-04-04 21:17:54 -06:00
import { createPinia } from 'pinia'
2016-10-26 19:03:55 +02:00
import 'custom-event-polyfill'
import './lib/event_target_polyfill.js'
2018-09-09 21:21:23 +03:00
import instanceModule from './modules/instance.js'
2016-10-27 18:03:25 +02:00
import statusesModule from './modules/statuses.js'
import notificationsModule from './modules/notifications.js'
2016-10-27 18:03:25 +02:00
import usersModule from './modules/users.js'
import apiModule from './modules/api.js'
import configModule from './modules/config.js'
import profileConfigModule from './modules/profileConfig.js'
2022-08-04 01:56:52 +03:00
import serverSideStorageModule from './modules/serverSideStorage.js'
import adminSettingsModule from './modules/adminSettings.js'
2018-10-26 15:16:23 +02:00
import oauthModule from './modules/oauth.js'
import authFlowModule from './modules/auth_flow.js'
import oauthTokensModule from './modules/oauth_tokens.js'
2023-03-10 11:20:06 -05:00
import draftsModule from './modules/drafts.js'
2020-05-07 16:10:53 +03:00
import chatsModule from './modules/chats.js'
import bookmarkFoldersModule from './modules/bookmark_folders.js'
2016-10-26 19:03:55 +02:00
import { createI18n } from 'vue-i18n'
import createPersistedState from './lib/persisted_state.js'
2018-12-25 20:43:18 +07:00
import pushNotifications from './lib/push_notifications_plugin.js'
2017-02-14 22:42:13 +01:00
2017-11-07 15:14:37 +01:00
import messages from './i18n/messages.js'
2018-10-26 15:16:23 +02:00
import afterStoreSetup from './boot/after_store.js'
2017-11-08 22:18:42 +02:00
const currentLocale = (window.navigator.language || 'en').split('-')[0]
2022-03-16 22:02:44 +02:00
const i18n = createI18n({
// By default, use the browser locale, we will update it if neccessary
locale: 'en',
2017-11-07 15:14:37 +01:00
fallbackLocale: 'en',
messages: messages.default
2017-11-07 15:14:37 +01:00
})
2023-04-13 00:03:36 +08:00
messages.setLanguage(i18n.global, currentLocale)
2018-10-26 15:16:23 +02:00
const persistedStateOptions = {
paths: [
2022-08-04 01:56:52 +03:00
'serverSideStorage.cache',
2018-10-26 15:16:23 +02:00
'config',
'users.lastLoginName',
'oauth'
]
2019-03-13 11:29:45 +01:00
};
2018-12-13 18:04:09 +07:00
2019-03-13 11:29:45 +01:00
(async () => {
const isFox = Math.floor(Math.random() * 2) > 0 ? '_fox' : ''
const splashError = (i18n, e) => {
const throbber = document.querySelector('#throbber')
throbber.addEventListener('animationend', () => {
document.querySelector('#mascot').src = `/static/pleromatan_orz${isFox}.png`
})
throbber.classList.add('dead')
document.querySelector('#status').textContent = i18n.global.t('splash.error')
console.error('PleromaFE failed to initialize: ', e)
2024-12-12 15:58:18 +02:00
document.querySelector('#statusError').textContent = e
document.querySelector('#statusStack').textContent = e.stack
document.querySelector('#statusError').style = 'display: block'
document.querySelector('#statusStack').style = 'display: block'
}
2023-04-05 21:06:37 -06:00
window.splashError = e => splashError(i18n, e)
window.splashUpdate = key => {
2024-12-18 16:29:38 +02:00
if (document.querySelector('#status')) {
document.querySelector('#status').textContent = i18n.global.t(key)
}
}
2023-04-04 21:17:54 -06:00
try {
let storageError
const plugins = [pushNotifications]
const pinia = createPinia()
try {
const persistedState = await createPersistedState(persistedStateOptions)
plugins.push(persistedState)
} catch (e) {
console.error('Storage error', e)
storageError = e
}
document.querySelector('#mascot').src = `/static/pleromatan_apology${isFox}.png`
document.querySelector('#status').removeAttribute('class')
document.querySelector('#status').textContent = i18n.global.t('splash.loading')
document.querySelector('#splash-credit').textContent = i18n.global.t('update.art_by', { linkToArtist: 'pipivovott' })
const store = createStore({
modules: {
instance: instanceModule,
// TODO refactor users/statuses modules, they depend on each other
users: usersModule,
statuses: statusesModule,
notifications: notificationsModule,
api: apiModule,
config: configModule,
profileConfig: profileConfigModule,
serverSideStorage: serverSideStorageModule,
adminSettings: adminSettingsModule,
oauth: oauthModule,
authFlow: authFlowModule,
oauthTokens: oauthTokensModule,
drafts: draftsModule,
chats: chatsModule,
bookmarkFolders: bookmarkFoldersModule
2019-03-31 21:59:18 -04:00
},
plugins,
options: {
devtools: process.env.NODE_ENV !== 'production'
},
strict: false // Socket modifies itself, let's ignore this for now.
// strict: process.env.NODE_ENV !== 'production'
})
2025-01-30 21:56:07 +02:00
window.vuex = store
// Temporarily passing pinia and vuex stores along with storageError result until migration is fully complete.
return await afterStoreSetup({ pinia, store, storageError, i18n })
} catch (e) {
splashError(i18n, e)
}
2019-03-13 11:29:45 +01:00
})()
// These are inlined by webpack's DefinePlugin
/* eslint-disable */
window.___pleromafe_mode = process.env
window.___pleromafe_commit_hash = COMMIT_HASH
window.___pleromafe_dev_overrides = DEV_OVERRIDES