yandere_fe/src/components/settings/settings.js

111 lines
3.7 KiB
JavaScript
Raw Normal View History

/* eslint-env browser */
import { filter, trim } from 'lodash'
import TabSwitcher from '../tab_switcher/tab_switcher.js'
2017-02-16 13:25:29 -08:00
import StyleSwitcher from '../style_switcher/style_switcher.vue'
import InterfaceLanguageSwitcher from '../interface_language_switcher/interface_language_switcher.vue'
2019-03-10 18:06:51 -07:00
import { extractCommit } from '../../services/version/version.service'
import { instanceDefaultProperties, defaultState as configDefaultState } from '../../modules/config.js'
2019-03-10 18:06:51 -07:00
const pleromaFeCommitUrl = 'https://git.pleroma.social/pleroma/pleroma-fe/commit/'
const pleromaBeCommitUrl = 'https://git.pleroma.social/pleroma/pleroma/commit/'
2017-02-16 13:25:29 -08:00
const multiChoiceProperties = [
'postContentType',
'subjectLineBehavior'
]
2017-02-16 13:25:29 -08:00
const settings = {
2017-02-22 15:04:47 -08:00
data () {
2018-09-09 11:21:23 -07:00
const instance = this.$store.state.instance
2017-02-22 15:04:47 -08:00
return {
2019-01-26 07:45:03 -08:00
loopSilentAvailable:
// Firefox
Object.getOwnPropertyDescriptor(HTMLVideoElement.prototype, 'mozHasAudio') ||
// Chrome-likes
Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'webkitAudioDecodedByteCount') ||
// Future spec, still not supported in Nightly 63 as of 08/2018
Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'audioTracks'),
backendVersion: instance.backendVersion,
frontendVersion: instance.frontendVersion
2017-02-22 15:04:47 -08:00
}
},
2017-02-16 13:25:29 -08:00
components: {
2018-08-28 04:28:05 -07:00
TabSwitcher,
StyleSwitcher,
InterfaceLanguageSwitcher
2017-02-22 15:04:47 -08:00
},
2017-04-16 04:44:11 -07:00
computed: {
user () {
return this.$store.state.users.currentUser
2018-09-07 08:17:17 -07:00
},
currentSaveStateNotice () {
2018-09-09 09:36:13 -07:00
return this.$store.state.interface.settings.currentSaveStateNotice
},
postFormats () {
return this.$store.state.instance.postFormats || []
},
2019-03-10 18:06:51 -07:00
instanceSpecificPanelPresent () { return this.$store.state.instance.showInstanceSpecificPanel },
frontendVersionLink () {
2019-03-10 18:13:01 -07:00
return pleromaFeCommitUrl + this.frontendVersion
},
2019-03-10 18:06:51 -07:00
backendVersionLink () {
2019-03-10 18:13:01 -07:00
return pleromaBeCommitUrl + extractCommit(this.backendVersion)
},
// Getting localized values for instance-default properties
...instanceDefaultProperties
.filter(key => multiChoiceProperties.includes(key))
.map(key => [
key + 'DefaultValue',
function () {
return this.$store.getters.instanceDefaultConfig[key]
}
])
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
...instanceDefaultProperties
.filter(key => !multiChoiceProperties.includes(key))
.map(key => [
key + 'LocalizedValue',
function () {
return this.$t('settings.values.' + this.$store.getters.instanceDefaultConfig[key])
}
])
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
// Generating computed values for vuex properties
...Object.keys(configDefaultState)
.map(key => [key, {
get () { return this.$store.getters.mergedConfig[key] },
set (value) {
this.$store.dispatch('setOption', { name: key, value })
}
}])
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
// Special cases (need to transform values)
muteWordsString: {
get () { return this.$store.getters.mergedConfig.muteWords.join('\n') },
set (value) {
this.$store.dispatch('setOption', {
name: 'muteWords',
value: filter(value.split('\n'), (word) => trim(word).length > 0)
})
}
}
2017-04-16 04:44:11 -07:00
},
// Updating nested properties
2017-02-22 15:04:47 -08:00
watch: {
notificationVisibility: {
handler (value) {
this.$store.dispatch('setOption', {
name: 'notificationVisibility',
value: this.$store.getters.mergedConfig.notificationVisibility
})
},
deep: true
2017-02-22 15:38:05 -08:00
}
2017-02-16 13:25:29 -08:00
}
}
export default settings