refs #948 Add other options in prefereces

This commit is contained in:
AkiraFukushima 2019-09-23 22:54:37 +09:00
parent b990229cc1
commit 337012c2ef
8 changed files with 111 additions and 68 deletions

View File

@ -14,6 +14,9 @@ const state = (): GeneralState => {
cw: false,
nfsw: false,
hideAllAttachments: false
},
other: {
launch: false
}
},
loading: false
@ -31,7 +34,7 @@ const initStore = () => {
const app = {
namespaced: true,
actions: {
loadPreferences (_) {
loadPreferences(_) {
return true
}
}

View File

@ -13,6 +13,9 @@ describe('Preferences/General', () => {
cw: false,
nfsw: false,
hideAllAttachments: false
},
other: {
launch: false
}
},
loading: false

View File

@ -127,6 +127,10 @@
"cw": "Always ignore contents warnings",
"nfsw": "Always ignore NFSW of medias",
"hideAllAttachments": "Hide all medias"
},
"other": {
"title": "Other options",
"launch": "Launch app on login"
}
},
"appearance": {

View File

@ -473,7 +473,6 @@ ipcMain.on('change-auto-launch', (event: Event, enable: boolean) => {
launcher.disable()
}
event.sender.send('response-change-auto-launch', enable)
return
})
})

View File

