Merge pull request #936 from h3poteto/refactor/any
refactor: Replace any type and organize preference
This commit is contained in:
commit
824ac51cd8
|
@ -11,28 +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'
|
||||||
type General = {
|
|
||||||
sound: Sound
|
|
||||||
timeline: Timeline
|
|
||||||
}
|
|
||||||
|
|
||||||
type State = {
|
|
||||||
collapse: boolean
|
|
||||||
hideGlobalHeader: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
type Notification = {
|
|
||||||
notify: Notify
|
|
||||||
}
|
|
||||||
|
|
||||||
type BaseConfig = {
|
|
||||||
general: General
|
|
||||||
state: State
|
|
||||||
language: LanguageSet
|
|
||||||
notification: Notification
|
|
||||||
appearance: Appearance
|
|
||||||
}
|
|
||||||
|
|
||||||
const sound: Sound = {
|
const sound: Sound = {
|
||||||
fav_rb: true,
|
fav_rb: true,
|
||||||
|
|
|
@ -9,6 +9,8 @@ import Language from '~/src/constants/language'
|
||||||
import DefaultFonts from '@/utils/fonts'
|
import DefaultFonts from '@/utils/fonts'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
import { Notify } from '~/src/types/notify'
|
import { Notify } from '~/src/types/notify'
|
||||||
|
import { BaseConfig } from '~/src/types/preference'
|
||||||
|
import { Appearance } from '~src/types/appearance'
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
theme: ThemeColorType
|
theme: ThemeColorType
|
||||||
|
@ -58,7 +60,7 @@ const MUTATION_TYPES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations: MutationTree<AppState> = {
|
const mutations: MutationTree<AppState> = {
|
||||||
[MUTATION_TYPES.UPDATE_THEME]: (state: AppState, themeColorList: any) => {
|
[MUTATION_TYPES.UPDATE_THEME]: (state: AppState, themeColorList: ThemeColorType) => {
|
||||||
state.theme = themeColorList
|
state.theme = themeColorList
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.UPDATE_FONT_SIZE]: (state: AppState, value: number) => {
|
[MUTATION_TYPES.UPDATE_FONT_SIZE]: (state: AppState, value: number) => {
|
||||||
|
@ -110,25 +112,24 @@ const actions: ActionTree<AppState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-get-preferences')
|
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
// TODO: any
|
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
|
||||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||||
dispatch('updateTheme', conf.appearance as any)
|
dispatch('updateTheme', conf.appearance)
|
||||||
commit(MUTATION_TYPES.UPDATE_DISPLAY_NAME_STYLE, conf.appearance.displayNameStyle as number)
|
commit(MUTATION_TYPES.UPDATE_DISPLAY_NAME_STYLE, conf.appearance.displayNameStyle)
|
||||||
commit(MUTATION_TYPES.UPDATE_FONT_SIZE, conf.appearance.fontSize as number)
|
commit(MUTATION_TYPES.UPDATE_FONT_SIZE, conf.appearance.fontSize)
|
||||||
commit(MUTATION_TYPES.UPDATE_NOTIFY, conf.notification.notify as Notify)
|
commit(MUTATION_TYPES.UPDATE_NOTIFY, conf.notification.notify)
|
||||||
commit(MUTATION_TYPES.UPDATE_TIME_FORMAT, conf.appearance.timeFormat as number)
|
commit(MUTATION_TYPES.UPDATE_TIME_FORMAT, conf.appearance.timeFormat)
|
||||||
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language.language as string)
|
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language.language)
|
||||||
commit(MUTATION_TYPES.UPDATE_TOOT_PADDING, conf.appearance.tootPadding as number)
|
commit(MUTATION_TYPES.UPDATE_TOOT_PADDING, conf.appearance.tootPadding)
|
||||||
commit(MUTATION_TYPES.ADD_FONT, conf.appearance.font as string)
|
commit(MUTATION_TYPES.ADD_FONT, conf.appearance.font)
|
||||||
commit(MUTATION_TYPES.UPDATE_IGNORE_CW, conf.general.timeline.cw as boolean)
|
commit(MUTATION_TYPES.UPDATE_IGNORE_CW, conf.general.timeline.cw)
|
||||||
commit(MUTATION_TYPES.UPDATE_IGNORE_NFSW, conf.general.timeline.nfsw as boolean)
|
commit(MUTATION_TYPES.UPDATE_IGNORE_NFSW, conf.general.timeline.nfsw)
|
||||||
commit(MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS, conf.general.timeline.hideAllAttachments as boolean)
|
commit(MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS, conf.general.timeline.hideAllAttachments)
|
||||||
resolve(conf)
|
resolve(conf)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
updateTheme: ({ commit }, appearance: any) => {
|
updateTheme: ({ commit }, appearance: Appearance) => {
|
||||||
const themeKey: string = appearance.theme
|
const themeKey: string = appearance.theme
|
||||||
switch (themeKey) {
|
switch (themeKey) {
|
||||||
case Theme.Light.key:
|
case Theme.Light.key:
|
||||||
|
|
|
@ -7,6 +7,7 @@ import DefaultFonts from '@/utils/fonts'
|
||||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
import { Appearance } from '~/src/types/appearance'
|
import { Appearance } from '~/src/types/appearance'
|
||||||
|
import { BaseConfig } from '~/src/types/preference'
|
||||||
|
|
||||||
export type AppearanceState = {
|
export type AppearanceState = {
|
||||||
appearance: Appearance
|
appearance: Appearance
|
||||||
|
@ -48,9 +49,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-get-preferences')
|
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
resolve(conf)
|
resolve(conf)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -82,9 +83,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
resolve(conf.appearance)
|
resolve(conf.appearance)
|
||||||
})
|
})
|
||||||
|
@ -103,9 +104,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
resolve(conf.appearance)
|
resolve(conf.appearance)
|
||||||
})
|
})
|
||||||
|
@ -124,10 +125,10 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
resolve(conf.appearance)
|
resolve(conf.appearance)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -145,10 +146,10 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
resolve(conf.appearance)
|
resolve(conf.appearance)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -167,9 +168,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
resolve(conf.appearance)
|
resolve(conf.appearance)
|
||||||
})
|
})
|
||||||
|
@ -188,9 +189,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
resolve(conf.appearance)
|
resolve(conf.appearance)
|
||||||
})
|
})
|
||||||
|
@ -209,9 +210,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
resolve(conf.appearance)
|
resolve(conf.appearance)
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,13 +3,10 @@ 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'
|
||||||
|
|
||||||
interface GeneralSet {
|
|
||||||
sound: Sound,
|
|
||||||
timeline: Timeline
|
|
||||||
}
|
|
||||||
export interface GeneralState {
|
export interface GeneralState {
|
||||||
general: GeneralSet,
|
general: General
|
||||||
loading: boolean
|
loading: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +31,7 @@ export const MUTATION_TYPES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations: MutationTree<GeneralState> = {
|
const mutations: MutationTree<GeneralState> = {
|
||||||
[MUTATION_TYPES.UPDATE_GENERAL]: (state, conf: GeneralSet) => {
|
[MUTATION_TYPES.UPDATE_GENERAL]: (state, conf: General) => {
|
||||||
state.general = conf
|
state.general = conf
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.CHANGE_LOADING]: (state, value: boolean) => {
|
[MUTATION_TYPES.CHANGE_LOADING]: (state, value: boolean) => {
|
||||||
|
@ -52,9 +49,9 @@ const actions: ActionTree<GeneralState, RootState> = {
|
||||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as GeneralSet)
|
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||||
resolve(conf)
|
resolve(conf)
|
||||||
})
|
})
|
||||||
|
@ -63,7 +60,7 @@ const actions: ActionTree<GeneralState, RootState> = {
|
||||||
updateSound: ({ commit, state }, sound: object) => {
|
updateSound: ({ commit, state }, sound: object) => {
|
||||||
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
||||||
const newSound: Sound = Object.assign({}, state.general.sound, sound)
|
const newSound: Sound = Object.assign({}, state.general.sound, sound)
|
||||||
const newGeneral: GeneralSet = Object.assign({}, state.general, {
|
const newGeneral: General = Object.assign({}, state.general, {
|
||||||
sound: newSound
|
sound: newSound
|
||||||
})
|
})
|
||||||
const config = {
|
const config = {
|
||||||
|
@ -76,9 +73,9 @@ const actions: ActionTree<GeneralState, RootState> = {
|
||||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as GeneralSet)
|
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||||
resolve(conf)
|
resolve(conf)
|
||||||
})
|
})
|
||||||
|
@ -87,7 +84,7 @@ const actions: ActionTree<GeneralState, RootState> = {
|
||||||
updateTimeline: ({ commit, state, dispatch }, timeline: object) => {
|
updateTimeline: ({ commit, state, dispatch }, timeline: object) => {
|
||||||
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
||||||
const newTimeline: Timeline = Object.assign({}, state.general.timeline, timeline)
|
const newTimeline: Timeline = Object.assign({}, state.general.timeline, timeline)
|
||||||
const newGeneral: GeneralSet = Object.assign({}, state.general, {
|
const newGeneral: General = Object.assign({}, state.general, {
|
||||||
timeline: newTimeline
|
timeline: newTimeline
|
||||||
})
|
})
|
||||||
const config = {
|
const config = {
|
||||||
|
@ -99,9 +96,9 @@ const actions: ActionTree<GeneralState, RootState> = {
|
||||||
commit('changeLoading', false)
|
commit('changeLoading', false)
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as GeneralSet)
|
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
resolve(conf)
|
resolve(conf)
|
||||||
|
@ -110,11 +107,10 @@ const actions: ActionTree<GeneralState, RootState> = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const General: Module<GeneralState, RootState> = {
|
|
||||||
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: state,
|
state: state,
|
||||||
mutations: mutations,
|
mutations: mutations,
|
||||||
actions: actions
|
actions: actions
|
||||||
}
|
} as Module<GeneralState, RootState>
|
||||||
|
|
||||||
export default General
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Language from '~/src/constants/language'
|
||||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
import { Language as LanguageSet } from '~/src/types/language'
|
import { Language as LanguageSet } from '~/src/types/language'
|
||||||
|
import { BaseConfig } from '~/src/types/preference'
|
||||||
|
|
||||||
export interface LanguageState {
|
export interface LanguageState {
|
||||||
language: LanguageSet
|
language: LanguageSet
|
||||||
|
@ -36,7 +37,7 @@ const actions: ActionTree<LanguageState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-get-preferences')
|
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language as LanguageSet)
|
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language as LanguageSet)
|
||||||
resolve(conf)
|
resolve(conf)
|
||||||
|
|
|
@ -2,10 +2,7 @@ import { ipcRenderer } from 'electron'
|
||||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
import { Notify } from '~/src/types/notify'
|
import { Notify } from '~/src/types/notify'
|
||||||
|
import { BaseConfig, Notification } from '~/src/types/preference'
|
||||||
interface Notification {
|
|
||||||
notify: Notify
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NotificationState {
|
export interface NotificationState {
|
||||||
notification: Notification
|
notification: Notification
|
||||||
|
@ -40,9 +37,9 @@ const actions: ActionTree<NotificationState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-get-preferences')
|
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||||
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification as Notification)
|
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification)
|
||||||
resolve(conf)
|
resolve(conf)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -57,8 +54,8 @@ const actions: ActionTree<NotificationState, RootState> = {
|
||||||
}
|
}
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
ipcRenderer.send('update-preferences', config)
|
ipcRenderer.send('update-preferences', config)
|
||||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||||
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification as Notification)
|
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification)
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
resolve(conf.notification)
|
resolve(conf.notification)
|
||||||
})
|
})
|
||||||
|
|
|
@ -47,7 +47,7 @@ const actions: ActionTree<TimelineState, RootState> = {
|
||||||
ipcRenderer.send('get-unread-notification', rootState.Settings.accountID)
|
ipcRenderer.send('get-unread-notification', rootState.Settings.accountID)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
changeUnreadNotification: ({ dispatch, state, rootState }, timeline: any): Promise<boolean> => {
|
changeUnreadNotification: ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise<boolean> => {
|
||||||
const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, {
|
const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, {
|
||||||
accountID: rootState.Settings.accountID
|
accountID: rootState.Settings.accountID
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { Sound } from '~/src/types/sound'
|
||||||
|
import { Timeline } from '~/src/types/timeline'
|
||||||
|
import { Notify } from '~/src/types/notify'
|
||||||
|
import { Appearance } from '~/src/types/appearance'
|
||||||
|
import { Language } from '~/src/types/language'
|
||||||
|
|
||||||
|
export type General = {
|
||||||
|
sound: Sound
|
||||||
|
timeline: Timeline
|
||||||
|
}
|
||||||
|
|
||||||
|
export type State = {
|
||||||
|
collapse: boolean
|
||||||
|
hideGlobalHeader: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Notification = {
|
||||||
|
notify: Notify
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BaseConfig = {
|
||||||
|
general: General
|
||||||
|
state: State
|
||||||
|
language: Language
|
||||||
|
notification: Notification
|
||||||
|
appearance: Appearance
|
||||||
|
}
|
Loading…
Reference in New Issue