@@ -183,80 +183,87 @@ function App () {
183183 * @returns {Promise<object> } the config used
184184 */
185185 this . start = async function ( ) {
186- const configObj = Utils . loadConfig ( ) ;
187- global . config = configObj . fullConf ;
188- const config = global . config ;
189- Utils . checkConfigFile ( configObj ) ;
190-
191- global . defaultModulesDir = config . defaultModulesDir ;
192- defaultModules = require ( `${ global . root_path } /${ global . defaultModulesDir } /defaultmodules` ) ;
193-
194- Log . setLogLevel ( config . logLevel ) ;
195-
196- env = getEnvVarsAsObj ( ) ;
197- // check for deprecated css/custom.css and move it to new location
198- if ( ( ! fs . existsSync ( `${ global . root_path } /${ env . customCss } ` ) ) && ( fs . existsSync ( `${ global . root_path } /css/custom.css` ) ) ) {
199- try {
200- fs . renameSync ( `${ global . root_path } /css/custom.css` , `${ global . root_path } /${ env . customCss } ` ) ;
201- Log . warn ( `WARNING! Your custom css file was moved from ${ global . root_path } /css/custom.css to ${ global . root_path } /${ env . customCss } ` ) ;
202- } catch {
203- Log . warn ( "WARNING! Your custom css file is currently located in the css folder. Please move it to the config folder!" ) ;
186+ try {
187+ const configObj = Utils . loadConfig ( ) ;
188+ global . config = configObj . fullConf ;
189+ const config = global . config ;
190+ Utils . checkConfigFile ( configObj ) ;
191+
192+ global . defaultModulesDir = config . defaultModulesDir ;
193+ defaultModules = require ( `${ global . root_path } /${ global . defaultModulesDir } /defaultmodules` ) ;
194+
195+ Log . setLogLevel ( config . logLevel ) ;
196+
197+ env = getEnvVarsAsObj ( ) ;
198+ // check for deprecated css/custom.css and move it to new location
199+ if ( ( ! fs . existsSync ( `${ global . root_path } /${ env . customCss } ` ) ) && ( fs . existsSync ( `${ global . root_path } /css/custom.css` ) ) ) {
200+ try {
201+ fs . renameSync ( `${ global . root_path } /css/custom.css` , `${ global . root_path } /${ env . customCss } ` ) ;
202+ Log . warn ( `WARNING! Your custom css file was moved from ${ global . root_path } /css/custom.css to ${ global . root_path } /${ env . customCss } ` ) ;
203+ } catch {
204+ Log . warn ( "WARNING! Your custom css file is currently located in the css folder. Please move it to the config folder!" ) ;
205+ }
204206 }
205- }
206207
207- // get the used module positions
208- Utils . getModulePositions ( ) ;
209-
210- let modules = [ ] ;
211- for ( const module of config . modules ) {
212- if ( module . disabled ) continue ;
213- if ( module . module ) {
214- if ( Utils . moduleHasValidPosition ( module . position ) || typeof ( module . position ) === "undefined" ) {
215- // Only add this module to be loaded if it is not a duplicate (repeated instance of the same module)
216- if ( ! modules . includes ( module . module ) ) {
217- modules . push ( module . module ) ;
208+ // get the used module positions
209+ Utils . getModulePositions ( ) ;
210+
211+ let modules = [ ] ;
212+ for ( const module of config . modules ) {
213+ if ( module . disabled ) continue ;
214+ if ( module . module ) {
215+ if ( Utils . moduleHasValidPosition ( module . position ) || typeof ( module . position ) === "undefined" ) {
216+ // Only add this module to be loaded if it is not a duplicate (repeated instance of the same module)
217+ if ( ! modules . includes ( module . module ) ) {
218+ modules . push ( module . module ) ;
219+ }
220+ } else {
221+ Log . warn ( "Invalid module position found for this configuration:" + `\n${ JSON . stringify ( module , null , 2 ) } ` ) ;
218222 }
219223 } else {
220- Log . warn ( "Invalid module position found for this configuration:" + `\n${ JSON . stringify ( module , null , 2 ) } ` ) ;
224+ Log . warn ( "No module name found for this configuration:" + `\n${ JSON . stringify ( module , null , 2 ) } ` ) ;
221225 }
222- } else {
223- Log . warn ( "No module name found for this configuration:" + `\n${ JSON . stringify ( module , null , 2 ) } ` ) ;
224226 }
225- }
226227
227- setGlobalDispatcher ( new Agent ( { connect : { timeout : fetch_timeout } } ) ) ;
228+ setGlobalDispatcher ( new Agent ( { connect : { timeout : fetch_timeout } } ) ) ;
228229
229- await loadModules ( modules ) ;
230+ await loadModules ( modules ) ;
230231
231- httpServer = new Server ( configObj ) ;
232- const { app, io } = await httpServer . open ( ) ;
233- Log . log ( "Server started ..." ) ;
232+ httpServer = new Server ( configObj ) ;
233+ const { app, io } = await httpServer . open ( ) ;
234+ Log . log ( "Server started ..." ) ;
234235
235- const nodePromises = [ ] ;
236- for ( let nodeHelper of nodeHelpers ) {
237- nodeHelper . setExpressApp ( app ) ;
238- nodeHelper . setSocketIO ( io ) ;
236+ const nodePromises = [ ] ;
237+ for ( let nodeHelper of nodeHelpers ) {
238+ nodeHelper . setExpressApp ( app ) ;
239+ nodeHelper . setSocketIO ( io ) ;
239240
240- try {
241- nodePromises . push ( nodeHelper . start ( ) ) ;
242- } catch ( error ) {
243- Log . error ( `Error when starting node_helper for module ${ nodeHelper . name } :` ) ;
244- Log . error ( error ) ;
241+ try {
242+ nodePromises . push ( nodeHelper . start ( ) ) ;
243+ } catch ( error ) {
244+ Log . error ( `Error when starting node_helper for module ${ nodeHelper . name } :` ) ;
245+ Log . error ( error ) ;
246+ }
245247 }
246- }
247248
248- const results = await Promise . allSettled ( nodePromises ) ;
249+ const results = await Promise . allSettled ( nodePromises ) ;
249250
250- // Log errors that happened during async node_helper startup
251- results . forEach ( ( result ) => {
252- if ( result . status === "rejected" ) {
253- Log . error ( result . reason ) ;
254- }
255- } ) ;
251+ // Log errors that happened during async node_helper startup
252+ results . forEach ( ( result ) => {
253+ if ( result . status === "rejected" ) {
254+ Log . error ( result . reason ) ;
255+ }
256+ } ) ;
256257
257- Log . log ( "Sockets connected & modules started ..." ) ;
258+ Log . log ( "Sockets connected & modules started ..." ) ;
258259
259- return global . config ;
260+ return global . config ;
261+ } catch {
262+ const int32 = new Int32Array ( new SharedArrayBuffer ( 4 ) ) ;
263+ // wait 1000ms before exiting so that child processes (e.g. systeminformation) have some additional time
264+ Atomics . wait ( int32 , 0 , 0 , 1000 ) ;
265+ process . exit ( 1 ) ;
266+ }
260267 } ;
261268
262269 /**
@@ -328,20 +335,6 @@ function App () {
328335 await this . stop ( ) ;
329336 process . exit ( 0 ) ;
330337 } ) ;
331-
332- /**
333- *
334- * @param {number } ms milliseconds to wait
335- */
336- function blockingSleep ( ms ) {
337- const int32 = new Int32Array ( new SharedArrayBuffer ( 4 ) ) ;
338- Atomics . wait ( int32 , 0 , 0 , ms ) ;
339- }
340-
341- process . on ( "exit" , ( ) => {
342- // wait before exiting so that child processes (e.g. systeminformation) have some additional time
343- blockingSleep ( 1000 ) ;
344- } ) ;
345338}
346339
347340module . exports = new App ( ) ;
0 commit comments