2025-02-04 15:23:21 +02:00
|
|
|
/* global process */
|
2021-04-24 17:56:00 +03:00
|
|
|
import { createStore } from 'vuex'
|
2023-04-04 21:17:54 -06:00
|
|
|
import { createPinia } from 'pinia'
|
2016-10-26 19:03:55 +02:00
|
|
|
|
2020-01-23 23:53:48 +03:00
|
|
|
import 'custom-event-polyfill'
|
|
|
|
|
import './lib/event_target_polyfill.js'
|
|
|
|
|
|
2025-03-09 12:00:06 +04:00
|
|
|
// Polyfill for Array.prototype.toSorted (ES2023)
|
|
|
|
|
if (!Array.prototype.toSorted) {
|
|
|
|
|
Array.prototype.toSorted = function(compareFn) {
|
|
|
|
|
return [...this].sort(compareFn)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 20:21:03 -05:00
|
|
|
import vuexModules from './modules/index.js'
|
2016-10-26 19:03:55 +02:00
|
|
|
|
2021-04-24 17:56:00 +03:00
|
|
|
import { createI18n } from 'vue-i18n'
|
2016-11-28 17:37:47 +01:00
|
|
|
|
2025-03-11 18:48:55 -04:00
|
|
|
import createPersistedState, { piniaPersistPlugin } 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({
|
2018-08-25 13:12:33 +03:00
|
|
|
// By default, use the browser locale, we will update it if neccessary
|
2020-06-08 17:22:07 +02:00
|
|
|
locale: 'en',
|
2017-11-07 15:14:37 +01:00
|
|
|
fallbackLocale: 'en',
|
2020-06-08 17:22:07 +02:00
|
|
|
messages: messages.default
|
2017-11-07 15:14:37 +01:00
|
|
|
})
|
|
|
|
|
|
2023-04-13 00:03:36 +08:00
|
|
|
messages.setLanguage(i18n.global, currentLocale)
|
2020-06-08 17:22:07 +02:00
|
|
|
|
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 () => {
|
2024-09-18 03:37:59 +03:00
|
|
|
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'
|
2020-07-01 19:15:28 +03:00
|
|
|
}
|
2023-04-05 21:06:37 -06:00
|
|
|
|
2024-12-12 15:42:03 +02: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)
|
|
|
|
|
}
|
2020-07-01 19:15:28 +03:00
|
|
|
}
|
2023-04-04 21:17:54 -06:00
|
|
|
|
2020-07-01 19:15:28 +03:00
|
|
|
try {
|
2024-09-17 05:04:52 +03:00
|
|
|
let storageError
|
|
|
|
|
const plugins = [pushNotifications]
|
2025-01-30 18:08:05 +02:00
|
|
|
const pinia = createPinia()
|
2025-03-11 18:48:55 -04:00
|
|
|
pinia.use(piniaPersistPlugin())
|
|
|
|
|
|
2024-09-17 05:04:52 +03:00
|
|
|
try {
|
|
|
|
|
const persistedState = await createPersistedState(persistedStateOptions)
|
|
|
|
|
plugins.push(persistedState)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Storage error', e)
|
|
|
|
|
storageError = e
|
|
|
|
|
}
|
2025-02-25 00:13:19 +04:00
|
|
|
document.querySelector('#mascot').src = `/static/pleromatan_apology${isFox}_small.webp`
|
2024-09-17 05:04:52 +03:00
|
|
|
document.querySelector('#status').removeAttribute('class')
|
|
|
|
|
document.querySelector('#status').textContent = i18n.global.t('splash.loading')
|
2024-09-17 22:56:06 +03:00
|
|
|
document.querySelector('#splash-credit').textContent = i18n.global.t('update.art_by', { linkToArtist: 'pipivovott' })
|
2024-09-17 05:04:52 +03:00
|
|
|
const store = createStore({
|
2025-02-26 20:21:03 -05:00
|
|
|
modules: vuexModules,
|
2024-09-17 05:04:52 +03:00
|
|
|
plugins,
|
2025-01-06 00:24:02 +00:00
|
|
|
options: {
|
|
|
|
|
devtools: process.env.NODE_ENV !== 'production'
|
|
|
|
|
},
|
2024-09-17 05:04:52 +03:00
|
|
|
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.
|
2025-01-30 18:08:05 +02:00
|
|
|
return await afterStoreSetup({ pinia, store, storageError, i18n })
|
2024-09-17 05:04:52 +03:00
|
|
|
} catch (e) {
|
|
|
|
|
splashError(i18n, e)
|
2020-07-02 10:40:41 +03:00
|
|
|
}
|
2019-03-13 11:29:45 +01:00
|
|
|
})()
|
2018-12-11 18:45:25 +03: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
|