2016-10-27 01:46:32 +11:00
|
|
|
import Vue from 'vue'
|
2016-10-27 04:03:55 +11:00
|
|
|
import VueRouter from 'vue-router'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
|
2018-09-10 02:36:13 +10:00
|
|
|
import interfaceModule from './modules/interface.js'
|
2018-09-10 04:21:23 +10:00
|
|
|
import instanceModule from './modules/instance.js'
|
2016-10-28 03:03:25 +11:00
|
|
|
import statusesModule from './modules/statuses.js'
|
|
|
|
import usersModule from './modules/users.js'
|
2016-11-27 04:57:08 +11:00
|
|
|
import apiModule from './modules/api.js'
|
2017-02-15 08:21:23 +11:00
|
|
|
import configModule from './modules/config.js'
|
2017-12-05 21:47:10 +11:00
|
|
|
import chatModule from './modules/chat.js'
|
2018-10-27 00:16:23 +11:00
|
|
|
import oauthModule from './modules/oauth.js'
|
2016-10-27 04:03:55 +11:00
|
|
|
|
2016-11-29 03:37:47 +11:00
|
|
|
import VueTimeago from 'vue-timeago'
|
2017-11-08 01:14:37 +11:00
|
|
|
import VueI18n from 'vue-i18n'
|
2016-11-29 03:37:47 +11:00
|
|
|
|
2017-02-21 04:25:19 +11:00
|
|
|
import createPersistedState from './lib/persisted_state.js'
|
2017-02-15 08:42:13 +11:00
|
|
|
|
2017-11-08 01:14:37 +11:00
|
|
|
import messages from './i18n/messages.js'
|
|
|
|
|
2018-01-27 01:11:34 +11:00
|
|
|
import VueChatScroll from 'vue-chat-scroll'
|
|
|
|
|
2018-10-27 00:16:23 +11:00
|
|
|
import afterStoreSetup from './boot/after_store.js'
|
|
|
|
|
2017-11-09 07:18:42 +11:00
|
|
|
const currentLocale = (window.navigator.language || 'en').split('-')[0]
|
|
|
|
|
2016-10-27 04:03:55 +11:00
|
|
|
Vue.use(Vuex)
|
|
|
|
Vue.use(VueRouter)
|
2016-11-29 03:37:47 +11:00
|
|
|
Vue.use(VueTimeago, {
|
2017-11-09 18:45:02 +11:00
|
|
|
locale: currentLocale === 'ja' ? 'ja' : 'en',
|
2016-11-29 03:37:47 +11:00
|
|
|
locales: {
|
2017-11-09 07:18:42 +11:00
|
|
|
'en': require('../static/timeago-en.json'),
|
|
|
|
'ja': require('../static/timeago-ja.json')
|
2016-11-29 03:37:47 +11:00
|
|
|
}
|
|
|
|
})
|
2017-11-08 01:14:37 +11:00
|
|
|
Vue.use(VueI18n)
|
2018-01-27 01:11:34 +11:00
|
|
|
Vue.use(VueChatScroll)
|
2016-10-27 04:03:55 +11:00
|
|
|
|
2017-11-08 01:14:37 +11:00
|
|
|
const i18n = new VueI18n({
|
2018-08-25 20:12:33 +10:00
|
|
|
// By default, use the browser locale, we will update it if neccessary
|
2017-11-08 01:23:00 +11:00
|
|
|
locale: currentLocale,
|
2017-11-08 01:14:37 +11:00
|
|
|
fallbackLocale: 'en',
|
|
|
|
messages
|
|
|
|
})
|
|
|
|
|
2018-10-27 00:16:23 +11:00
|
|
|
const persistedStateOptions = {
|
|
|
|
paths: [
|
|
|
|
'config',
|
|
|
|
'users.lastLoginName',
|
|
|
|
'oauth'
|
|
|
|
]
|
|
|
|
}
|
2018-12-13 22:04:09 +11:00
|
|
|
|
|
|
|
const registerPushNotifications = store => {
|
|
|
|
store.subscribe((mutation, state) => {
|
|
|
|
const vapidPublicKey = state.instance.vapidPublicKey
|
2018-12-20 17:17:59 +11:00
|
|
|
const webPushNotification = state.config.webPushNotifications
|
2018-12-13 22:04:09 +11:00
|
|
|
const permission = state.interface.notificationPermission === 'granted'
|
|
|
|
const user = state.users.currentUser
|
|
|
|
|
2018-12-20 17:17:59 +11:00
|
|
|
const isUserMutation = mutation.type === 'setCurrentUser'
|
|
|
|
const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey'
|
2018-12-13 22:04:09 +11:00
|
|
|
const isPermMutation = mutation.type === 'setNotificationPermission' && mutation.payload === 'granted'
|
2018-12-20 17:17:59 +11:00
|
|
|
const isUserConfigMutation = mutation.type === 'setOption' && mutation.payload.name === 'webPushNotifications'
|
|
|
|
|
|
|
|
if (isUserMutation || isVapidMutation || isPermMutation || isUserConfigMutation) {
|
|
|
|
if (user && vapidPublicKey && permission && webPushNotification) {
|
|
|
|
return store.dispatch('registerPushNotifications')
|
|
|
|
} else if (isUserConfigMutation && !webPushNotification) {
|
|
|
|
return store.dispatch('unregisterPushNotifications')
|
|
|
|
}
|
2018-12-13 22:04:09 +11:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-27 00:16:23 +11:00
|
|
|
createPersistedState(persistedStateOptions).then((persistedState) => {
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
interface: interfaceModule,
|
|
|
|
instance: instanceModule,
|
|
|
|
statuses: statusesModule,
|
|
|
|
users: usersModule,
|
|
|
|
api: apiModule,
|
|
|
|
config: configModule,
|
|
|
|
chat: chatModule,
|
2018-12-11 02:36:25 +11:00
|
|
|
oauth: oauthModule
|
2018-10-27 00:16:23 +11:00
|
|
|
},
|
2018-12-13 22:04:09 +11:00
|
|
|
plugins: [persistedState, registerPushNotifications],
|
2018-10-27 00:16:23 +11:00
|
|
|
strict: false // Socket modifies itself, let's ignore this for now.
|
|
|
|
// strict: process.env.NODE_ENV !== 'production'
|
2018-02-04 02:27:33 +11:00
|
|
|
})
|
|
|
|
|
2018-12-08 00:13:36 +11:00
|
|
|
afterStoreSetup({ store, i18n })
|
2018-10-27 00:16:23 +11:00
|
|
|
})
|
2018-12-12 02:45:25 +11: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
|