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, cw: false,
nfsw: false, nfsw: false,
hideAllAttachments: false hideAllAttachments: false
},
other: {
launch: false
} }
}, },
loading: false loading: false
@ -31,7 +34,7 @@ const initStore = () => {
const app = { const app = {
namespaced: true, namespaced: true,
actions: { actions: {
loadPreferences (_) { loadPreferences(_) {
return true return true
} }
} }

View File

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

View File

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

View File

@ -473,7 +473,6 @@ ipcMain.on('change-auto-launch', (event: Event, enable: boolean) => {
launcher.disable() launcher.disable()
} }
event.sender.send('response-change-auto-launch', enable) 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 { Notify } from '~/src/types/notify'
import { Appearance } from '~/src/types/appearance' import { Appearance } from '~/src/types/appearance'
import { Language as LanguageSet } from '~/src/types/language' 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 = { const sound: Sound = {
fav_rb: true, fav_rb: true,
@ -24,9 +24,14 @@ const timeline: Timeline = {
hideAllAttachments: false hideAllAttachments: false
} }
const other: Other = {
launch: false
}
const general: General = { const general: General = {
sound: sound, sound: sound,
timeline: timeline timeline: timeline,
other: other
} }
const state: State = { const state: State = {

View File

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

View File

@ -3,7 +3,7 @@ import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store' import { RootState } from '@/store'
import { Sound } from '~/src/types/sound' import { Sound } from '~/src/types/sound'
import { Timeline } from '~/src/types/timeline' import { Timeline } from '~/src/types/timeline'
import { BaseConfig, General } from '~/src/types/preference' import { BaseConfig, General, Other } from '~/src/types/preference'
export type GeneralState = { export type GeneralState = {
general: General general: General
@ -20,6 +20,9 @@ const state = (): GeneralState => ({
cw: false, cw: false,
nfsw: false, nfsw: false,
hideAllAttachments: false hideAllAttachments: false
},
other: {
launch: false
} }
}, },
loading: false loading: false
@ -105,6 +108,32 @@ const actions: ActionTree<GeneralState, RootState> = {
}) })
ipcRenderer.send('update-preferences', config) 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 { Appearance } from '~/src/types/appearance'
import { Language } from '~/src/types/language' import { Language } from '~/src/types/language'
export type Other = {
launch: boolean
}
export type General = { export type General = {
sound: Sound sound: Sound
timeline: Timeline timeline: Timeline
other: Other
} }
export type State = { export type State = {