@@ -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,81 @@ 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 = [ ] ;
108145
109146 function get_imgs_elem_key ( ) {
110- return img_elem_keys ;
147+
148+ fetch ( '/lightdiffusionflow/local/get_imgs_elem_key' ) //初始化部分图片组件id, 后续设置onchanged事件
149+ . then ( response => response . json ( ) )
150+ . then ( data => {
151+ console . log ( data )
152+ if ( data == '' ) {
153+ console . log ( '-----------------------------' )
154+ setTimeout ( ( ) => {
155+ get_imgs_elem_key ( )
156+ } , 500 ) ;
157+ }
158+ else {
159+ img_elem_keys = data . split ( "," )
160+ img_elem_keys . forEach ( key => {
161+ IMAGES_WITHOUT_PREFIX [ key ] = key
162+ } ) ;
163+
164+ // 等上面的组件ID同步过来后 再加载其他配置
165+ fetch ( '/lightdiffusionflow/local/config.json?_=' + ( + new Date ( ) ) )
166+ . then ( response => response . json ( ) )
167+ . then ( config => {
168+ try {
169+ store = new state . Store ( ) ;
170+ store . clearAll ( ) ;
171+ load ( config ) ;
172+ timer = window . setInterval ( fn_timer , 1000 ) ; // 初始化页面完成后再启动timer读取文件
173+ } catch ( error ) {
174+ console . error ( '[state]: Error:' , error ) ;
175+ }
176+ } )
177+ . catch ( error => console . error ( '[state]: Error getting JSON file:' , error ) ) ;
178+ }
179+ } ) ;
180+
111181 }
112182
113183 function init ( ) {
@@ -119,30 +189,7 @@ state.core = (function () {
119189 sd_versions = data
120190 } ) ;
121191
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-
192+ get_imgs_elem_key ( )
146193
147194 }
148195
@@ -671,36 +718,36 @@ state.core = (function () {
671718 startImportImage : function ( index ) {
672719 index = Number ( index )
673720
721+ console . log ( `-------startImportImage--'${ index } '---------------` )
674722 if ( index + 1 < img_elem_keys . length ) {
675723 //console.log(`---------${img_elem_keys}---------------`)
676- // console.log(`---------${index}-----${img_elem_keys.length}-----------`)
724+ console . log ( `---------' ${ index } ' -----' ${ img_elem_keys . length } ' -----------` )
677725 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)"
726+ "img2img_invisible_img2img_image " : "switch_to_img2img()" ,
727+ "img2img_invisible_img2img_sketch " : "switch_to_sketch()" ,
728+ "img2img_invisible_img2maskimg " : "switch_to_inpaint()" ,
729+ "img2img_invisible_inpaint_sketch " : "switch_to_inpaint_sketch()" ,
730+ "img2img_invisible_img_inpaint_base " : "state.utils.switch_to_img_inpaint()" ,
731+ "img2img_invisible_img_inpaint_mask " : "state.utils.switch_to_img_inpaint()" ,
732+ "img2img_invisible_txt2img_controlnet_ControlNet_input_image " : "state.utils.switch_to_txt2img_ControlNet(0)" ,
733+ "img2img_invisible_img2img_controlnet_ControlNet_input_image " : "state.utils.switch_to_img2img_ControlNet(0)"
686734 }
687735
688736 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 } )`
737+ switch_tab_dict [ `img2img_invisible_txt2img_controlnet_ControlNet -${ i } _input_image` ] = `state.utils.switch_to_txt2img_ControlNet(${ i } )`
738+ switch_tab_dict [ `img2img_invisible_img2img_controlnet_ControlNet -${ i } _input_image` ] = `state.utils.switch_to_img2img_ControlNet(${ i } )`
691739 }
692740
693741 state . utils . sleep ( 300 ) . then ( ( ) => {
694742 try {
695- key = "txt2img_invisible_ " + img_elem_keys [ index + 1 ]
743+ key = "img2img_invisible_ " + img_elem_keys [ index + 1 ]
696744 eval ( switch_tab_dict [ key ] ) // 跳转界面
697745 const button = gradioApp ( ) . getElementById ( key ) ;
698746 button . click ( ) ;
699747 } catch ( error ) {
700748 console . warn ( '[startImportImage]: Error:' , error ) ;
701749 if ( index + 1 < img_elem_keys . length ) {
702750 // 图片组件设置出错了,但是需要继续后续的流程
703-
704751 index = img_elem_keys . length - 1
705752 }
706753 }
@@ -736,7 +783,7 @@ state.core = (function () {
736783 } ,
737784 output_log : function ( msg , msg_style = "" ) {
738785 fetch ( `/lightdiffusionflow/local/output_log?msg=${ msg } &style=${ msg_style } ` ) . then ( ( ) => {
739- gradioApp ( ) . getElementById ( "txt2img_invisible_refresh_log " ) . click ( ) ;
786+ gradioApp ( ) . getElementById ( "img2img_invisible_refresh_log " ) . click ( ) ;
740787 } ) ;
741788 } ,
742789 output_warning : function ( msg , msg_style = "color:Orange;" ) {
0 commit comments