@@ -86,7 +86,7 @@ state.core = (function () {
8686 fetch ( '/lightdiffusionflow/local/need_preload' )
8787 . then ( response => response . json ( ) )
8888 . then ( data => {
89- //console.log(`fn_timer ${data} `)
89+ //console.log(`fn_timer`)
9090 if ( data != "" ) {
9191 //state.core.actions.handleLightDiffusionFlow([{"name":data}]);
9292 const btn1 = gradioApp ( ) . querySelector ( `button#set_lightdiffusionflow_file` ) ;
@@ -168,7 +168,6 @@ state.core = (function () {
168168 }
169169
170170 function load ( config ) {
171-
172171 config . hasSetting = hasSetting
173172
174173 //loadUI(); // 往页面上添加按钮
@@ -481,8 +480,9 @@ state.core = (function () {
481480 // alert('All state values deleted!');
482481 // }
483482 // },
484- applyState : function ( ) {
485- fetch ( '/lightdiffusionflow/local/config.json?_=' + ( + new Date ( ) ) )
483+ applyState : async function ( ) {
484+ console . log ( "applyState" )
485+ await fetch ( '/lightdiffusionflow/local/config.json?_=' + ( + new Date ( ) ) )
486486 . then ( response => response . json ( ) )
487487 . then ( config => {
488488 try {
@@ -644,7 +644,6 @@ state.core = (function () {
644644 actions . output_log ( "Please select a valid lightdiffusionflow or image file!" )
645645 return ;
646646 }
647- console . log ( json_obj )
648647
649648 forEachElement_WithoutTabs ( IMAGES_WITHOUT_PREFIX , ( image_id ) => {
650649 json_obj [ image_id ] = ""
@@ -653,58 +652,84 @@ state.core = (function () {
653652 store . clear ( ) ;
654653 store . load ( json_obj ) ;
655654 actions . applyState ( ) ;
656-
657655 return ;
658656 } ,
659657 startImportImage : function ( index ) {
658+ index = Number ( index )
659+
660+ if ( index + 1 < img_elem_keys . length ) {
661+ //console.log(`---------${img_elem_keys}---------------`)
662+ //console.log(`---------${index}-----${img_elem_keys.length}-----------`)
663+ switch_tab_dict = {
664+ "txt2img_invisible_img2img_image" : "switch_to_img2img()" ,
665+ "txt2img_invisible_img2img_sketch" : "switch_to_sketch()" ,
666+ "txt2img_invisible_img2maskimg" : "switch_to_inpaint()" ,
667+ "txt2img_invisible_inpaint_sketch" : "switch_to_inpaint_sketch()" ,
668+ "txt2img_invisible_img_inpaint_base" : "state.utils.switch_to_img_inpaint()" ,
669+ "txt2img_invisible_img_inpaint_mask" : "state.utils.switch_to_img_inpaint()" ,
670+ "txt2img_invisible_txt2img_controlnet_ControlNet_input_image" : "state.utils.switch_to_txt2img_ControlNet(0)" ,
671+ "txt2img_invisible_img2img_controlnet_ControlNet_input_image" : "state.utils.switch_to_img2img_ControlNet(0)"
672+ }
673+
674+ for ( let i = 0 ; i < 10 ; i ++ ) {
675+ switch_tab_dict [ `txt2img_invisible_txt2img_controlnet_ControlNet-${ i } _input_image` ] = `state.utils.switch_to_txt2img_ControlNet(${ i } )`
676+ switch_tab_dict [ `txt2img_invisible_img2img_controlnet_ControlNet-${ i } _input_image` ] = `state.utils.switch_to_img2img_ControlNet(${ i } )`
677+ }
660678
661- console . log ( `---------${ img_elem_keys } ---------------` )
662- console . log ( `---------${ index } -----${ img_elem_keys . length } -----------` )
663- switch_tab_dict = {
664- "txt2img_invisible_img2img_image" : "switch_to_img2img()" ,
665- "txt2img_invisible_img2img_sketch" : "switch_to_sketch()" ,
666- "txt2img_invisible_img2maskimg" : "switch_to_inpaint()" ,
667- "txt2img_invisible_inpaint_sketch" : "switch_to_inpaint_sketch()" ,
668- "txt2img_invisible_img_inpaint_base" : "state.utils.switch_to_img_inpaint()" ,
669- "txt2img_invisible_img_inpaint_mask" : "state.utils.switch_to_img_inpaint()" ,
670- "txt2img_invisible_txt2img_controlnet_ControlNet_input_image" : "state.utils.switch_to_txt2img_ControlNet(0)" ,
671- "txt2img_invisible_img2img_controlnet_ControlNet_input_image" : "state.utils.switch_to_img2img_ControlNet(0)"
672- }
673-
674- for ( let i = 0 ; i < 10 ; i ++ ) {
675- switch_tab_dict [ `txt2img_invisible_txt2img_controlnet_ControlNet-${ i } _input_image` ] = `state.utils.switch_to_txt2img_ControlNet(${ i } )`
676- switch_tab_dict [ `txt2img_invisible_img2img_controlnet_ControlNet-${ i } _input_image` ] = `state.utils.switch_to_img2img_ControlNet(${ i } )`
679+ state . utils . sleep ( 300 ) . then ( ( ) => {
680+ try {
681+ key = "txt2img_invisible_" + img_elem_keys [ index + 1 ]
682+ eval ( switch_tab_dict [ key ] ) // 跳转界面
683+ const button = gradioApp ( ) . getElementById ( key ) ;
684+ button . click ( ) ;
685+ } catch ( error ) {
686+ console . warn ( '[startImportImage]: Error:' , error ) ;
687+ if ( index + 1 < img_elem_keys . length ) {
688+ // 图片组件设置出错了,但是需要继续后续的流程
689+
690+ index = img_elem_keys . length - 1
691+ }
692+ }
693+ } ) ;
677694 }
678695
679- state . utils . sleep ( 300 ) . then ( ( ) => {
680- try {
681- key = "txt2img_invisible_" + img_elem_keys [ Number ( index ) + 1 ]
682- //console.log(key)
683- eval ( switch_tab_dict [ key ] ) // 跳转界面
684- const button = gradioApp ( ) . getElementById ( key ) ;
685- button . click ( ) ;
686- } catch ( error ) {
687- console . warn ( '[startImportImage]: Error:' , error ) ;
688- }
689- } ) ;
690-
691- if ( Number ( index ) + 1 >= img_elem_keys . length ) { // 图片导入完成
692- console . log ( lightdiffusionflow_set_dropdowns )
693- const button = gradioApp ( ) . getElementById ( "lightdiffusionflow_set_dropdowns" ) ;
694- button . click ( ) ;
696+ switch ( index + 1 - img_elem_keys . length ) {
697+ case 0 :// 图片导入完成,开始导入Dropdown
698+ state . utils . sleep ( 500 ) . then ( ( ) => {
699+ try {
700+ const button = gradioApp ( ) . getElementById ( "lightdiffusionflow_set_dropdowns" ) ;
701+ button . click ( ) ;
702+ } catch ( error ) {
703+ console . warn ( '[set_dropdowns]: Error:' , error ) ;
704+ }
705+ } ) ;
706+ break
707+ // case 1:// 触发了导入Dropdown,现在导入其他参数会卡死,触发导入按钮,等下一轮正式开始导入
708+ // state.utils.sleep(500).then(() => {
709+ // const button = gradioApp().getElementById("lightdiffusionflow_set_js_params");
710+ // console.log("lightdiffusionflow_set_js_params")
711+ // button.click();
712+ // });
713+ // break
714+ // case 2:// 导入其他参数
715+ // state.utils.sleep(500).then(() => {
716+ // console.log("导入其他参数")
717+ // actions.applyState();
718+ // });
719+ // break
695720 }
696721
697722 } ,
698- output_log : function ( msg , style = "" ) {
699- fetch ( `/lightdiffusionflow/local/output_log?msg=${ msg } &style=${ style } ` ) . then ( ( ) => {
723+ output_log : function ( msg , msg_style = "" ) {
724+ fetch ( `/lightdiffusionflow/local/output_log?msg=${ msg } &style=${ msg_style } ` ) . then ( ( ) => {
700725 gradioApp ( ) . getElementById ( "txt2img_invisible_refresh_log" ) . click ( ) ;
701726 } ) ;
702727 } ,
703- output_warning : function ( msg , style = "color:Orange;" ) {
704- actions . output_log ( msg , style )
728+ output_warning : function ( msg , msg_style = "color:Orange;" ) {
729+ actions . output_log ( msg , msg_style )
705730 } ,
706- output_error : function ( msg , style = "color:Tomato;" ) {
707- actions . output_log ( msg , style )
731+ output_error : function ( msg , msg_style = "color:Tomato;" ) {
732+ actions . output_log ( msg , msg_style )
708733 }
709734 } ;
710735
0 commit comments