@@ -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` ) ;
@@ -104,6 +104,11 @@ state.core = (function () {
104104 }
105105
106106 let img_elem_keys = [ ] ;
107+
108+ function get_imgs_elem_key ( ) {
109+ return img_elem_keys ;
110+ }
111+
107112 function init ( ) {
108113
109114 //console.log(window.localization)
@@ -163,7 +168,6 @@ state.core = (function () {
163168 }
164169
165170 function load ( config ) {
166-
167171 config . hasSetting = hasSetting
168172
169173 //loadUI(); // 往页面上添加按钮
@@ -476,8 +480,9 @@ state.core = (function () {
476480 // alert('All state values deleted!');
477481 // }
478482 // },
479- applyState : function ( ) {
480- fetch ( '/lightdiffusionflow/local/config.json?_=' + ( + new Date ( ) ) )
483+ applyState : async function ( ) {
484+ console . log ( "applyState" )
485+ await fetch ( '/lightdiffusionflow/local/config.json?_=' + ( + new Date ( ) ) )
481486 . then ( response => response . json ( ) )
482487 . then ( config => {
483488 try {
@@ -639,7 +644,6 @@ state.core = (function () {
639644 actions . output_log ( "Please select a valid lightdiffusionflow or image file!" )
640645 return ;
641646 }
642- console . log ( json_obj )
643647
644648 forEachElement_WithoutTabs ( IMAGES_WITHOUT_PREFIX , ( image_id ) => {
645649 json_obj [ image_id ] = ""
@@ -648,54 +652,86 @@ state.core = (function () {
648652 store . clear ( ) ;
649653 store . load ( json_obj ) ;
650654 actions . applyState ( ) ;
651-
652655 return ;
653656 } ,
654657 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+ }
655678
656- switch_tab_dict = {
657- "txt2img_invisible_img2img_image" : "switch_to_img2img()" ,
658- "txt2img_invisible_img2img_sketch" : "switch_to_sketch()" ,
659- "txt2img_invisible_img2maskimg" : "switch_to_inpaint()" ,
660- "txt2img_invisible_inpaint_sketch" : "switch_to_inpaint_sketch()" ,
661- "txt2img_invisible_img_inpaint_base" : "state.utils.switch_to_img_inpaint()" ,
662- "txt2img_invisible_img_inpaint_mask" : "state.utils.switch_to_img_inpaint()" ,
663- "txt2img_invisible_txt2img_controlnet_ControlNet_input_image" : "state.utils.switch_to_txt2img_ControlNet(0)" ,
664- "txt2img_invisible_img2img_controlnet_ControlNet_input_image" : "state.utils.switch_to_img2img_ControlNet(0)"
665- }
666-
667- for ( let i = 0 ; i < 10 ; i ++ ) {
668- switch_tab_dict [ `txt2img_invisible_txt2img_controlnet_ControlNet-${ i } _input_image` ] = `state.utils.switch_to_txt2img_ControlNet(${ i } )`
669- 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+ } ) ;
670694 }
671695
672- state . utils . sleep ( 300 ) . then ( ( ) => {
673-
674- try {
675- key = "txt2img_invisible_" + img_elem_keys [ Number ( index ) + 1 ]
676- //console.log(key)
677- eval ( switch_tab_dict [ key ] ) // 跳转界面
678- const button = gradioApp ( ) . getElementById ( key ) ;
679- button . click ( ) ;
680- } catch ( error ) {
681- console . warn ( '[startImportImage]: Error:' , error ) ;
682- }
683-
684- } ) ;
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
720+ }
685721
686722 } ,
687- output_log : function ( msg , style = "" ) {
688- 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 ( ( ) => {
689725 gradioApp ( ) . getElementById ( "txt2img_invisible_refresh_log" ) . click ( ) ;
690726 } ) ;
691727 } ,
692- output_warning : function ( msg , style = "color:Orange;" ) {
693- actions . output_log ( msg , style )
728+ output_warning : function ( msg , msg_style = "color:Orange;" ) {
729+ actions . output_log ( msg , msg_style )
694730 } ,
695- output_error : function ( msg , style = "color:Tomato;" ) {
696- actions . output_log ( msg , style )
731+ output_error : function ( msg , msg_style = "color:Tomato;" ) {
732+ actions . output_log ( msg , msg_style )
697733 }
698734 } ;
699735
700- return { init, actions } ;
736+ return { init, actions } ;
701737} ( ) ) ;
0 commit comments