@@ -34,7 +34,7 @@ var processList=[]
3434let in_docker_container = false
3535
3636// the generated module list form
37- let formdata
37+ let formdata = null
3838
3939const Configurator_in_config_file = false
4040
@@ -151,34 +151,15 @@ async function setupServer(expressApp, sortOrder){
151151}
152152
153153async function buildFormData ( /*NodeHelper,*/ sortOrder ) {
154+ // used to do this inline, but it blocked MM startup,
155+ // takes minutes to sync the initial module list
154156 // get the latest data from the 3rd party repo
155- //console.log("entered buildformdata")
156- const response = await fetch ( modules_url ) ;
157- if ( ! response . ok ) {
158- const message = `An error occured: ${ response . status } ` ;
159- throw new Error ( message ) ;
160- }
161- //console.log("fetch conmpleted")
162- // we need the json
163- const responseData = await response . json ( ) ;
164- //console.log("have form data l="+responseData.length)
165-
166- // Extract modules array from the new API structure
167- const modulesArray = responseData . modules || responseData ;
168-
169- // format in category and in category sorted as requested (date or time)
170- let data = await formatter ( modulesArray , sortOrder , true /*local_debug*/ )
171- //console.log("back from formatter")
172- // make the form for the installer page
173- let newformdata = fs . readFileSync ( module_form_template ) + '"categories":' + JSON . stringify ( data . categories , null , 2 ) + formTail
174- // save it for page load
175- formdata = newformdata
176- // write it out for next time start
177- // write it out to be loaded by installer page
178- fs . writeFileSync ( module_selector_form , newformdata )
179- // write out the updated url hash (adds/deletes done twice a day)
180- fs . writeFileSync ( module_url_hash , JSON . stringify ( data . hash , null , 2 ) )
181- // async, return something
157+ // execute the 3rd party module jsonform creator in the background
158+ const cmdstring = "node " + __dirname + "/formatter.js " + sortOrder
159+ //console.log("cmdstring="+cmdstring+" cwd="+process.cwd())
160+ exec ( cmdstring , { cwd : __dirname } )
161+ // indicate we are working on new data
162+ formdata = null ;
182163 return true
183164}
184165
@@ -222,14 +203,24 @@ function handleConnection(socket, type) {
222203 console . log ( "cancel requested" )
223204 console . log ( "cancel received, closing installer" )
224205 socket . emit ( "close" )
225- // setTimeout(()=>{process.exit(1)}, 3000)
226206 }
227207 } ) ;
228208
229209 // when the page askes for form
230210 socket . on ( "getForm" , ( ) => {
231211 if ( local_debug )
232- console . log ( "form requested" )
212+ console . log ( "installer form requested" )
213+ // if we haven't loaded the 3rd party modules form for installer
214+ if ( ! formdata ) {
215+ // if the file exists
216+ if ( fs . statSync ( module_selector_form ) )
217+ // load it as text
218+ formdata = fs . readFileSync ( module_selector_form , "utf8" ) ;
219+ else
220+ // for didn't exist, don't send junk
221+ // user will have to hit refresh to load the page html which will request again
222+ return
223+ }
233224 // send it via socket io, string data
234225 socket . emit ( "json" , "'" + formdata + "'" ) ;
235226 } ) ;
0 commit comments