import { PresetGetters , PresetActions , PresetMutations , PresetStoreState , VoiceVoxStoreOptions , } from "@/store/type" ; import { Preset } from "@/type/preload" ; import { v4 as uuidv4 } from "uuid" ; export const presetStoreState = { presetItems : { } , presetKeys : [ ] , } ; export const presetStore = { getters : { } , mutations : { SET_PRESET_ITEMS ( state , { presetItems } ) { state . presetItems = presetItems ; } , SET_PRESET_KEYS ( state , { presetKeys } ) { state . presetKeys = presetKeys ; } , } , actions : { GET_PRESET_CONFIG : async ( context ) => { const presetConfig = await window . electron . savingPresets ( ) ; if ( presetConfig === undefined || presetConfig . items === undefined || presetConfig . keys === undefined ) return ; context . commit ( "SET_PRESET_ITEMS" , { presetItems : presetConfig . items , } ) ; context . commit ( "SET_PRESET_KEYS" , { presetKeys : presetConfig . keys , } ) ; } , SAVE_PRESET_CONFIG : async ( context , { presetItems , presetKeys , } ) => { const result = await window . electron . savingPresets ( { presetItems : JSON . parse ( JSON . stringify ( presetItems ) ) , presetKeys : JSON . parse ( JSON . stringify ( presetKeys ) ) , } ) ; context . commit ( "SET_PRESET_ITEMS" , { presetItems : result . items } ) ; context . commit ( "SET_PRESET_KEYS" , { presetKeys : result . keys } ) ; } , async ADD_PRESET ( context , { presetData } ) { const newKey = uuidv4 ( ) ; const newPresetItems = { ... context . state . presetItems , [ newKey ] : presetData , } ; const newPresetKeys = [ newKey , ... context . state . presetKeys ] ; await context . dispatch ( "SAVE_PRESET_CONFIG" , { presetItems : newPresetItems , presetKeys : newPresetKeys , } ) ; return newKey ; } , async UPDATE_PRESET ( context , { presetKey , presetData } ) { const newPresetItems = { ... context . state . presetItems , [ presetKey ] : presetData , } ; const newPresetKeys = context . state . presetKeys . includes ( presetKey ) ? [ ... context . state . presetKeys ] : [ presetKey , ... context . state . presetKeys ] ; await context . dispatch ( "SAVE_PRESET_CONFIG" , { presetItems : newPresetItems , presetKeys : newPresetKeys , } ) ; } , async DELETE_PRESET ( context , { presetKey } ) { const newPresetKeys = context . state . presetKeys . filter ( ( key ) => key != presetKey ) ; const { [ presetKey ] : _ , ... newPresetItems } = context . state . presetItems ; await context . dispatch ( "SAVE_PRESET_CONFIG" , { presetItems : newPresetItems , presetKeys : newPresetKeys , } ) ; } , } , } ;