import { Module , MutationTree , ActionTree } from 'vuex' ; import { RootState } from '@/store' ; import { Notify } from '~/src/types/notify' ; import { BaseConfig , Notification } from '~/src/types/preference' ; import { MyWindow } from '~/src/types/global' ; const win = ( window as any ) as MyWindow ; export type NotificationState = { notification : Notification ; } ; const state = { notification : { notify : { reply : true , reblog : true , favourite : true , follow : true , follow_request : true , reaction : true , status : true , poll_vote : true , poll_expired : true } } } ; export const MUTATION_TYPES = { UPDATE_NOTIFICATION : 'updateNotification' } ; const mutations = { [ MUTATION_TYPES . UPDATE_NOTIFICATION ] : ( state , notification ) => { state . notification = notification ; } } ; const actions = { loadNotification : async ( { commit } ) => { const conf = await win . ipcRenderer . invoke ( 'get-preferences' ) ; commit ( MUTATION_TYPES . UPDATE_NOTIFICATION , conf . notification ) ; return conf ; } , updateNotify : async ( { commit , state , dispatch } , notify ) => { const newNotify = Object . assign ( { } , state . notification . notify , notify ) ; const newNotification = Object . assign ( { } , state . notification , { notify : newNotify } ) ; const config = { notification : newNotification } ; const conf = await win . ipcRenderer . invoke ( 'update-preferences' , config ) ; commit ( MUTATION_TYPES . UPDATE_NOTIFICATION , conf . notification ) ; dispatch ( 'App/loadPreferences' , null , { root : true } ) ; } } ; export default { namespaced : true , state : state , mutations : mutations , actions : actions } as Module < NotificationState , RootState > ;