refs #825 Add preferences to change cw and nfsw

This commit is contained in:
AkiraFukushima 2019-01-23 22:25:18 +09:00
parent 196a602862
commit d5f2db098a
5 changed files with 115 additions and 15 deletions

View File

@ -3,21 +3,28 @@ import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import General from '@/store/Preferences/General'
const state = {
general: {
sound: {
fav_rb: true,
toot: true
}
},
loading: false
const state = () => {
return {
general: {
sound: {
fav_rb: true,
toot: true
},
timeline: {
cw: false,
nfsw: false
}
},
loading: false
}
}
const Preferences = {
namespaced: true,
state: state,
actions: General.actions,
mutations: General.mutations
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: General.actions,
mutations: General.mutations
}
}
describe('Preferences/General', () => {
@ -29,7 +36,7 @@ describe('Preferences/General', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Preferences
Preferences: initStore()
}
})
})
@ -71,4 +78,21 @@ describe('Preferences/General', () => {
expect(store.state.Preferences.loading).toEqual(false)
})
})
describe('updateTimeline', () => {
beforeEach(() => {
ipcMain.once('update-preferences', (event, config) => {
event.sender.send('response-update-preferences', config)
})
})
it('should be updated', async () => {
await store.dispatch('Preferences/updateTimeline', {
cw: true,
nfsw: true
})
expect(store.state.Preferences.general.timeline.cw).toEqual(true)
expect(store.state.Preferences.general.timeline.nfsw).toEqual(true)
expect(store.state.Preferences.loading).toEqual(false)
})
})
})

View File

@ -116,6 +116,12 @@
"description": "Please set feedback sounds.",
"fav_rb": "When you favorite or boost the toot",
"toot": "When you post toot"
},
"timeline": {
"title": "Timeline",
"description": "Customize view in your timelines.",
"cw": "Always ignore contents warnings",
"nfsw": "Always ignore NFSW of medias"
}
},
"appearance": {

View File

@ -12,6 +12,10 @@ const Base = {
sound: {
fav_rb: true,
toot: true
},
timeline: {
cw: false,
nfsw: false
}
},
state: {

View File

@ -19,6 +19,24 @@
</el-switch>
</el-form-item>
</el-form>
<el-form class="timeline section" label-potision="right" label-width="250px" size="samll">
<h3>{{ $t('preferences.general.timeline.title') }}</h3>
<p class="description">{{ $t('preferences.general.timeline.description') }}</p>
<el-form-item for="cw" :label="$t('preferences.general.timeline.cw')">
<el-switch
id="cw"
v-model="timeline_cw"
active-color="#13ce66">
</el-switch>
</el-form-item>
<el-form-item for="nfsw" :label="$t('preferences.general.timeline.nfsw')">
<el-switch
id="nfsw"
v-model="timeline_nfsw"
active-color="#13ce66">
</el-switch>
</el-form-item>
</el-form>
</div>
</template>
@ -50,6 +68,26 @@ export default {
toot: value
})
}
},
timeline_cw: {
get () {
return this.$store.state.Preferences.General.general.timeline.cw
},
set (value) {
this.$store.dispatch('Preferences/General/updateTimeline', {
cw: value
})
}
},
timeline_nfsw: {
get () {
return this.$store.state.Preferences.General.general.timeline.nfsw
},
set (value) {
this.$store.dispatch('Preferences/General/updateTimeline', {
nfsw: value
})
}
}
},
created () {

View File

@ -7,6 +7,10 @@ const General = {
sound: {
fav_rb: true,
toot: true
},
timeline: {
cw: false,
nfsw: false
}
},
loading: false
@ -60,6 +64,30 @@ const General = {
resolve(conf)
})
})
},
updateTimeline ({ commit, state }, timeline) {
commit('changeLoading', true)
const newTimeline = Object.assign({}, state.general.timeline, timeline)
const newGeneral = Object.assign({}, state.general, {
timeline: newTimeline
})
const config = {
general: newGeneral
}
return new Promise((resolve, reject) => {
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
commit('changeLoading', false)
reject(err)
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateGeneral', conf.general)
commit('changeLoading', false)
resolve(conf)
})
ipcRenderer.send('update-preferences', config)
})
}
}
}