@ -11,7 +11,7 @@ import { Timeline } from '~/src/types/timeline'
import { Notify } from '~/src/types/notify'
import { Appearance } from '~/src/types/appearance'
import { Language as LanguageSet } from '~/src/types/language'
import { General, State, Notification, BaseConfig } from '~/src/types/preference'
import { General, State, Notification, BaseConfig, Other } from '~/src/types/preference'
const sound: Sound = {
fav_rb: true,
@ -24,9 +24,14 @@ const timeline: Timeline = {
hideAllAttachments: false
}
const other: Other = {
launch: false
}
const general: General = {
sound: sound,
timeline: timeline
timeline: timeline,
other: other
}
const state: State = {

View File

@ -1,50 +1,36 @@
<template>
<div id="general" v-loading="loading">
<h2>{{ $t('preferences.general.title') }}</h2>
<el-form class="sounds section" label-position="right" label-width="250px" size="small">
<h3>{{ $t('preferences.general.sounds.title') }}</h3>
<p class="description">{{ $t('preferences.general.sounds.description') }}</p>
<el-form-item for="fav_rb" :label="$t('preferences.general.sounds.fav_rb')">
<el-switch
id="fav_rb"
v-model="sound_fav_rb"
active-color="#13ce66">
</el-switch>
</el-form-item>
<el-form-item for="sound_toot" :label="$t('preferences.general.sounds.toot')">
<el-switch
id="sound_toot"
v-model="sound_toot"
active-color="#13ce66">
</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-item for="hideAllAttachments" :label="$t('preferences.general.timeline.hideAllAttachments')">
<el-switch
id="hideAllAttachments"
v-model="timeline_hide_attachments"
active-color="#13ce66">
</el-switch>
</el-form-item>
</el-form>
</div>
<div id="general" v-loading="loading">
<h2>{{ $t('preferences.general.title') }}</h2>
<el-form class="sounds section" label-position="right" label-width="250px" size="small">
<h3>{{ $t('preferences.general.sounds.title') }}</h3>
<p class="description">{{ $t('preferences.general.sounds.description') }}</p>
<el-form-item for="fav_rb" :label="$t('preferences.general.sounds.fav_rb')">
<el-switch id="fav_rb" v-model="sound_fav_rb" active-color="#13ce66"> </el-switch>
</el-form-item>
<el-form-item for="sound_toot" :label="$t('preferences.general.sounds.toot')">
<el-switch id="sound_toot" v-model="sound_toot" active-color="#13ce66"> </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-item for="hideAllAttachments" :label="$t('preferences.general.timeline.hideAllAttachments')">
<el-switch id="hideAllAttachments" v-model="timeline_hide_attachments" active-color="#13ce66"> </el-switch>
</el-form-item>
</el-form>
<el-form class="other section" label-position="right" label-width="250px" size="small">
<h3>{{ $t('preferences.general.other.title') }}</h3>
<el-form-item for="launch" :label="$t('preferences.general.other.launch')">
<el-switch id="launch" v-model="other_launch" active-color="#13ce66"> </el-switch>
</el-form-item>
</el-form>
</div>
</template>
<script>
@ -57,64 +43,73 @@ export default {
loading: state => state.Preferences.General.loading
}),
sound_fav_rb: {
get () {
get() {
return this.$store.state.Preferences.General.general.sound.fav_rb
},
set (value) {
set(value) {
this.$store.dispatch('Preferences/General/updateSound', {
fav_rb: value
})
}
},
sound_toot: {
get () {
get() {
return this.$store.state.Preferences.General.general.sound.toot
},
set (value) {
set(value) {
this.$store.dispatch('Preferences/General/updateSound', {
toot: value
})
}
},
timeline_cw: {
get () {
get() {
return this.$store.state.Preferences.General.general.timeline.cw
},
set (value) {
set(value) {
this.$store.dispatch('Preferences/General/updateTimeline', {
cw: value
})
}
},
timeline_nfsw: {
get () {
get() {
return this.$store.state.Preferences.General.general.timeline.nfsw
},
set (value) {
set(value) {
this.$store.dispatch('Preferences/General/updateTimeline', {
nfsw: value
})
}
},
timeline_hide_attachments: {
get () {
get() {
return this.$store.state.Preferences.General.general.timeline.hideAllAttachments
},
set (value) {
set(value) {
this.$store.dispatch('Preferences/General/updateTimeline', {
hideAllAttachments: value
})
}
},
other_launch: {
get() {
return this.$store.state.Preferences.General.general.other.launch
},
set(value) {
this.$store.dispatch('Preferences/General/updateOther', {
launch: value
})
}
}
},
created () {
this.$store.dispatch('Preferences/General/loadGeneral')
.catch(() => {
this.$message({
message: this.$t('message.preferences_load_error'),
type: 'error'
})
created() {
this.$store.dispatch('Preferences/General/loadGeneral').catch(() => {
this.$message({
message: this.$t('message.preferences_load_error'),
type: 'error'
})
})
}
}
</script>

View File

@ -3,7 +3,7 @@ import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
import { Sound } from '~/src/types/sound'
import { Timeline } from '~/src/types/timeline'
import { BaseConfig, General } from '~/src/types/preference'
import { BaseConfig, General, Other } from '~/src/types/preference'
export type GeneralState = {
general: General
@ -20,6 +20,9 @@ const state = (): GeneralState => ({
cw: false,
nfsw: false,
hideAllAttachments: false
},
other: {
launch: false
}
},
loading: false
@ -105,6 +108,32 @@ const actions: ActionTree<GeneralState, RootState> = {
})
ipcRenderer.send('update-preferences', config)
})
},
updateOther: ({ commit, state, dispatch }, other: {}) => {
commit(MUTATION_TYPES.CHANGE_LOADING, true)
const newOther: Other = Object.assign({}, state.general.other, other)
const newGeneral: General = Object.assign({}, state.general, {
other: newOther
})
const config = {
general: newGeneral
}
return new Promise((resolve, reject) => {
// TODO: call change settings
ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences')
commit(MUTATION_TYPES.CHANGE_LOADING, false)
reject(err)
})
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
commit(MUTATION_TYPES.CHANGE_LOADING, false)
dispatch('App/loadPreferences', null, { root: true })
resolve(conf)
})
ipcRenderer.send('update-preferences', config)
})
}
}

View File

@ -4,9 +4,14 @@ import { Notify } from '~/src/types/notify'
import { Appearance } from '~/src/types/appearance'
import { Language } from '~/src/types/language'
export type Other = {
launch: boolean
}
export type General = {
sound: Sound
timeline: Timeline
other: Other
}
export type State = {