@@ -74,6 +74,7 @@ state.core = (function () {
7474
7575 let store = null ;
7676 let timer = null ;
77+ let inited = false
7778 let sd_versions = "0.0.0"
7879
7980 function hasSetting ( id , tab ) {
@@ -84,7 +85,8 @@ state.core = (function () {
8485
8586 function fn_timer ( ) {
8687
87- fetch ( '/lightdiffusionflow/local/need_preload' )
88+ // if(inited){
89+ fetch ( '/lightdiffusionflow/local/need_preload' )
8890 . then ( response => response . json ( ) )
8991 . then ( data => {
9092 //console.log(`fn_timer`)
@@ -101,13 +103,88 @@ state.core = (function () {
101103 clearInterval ( timer )
102104 console . log ( "Oops, error" ) ;
103105 } ) ;
106+ // }
107+ // else{
108+
109+ // fetch('/lightdiffusionflow/local/get_imgs_elem_key') //初始化部分图片组件id, 后续设置onchanged事件
110+ // .then(response => response.json())
111+ // .then(data => {
112+ // console.log('-----------------------------')
113+ // console.log(data)
114+ // console.log('-----------------------------')
115+ // if(data != ""){
116+
117+ // img_elem_keys = data.split(",")
118+ // img_elem_keys.forEach(key => {
119+ // IMAGES_WITHOUT_PREFIX[key] = key
120+ // });
121+
122+ // // 等上面的组件ID同步过来后 再加载其他配置
123+ // fetch('/lightdiffusionflow/local/config.json?_=' + (+new Date()))
124+ // .then(response => response.json())
125+ // .then(config => {
126+ // try {
127+ // store = new state.Store();
128+ // store.clearAll();
129+ // load(config);
130+ // inited = true
131+ // } catch (error) {
132+ // console.error('[state]: Error:', error);
133+ // }
134+ // })
135+ // .catch(error => console.error('[state]: Error getting JSON file:', error));
136+ // }
137+ // });
138+
104139
140+ // }
141+
105142 }
106143
107144 let img_elem_keys = [ ] ;
145+ let ext_list = [ ] ;
108146
109147 function get_imgs_elem_key ( ) {
110- return img_elem_keys ;
148+
149+ fetch ( '/lightdiffusionflow/local/get_imgs_elem_key' ) //初始化部分图片组件id, 后续设置onchanged事件
150+ . then ( response => response . json ( ) )
151+ . then ( data => {
152+ console . log ( data )
153+ if ( data == '' ) {
154+ console . log ( '-----------------------------' )
155+ setTimeout ( ( ) => {
156+ get_imgs_elem_key ( )
157+ } , 500 ) ;
158+ }
159+ else {
160+ img_elem_keys = data . split ( "," )
161+ img_elem_keys . forEach ( key => {
162+ IMAGES_WITHOUT_PREFIX [ key ] = key
163+ } ) ;
164+
165+ fetch ( '/lightdiffusionflow/local/get_ext_list' )
166+ . then ( response => response . json ( ) )
167+ . then ( data => {
168+ ext_list = data . split ( "," )
169+ } ) ;
170+
171+ // 等上面的组件ID同步过来后 再加载其他配置
172+ fetch ( '/lightdiffusionflow/local/config.json?_=' + ( + new Date ( ) ) )
173+ . then ( response => response . json ( ) )
174+ . then ( config => {
175+ try {
176+ store = new state . Store ( ) ;
177+ store . clearAll ( ) ;
178+ load ( config ) ;
179+ timer = window . setInterval ( fn_timer , 1000 ) ; // 初始化页面完成后再启动timer读取文件
180+ } catch ( error ) {
181+ console . error ( '[state]: Error:' , error ) ;
182+ }
183+ } )
184+ . catch ( error => console . error ( '[state]: Error getting JSON file:' , error ) ) ;
185+ }
186+ } ) ;
187+
111188 }
112189
113190 function init ( ) {
@@ -119,30 +196,7 @@ state.core = (function () {
119196 sd_versions = data
120197 } ) ;
121198
122- fetch ( '/lightdiffusionflow/local/get_imgs_elem_key' ) //初始化部分图片组件id, 后续设置onchanged事件
123- . then ( response => response . json ( ) )
124- . then ( data => {
125- img_elem_keys = data . split ( "," )
126- img_elem_keys . forEach ( key => {
127- IMAGES_WITHOUT_PREFIX [ key ] = key
128- } ) ;
129-
130- // 等上面的组件ID同步过来后 再加载其他配置
131- fetch ( '/lightdiffusionflow/local/config.json?_=' + ( + new Date ( ) ) )
132- . then ( response => response . json ( ) )
133- . then ( config => {
134- try {
135- store = new state . Store ( ) ;
136- store . clearAll ( ) ;
137- load ( config ) ;
138- timer = window . setInterval ( fn_timer , 1000 ) ; // 初始化页面完成后再启动timer读取文件
139- } catch ( error ) {
140- console . error ( '[state]: Error:' , error ) ;
141- }
142- } )
143- . catch ( error => console . error ( '[state]: Error getting JSON file:' , error ) ) ;
144- } ) ;
145-
199+ get_imgs_elem_key ( )
146200
147201 }
148202
@@ -555,6 +609,13 @@ state.core = (function () {
555609 }
556610 }
557611
612+ for ( let key in stored_config ) {
613+ if ( key . indexOf ( "allow-preview" ) !== - 1 && key . indexOf ( "ext-control-net" ) !== - 1 )
614+ {
615+ stored_config [ key ] = "false"
616+ }
617+ }
618+
558619 var checkTime = function ( i ) {
559620 if ( i < 10 ) { i = "0" + i ; }
560621 return i ;
@@ -575,6 +636,8 @@ state.core = (function () {
575636 filename += ".flow" ;
576637 }
577638 if ( filename != ".flow" ) {
639+ // const handle = window.showDirectoryPicker();
640+ // console.log(handle)
578641 state . utils . saveFile ( filename , stored_config ) ;
579642 }
580643
@@ -585,14 +648,16 @@ state.core = (function () {
585648 } ,
586649
587650 handleLightDiffusionFlow : function ( fileInput ) {
588- actions . output_log ( "Start parsing settings..." )
651+ actions . preset_output_log ( "start" )
652+ //actions.output_log("<hr style='margin-top:10px;margin-bottom:10px'>Start parsing settings...")
589653 console . log ( fileInput )
590654 let temp_fileInput = undefined
591655 try { temp_fileInput = fileInput [ 0 ] } catch ( error ) { }
592656 if ( ! temp_fileInput ) { temp_fileInput = fileInput }
593657 if ( ! temp_fileInput ) {
594658 //alert('Please select a JSON file!');
595- actions . output_log ( "Please select a valid lightdiffusionflow or image file!" )
659+ actions . preset_output_log ( "invalid" )
660+ //actions.output_log("Please select a valid lightdiffusionflow or image file!")
596661 return ;
597662 }
598663
@@ -655,52 +720,87 @@ state.core = (function () {
655720
656721 let json_obj = { }
657722 try { json_obj = JSON . parse ( inputData ) } catch ( error ) {
658- actions . output_log ( "Please select a valid lightdiffusionflow or image file!" )
723+ actions . preset_output_log ( "invalid" )
724+ //actions.output_log("Please select a valid lightdiffusionflow or image file!")
659725 return ;
660726 }
661727
662- forEachElement_WithoutTabs ( IMAGES_WITHOUT_PREFIX , ( image_id ) => {
663- json_obj [ image_id ] = ""
728+ // 筛选掉默认值参数
729+ let data = {
730+ method : 'POST' ,
731+ headers : { 'Content-Type' : 'application/json' } ,
732+ body : JSON . stringify ( {
733+ "config_data" :json_obj
734+ } )
735+ }
736+ fetch ( `/lightdiffusionflow/local/useless_config_filter` , data )
737+ . then ( response => response . json ( ) )
738+ . then ( data => {
739+ json_obj = data
740+ console . log ( ext_list )
741+ // 缺少的插件
742+ missing_ext_list = [ ]
743+ for ( let key in json_obj ) {
744+ ext_name = key . match ( / e x t - ( \S + ) - ( t x t 2 i m g | i m g 2 i m g ) / )
745+ console . log ( key )
746+ if ( ext_name != null ) {
747+ ext_name = ext_name [ 1 ]
748+ console . log ( ext_name )
749+ if ( ext_list . indexOf ( ext_name ) === - 1 ) {
750+ if ( missing_ext_list . indexOf ( ext_name ) === - 1 ) {
751+ missing_ext_list . push ( ext_name )
752+ }
753+ }
754+ }
755+ }
756+
757+ if ( missing_ext_list . length > 0 ) {
758+ actions . preset_output_log ( "missing_exts" , "" , missing_ext_list . join ( ';' ) )
759+ }
760+
761+ forEachElement_WithoutTabs ( IMAGES_WITHOUT_PREFIX , ( image_id ) => {
762+ json_obj [ image_id ] = ""
763+ } ) ;
764+ // webui主界面 没有localization相关的兼容问题 所以不用管
765+ store . clear ( ) ;
766+ store . load ( json_obj ) ;
767+ actions . applyState ( ) ;
664768 } ) ;
665- // webui主界面 没有localization相关的兼容问题 所以不用管
666- store . clear ( ) ;
667- store . load ( json_obj ) ;
668- actions . applyState ( ) ;
669769 return ;
670770 } ,
671771 startImportImage : function ( index ) {
672772 index = Number ( index )
673773
774+ //console.log(`-------startImportImage--'${index}'---------------`)
674775 if ( index + 1 < img_elem_keys . length ) {
675776 //console.log(`---------${img_elem_keys}---------------`)
676- //console.log(`---------${index}-----${img_elem_keys.length}-----------`)
777+ //console.log(`---------' ${index}' -----' ${img_elem_keys.length}' -----------`)
677778 switch_tab_dict = {
678- "txt2img_invisible_img2img_image " : "switch_to_img2img()" ,
679- "txt2img_invisible_img2img_sketch " : "switch_to_sketch()" ,
680- "txt2img_invisible_img2maskimg " : "switch_to_inpaint()" ,
681- "txt2img_invisible_inpaint_sketch " : "switch_to_inpaint_sketch()" ,
682- "txt2img_invisible_img_inpaint_base " : "state.utils.switch_to_img_inpaint()" ,
683- "txt2img_invisible_img_inpaint_mask " : "state.utils.switch_to_img_inpaint()" ,
684- "txt2img_invisible_txt2img_controlnet_ControlNet_input_image " : "state.utils.switch_to_txt2img_ControlNet(0)" ,
685- "txt2img_invisible_img2img_controlnet_ControlNet_input_image " : "state.utils.switch_to_img2img_ControlNet(0)"
779+ "img2img_invisible_img2img_image " : "switch_to_img2img()" ,
780+ "img2img_invisible_img2img_sketch " : "switch_to_sketch()" ,
781+ "img2img_invisible_img2maskimg " : "switch_to_inpaint()" ,
782+ "img2img_invisible_inpaint_sketch " : "switch_to_inpaint_sketch()" ,
783+ "img2img_invisible_img_inpaint_base " : "state.utils.switch_to_img_inpaint()" ,
784+ "img2img_invisible_img_inpaint_mask " : "state.utils.switch_to_img_inpaint()" ,
785+ "img2img_invisible_txt2img_controlnet_ControlNet_input_image " : "state.utils.switch_to_txt2img_ControlNet(0)" ,
786+ "img2img_invisible_img2img_controlnet_ControlNet_input_image " : "state.utils.switch_to_img2img_ControlNet(0)"
686787 }
687788
688789 for ( let i = 0 ; i < 10 ; i ++ ) {
689- switch_tab_dict [ `txt2img_invisible_txt2img_controlnet_ControlNet -${ i } _input_image` ] = `state.utils.switch_to_txt2img_ControlNet(${ i } )`
690- switch_tab_dict [ `txt2img_invisible_img2img_controlnet_ControlNet -${ i } _input_image` ] = `state.utils.switch_to_img2img_ControlNet(${ i } )`
790+ switch_tab_dict [ `img2img_invisible_txt2img_controlnet_ControlNet -${ i } _input_image` ] = `state.utils.switch_to_txt2img_ControlNet(${ i } )`
791+ switch_tab_dict [ `img2img_invisible_img2img_controlnet_ControlNet -${ i } _input_image` ] = `state.utils.switch_to_img2img_ControlNet(${ i } )`
691792 }
692793
693794 state . utils . sleep ( 300 ) . then ( ( ) => {
694795 try {
695- key = "txt2img_invisible_ " + img_elem_keys [ index + 1 ]
796+ key = "img2img_invisible_ " + img_elem_keys [ index + 1 ]
696797 eval ( switch_tab_dict [ key ] ) // 跳转界面
697798 const button = gradioApp ( ) . getElementById ( key ) ;
698799 button . click ( ) ;
699800 } catch ( error ) {
700801 console . warn ( '[startImportImage]: Error:' , error ) ;
701802 if ( index + 1 < img_elem_keys . length ) {
702803 // 图片组件设置出错了,但是需要继续后续的流程
703-
704804 index = img_elem_keys . length - 1
705805 }
706806 }
@@ -732,17 +832,21 @@ state.core = (function () {
732832 // });
733833 // break
734834 }
735-
835+ } ,
836+ preset_output_log : function ( preset , key = "" , value = "" ) {
837+ fetch ( `/lightdiffusionflow/local/preset_output_log?preset=${ preset } &key=${ key } &value=${ value } ` ) . then ( ( ) => {
838+ gradioApp ( ) . getElementById ( "img2img_invisible_refresh_log" ) . click ( ) ;
839+ } ) ;
736840 } ,
737841 output_log : function ( msg , msg_style = "" ) {
738842 fetch ( `/lightdiffusionflow/local/output_log?msg=${ msg } &style=${ msg_style } ` ) . then ( ( ) => {
739- gradioApp ( ) . getElementById ( "txt2img_invisible_refresh_log " ) . click ( ) ;
843+ gradioApp ( ) . getElementById ( "img2img_invisible_refresh_log " ) . click ( ) ;
740844 } ) ;
741845 } ,
742846 output_warning : function ( msg , msg_style = "color:Orange;" ) {
743847 actions . output_log ( msg , msg_style )
744848 } ,
745- output_error : function ( msg , msg_style = "color:Tomato ;" ) {
849+ output_error : function ( msg , msg_style = "color:Red ;" ) {
746850 actions . output_log ( msg , msg_style )
747851 } ,
748852 get_sd_version : function ( ) {
0 commit comments