diff options
Diffstat (limited to 'src/modules/instance.js')
| -rw-r--r-- | src/modules/instance.js | 99 |
1 files changed, 69 insertions, 30 deletions
diff --git a/src/modules/instance.js b/src/modules/instance.js index 625323b9..ec5f4e54 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -1,53 +1,60 @@ import { set } from 'vue' -import { setPreset } from '../services/style_setter/style_setter.js' +import { getPreset, applyTheme } from '../services/style_setter/style_setter.js' +import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js' +import apiService from '../services/api/api.service.js' import { instanceDefaultProperties } from './config.js' const defaultState = { - // Stuff from static/config.json and apiConfig + // Stuff from apiConfig name: 'Pleroma FE', registrationOpen: true, - safeDM: true, - textlimit: 5000, server: 'http://localhost:4040/', - theme: 'pleroma-dark', - background: '/static/aurora_borealis.jpg', - logo: '/static/logo.png', - logoMask: true, - logoMargin: '.2em', - redirectRootNoLogin: '/main/all', - redirectRootLogin: '/main/friends', - showInstanceSpecificPanel: false, + textlimit: 5000, + themeData: undefined, + vapidPublicKey: undefined, + + // Stuff from static/config.json alwaysShowSubjectInput: true, - hideMutedPosts: false, + background: '/static/aurora_borealis.jpg', collapseMessageWithSubject: false, - hidePostStats: false, - hideUserStats: false, - hideFilteredStatuses: false, disableChat: false, - scopeCopy: true, - subjectLineBehavior: 'email', - postContentType: 'text/plain', + greentext: false, + hideFilteredStatuses: false, + hideMutedPosts: false, + hidePostStats: false, hideSitename: false, + hideUserStats: false, + loginMethod: 'password', + logo: '/static/logo.png', + logoMargin: '.2em', + logoMask: true, + minimalScopesMode: false, nsfwCensorImage: undefined, - vapidPublicKey: undefined, - noAttachmentLinks: false, + postContentType: 'text/plain', + redirectRootLogin: '/main/friends', + redirectRootNoLogin: '/main/all', + scopeCopy: true, showFeaturesPanel: true, - minimalScopesMode: false, - greentext: false, + showInstanceSpecificPanel: false, + sidebarRight: false, + subjectLineBehavior: 'email', + theme: 'pleroma-dark', // Nasty stuff - pleromaBackend: true, - emoji: [], - emojiFetched: false, customEmoji: [], customEmojiFetched: false, - restrictedNicknames: [], + emoji: [], + emojiFetched: false, + pleromaBackend: true, postFormats: [], + restrictedNicknames: [], + safeDM: true, + knownDomains: [], // Feature-set, apparently, not everything here is reported... - mediaProxyAvailable: false, chatAvailable: false, gopherAvailable: false, + mediaProxyAvailable: false, suggestionsEnabled: false, suggestionsWeb: '', @@ -75,6 +82,9 @@ const instance = { if (typeof value !== 'undefined') { set(state, name, value) } + }, + setKnownDomains (state, domains) { + state.knownDomains = domains } }, getters: { @@ -96,6 +106,9 @@ const instance = { dispatch('initializeSocket') } break + case 'theme': + dispatch('setTheme', value) + break } }, async getStaticEmoji ({ commit }) { @@ -147,9 +160,23 @@ const instance = { } }, - setTheme ({ commit }, themeName) { + setTheme ({ commit, rootState }, themeName) { commit('setInstanceOption', { name: 'theme', value: themeName }) - return setPreset(themeName, commit) + getPreset(themeName) + .then(themeData => { + commit('setInstanceOption', { name: 'themeData', value: themeData }) + // No need to apply theme if there's user theme already + const { customTheme } = rootState.config + if (customTheme) return + + // New theme presets don't have 'theme' property, they use 'source' + const themeSource = themeData.source + if (!themeData.theme || (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION)) { + applyTheme(themeSource) + } else { + applyTheme(themeData.theme) + } + }) }, fetchEmoji ({ dispatch, state }) { if (!state.customEmojiFetched) { @@ -160,6 +187,18 @@ const instance = { state.emojiFetched = true dispatch('getStaticEmoji') } + }, + + async getKnownDomains ({ commit, rootState }) { + try { + const result = await apiService.fetchKnownDomains({ + credentials: rootState.users.currentUser.credentials + }) + commit('setKnownDomains', result) + } catch (e) { + console.warn("Can't load known domains") + console.warn(e) + } } } } |
