11import { computed , defineComponent , onMounted , ref , watch } from "vue" ;
2- import { NButton , NCheckbox , NFlex , NModal , NSwitch , useDialog } from "naive-ui" ;
2+ import { NButton , NCheckbox , NFlex , NModal , NSwitch , useDialog , useMessage } from "naive-ui" ;
33import api from "@/client/api" ;
44import { globalCapture , modInfo , updateModInfo , updateMusicList , aquaMaiConfig as config } from "@/store/refs" ;
55import AquaMaiConfigurator from "./AquaMaiConfigurator" ;
66import { shouldShowUpdate } from "./shouldShowUpdateController" ;
77import { useStorage } from "@vueuse/core" ;
8+ import _ from "lodash" ;
89
910export default defineComponent ( {
1011 props : {
@@ -29,6 +30,7 @@ export default defineComponent({
2930 const installingAquaMai = ref ( false )
3031 const showAquaMaiInstallDone = ref ( false )
3132 const useNewSort = useStorage ( 'useNewSort' , true )
33+ const message = useMessage ( ) ;
3234
3335 const updateAquaMaiConfig = async ( ) => {
3436 try {
@@ -96,17 +98,26 @@ export default defineComponent({
9698 }
9799 }
98100
99- watch ( ( ) => show . value , async ( val ) => {
101+ const saveImpl = async ( ) => {
102+ if ( ! config . value ) return ;
103+ try {
104+ await api . SetAquaMaiConfig ( config . value )
105+ await updateMusicList ( )
106+ message . success ( "保存配置文件成功" )
107+ } catch ( e ) {
108+ globalCapture ( e , "保存 AquaMai 配置失败" )
109+ }
110+ }
111+ const save = _ . debounce ( saveImpl , 2000 ) ;
112+
113+ watch ( ( ) => config . value , async ( val ) => {
100114 if ( configReadErr . value ) return
101- if ( ! val && config . value ) {
102- try {
103- await api . SetAquaMaiConfig ( config . value )
104- await updateMusicList ( )
105- } catch ( e ) {
106- globalCapture ( e , "保存 AquaMai 配置失败" )
107- }
115+ if ( ! show . value ) return
116+ if ( val ) {
117+ console . log ( '配置变动' )
118+ save ( )
108119 }
109- } )
120+ } , { deep : true } )
110121
111122
112123 return ( ) => < NModal
0 commit comments