refs #579 Save fonts when user change fonts

This commit is contained in:
AkiraFukushima 2018-09-26 20:49:01 +09:00
parent 69021bc6d1
commit 7c1bb16147
3 changed files with 32 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import Theme from '../constants/theme'
import Language from '../constants/language'
import TimeFormat from '../constants/timeFormat'
import { LightTheme } from '../renderer/utils/theme'
import DefaultFonts from '../renderer/utils/fonts'
const Base = {
general: {
@ -34,7 +35,8 @@ const Base = {
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
timeFormat: TimeFormat.Absolute.value,
customThemeColor: LightTheme
customThemeColor: LightTheme,
font: DefaultFonts[0]
}
}

View File

@ -102,8 +102,7 @@ export default {
timeFormats: [
TimeFormat.Absolute,
TimeFormat.Relative
],
font: ''
]
}
},
computed: {
@ -137,6 +136,14 @@ export default {
},
customizeThemeColor () {
return this.theme === Theme.Custom.key
},
font: {
get () {
return this.$store.state.Preferences.Appearance.appearance.font
},
set (value) {
this.$store.dispatch('Preferences/Appearance/updateFont', value)
}
}
},
created () {

View File

@ -13,19 +13,11 @@ export default {
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
timeFormat: TimeFormat.Absolute.value,
customThemeColor: LightTheme
customThemeColor: LightTheme,
font: DefaultFonts[0]
},
fonts: []
},
getters: {
currentFont: state => {
const font = DefaultFonts.find(f => state.fonts.includes(f))
if (font) {
return font
}
return DefaultFonts[0]
}
},
mutations: {
updateAppearance (state, conf) {
state.appearance = conf
@ -58,7 +50,7 @@ export default {
})
ipcRenderer.once('response-list-fonts', (event, fonts) => {
ipcRenderer.removeAllListeners('error-list-fonts')
commit('updateFonts', fonts)
commit('updateFonts', [DefaultFonts[0]].concat(fonts))
resolve(fonts)
})
})
@ -148,6 +140,23 @@ export default {
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
})
},
updateFont ({ dispatch, state, commit }, value) {
const newAppearance = Object.assign({}, state.appearance, {
font: value
})
const config = {
appearance: newAppearance
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (event, err) => {
ipcRenderer.removeAllListeners('response-update-preferences')
})
ipcRenderer.once('response-update-preferences', (event, conf) => {
ipcRenderer.removeAllListeners('error-update-preferences')
commit('updateAppearance', conf.appearance)
dispatch('App/loadPreferences', null, { root: true })
})
}
}
}