2018-03-03 22:15:50 +00:00
|
|
|
import { observers } from './observers/observers'
|
|
|
|
import { computations } from './computations/computations'
|
|
|
|
import { mixins } from './mixins/mixins'
|
2018-01-28 21:09:39 +00:00
|
|
|
import { LocalStorageStore } from './LocalStorageStore'
|
2018-05-01 00:20:20 +00:00
|
|
|
import { observe } from 'svelte-extras'
|
2018-01-28 21:09:39 +00:00
|
|
|
|
2018-12-01 19:53:20 +00:00
|
|
|
const persistedState = {
|
|
|
|
autoplayGifs: false,
|
|
|
|
composeData: {},
|
2018-01-28 21:09:39 +00:00
|
|
|
currentInstance: null,
|
2018-12-01 19:53:20 +00:00
|
|
|
currentRegisteredInstanceName: undefined,
|
|
|
|
currentRegisteredInstance: undefined,
|
|
|
|
disableCustomScrollbars: false,
|
|
|
|
disableLongAriaLabels: false,
|
2018-12-03 05:12:58 +00:00
|
|
|
disableTapOnStatus: false,
|
2018-12-08 17:44:12 +00:00
|
|
|
largeInlineMedia: false,
|
2018-12-01 19:53:20 +00:00
|
|
|
instanceNameInSearch: '',
|
|
|
|
instanceThemes: {},
|
2018-01-28 21:09:39 +00:00
|
|
|
loggedInInstances: {},
|
|
|
|
loggedInInstancesInOrder: [],
|
2018-02-08 06:49:50 +00:00
|
|
|
markMediaAsSensitive: false,
|
2018-12-01 22:09:08 +00:00
|
|
|
neverMarkMediaAsSensitive: false,
|
2018-12-01 19:53:20 +00:00
|
|
|
omitEmojiInDisplayNames: undefined,
|
2018-02-08 17:15:25 +00:00
|
|
|
pinnedPages: {},
|
2018-12-01 19:53:20 +00:00
|
|
|
pushSubscription: null,
|
2018-12-08 17:42:38 +00:00
|
|
|
reduceMotion:
|
|
|
|
!process.browser ||
|
|
|
|
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
2018-12-01 19:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const nonPersistedState = {
|
2018-03-03 18:11:32 +00:00
|
|
|
customEmoji: {},
|
2018-12-01 19:53:20 +00:00
|
|
|
instanceInfos: {},
|
|
|
|
instanceLists: {},
|
2018-10-06 20:06:10 +00:00
|
|
|
online: !process.browser || navigator.onLine,
|
2018-12-01 19:53:20 +00:00
|
|
|
pinnedStatuses: {},
|
2018-12-08 17:42:38 +00:00
|
|
|
pushNotificationsSupport:
|
|
|
|
process.browser &&
|
|
|
|
('serviceWorker' in navigator &&
|
|
|
|
'PushManager' in window &&
|
|
|
|
'getKey' in window.PushSubscription.prototype),
|
2018-12-01 19:53:20 +00:00
|
|
|
queryInSearch: '',
|
|
|
|
repliesShown: {},
|
|
|
|
sensitivesShown: {},
|
|
|
|
spoilersShown: {},
|
|
|
|
statusModifications: {},
|
|
|
|
verifyCredentials: {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = Object.assign({}, persistedState, nonPersistedState)
|
|
|
|
const keysToStoreInLocalStorage = new Set(Object.keys(persistedState))
|
|
|
|
|
|
|
|
class PinaforeStore extends LocalStorageStore {
|
|
|
|
constructor (state) {
|
|
|
|
super(state, keysToStoreInLocalStorage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PinaforeStore.prototype.observe = observe
|
|
|
|
|
|
|
|
export const store = new PinaforeStore(state)
|
2018-01-28 21:09:39 +00:00
|
|
|
|
|
|
|
mixins(PinaforeStore)
|
|
|
|
computations(store)
|
2018-02-21 05:29:59 +00:00
|
|
|
observers(store)
|
2018-01-28 21:09:39 +00:00
|
|
|
|
2018-02-20 04:15:24 +00:00
|
|
|
if (process.browser && process.env.NODE_ENV !== 'production') {
|
|
|
|
window.store = store // for debugging
|
2018-02-20 04:28:31 +00:00
|
|
|
}
|
2018-05-26 20:51:41 +00:00
|
|
|
|
|
|
|
// needed for tests
|
|
|
|
if (process.browser) {
|
2018-08-30 04:42:57 +00:00
|
|
|
window.__forceOnline = online => store.set({ online })
|
2018-05-26 20:51:41 +00:00
|
|
|
}
|