import { app } from "electron" ; import path from "path" ; import { fork , ChildProcess } from "child_process" ; let child = null ; export async function startThoriumServer ( ) { return new Promise < void > ( function startServer ( resolve , reject ) { if ( child ) return ; child = fork ( path . join ( app . getAppPath ( ) , "dist/index.js" ) , [ ] , { env : { FORK : "1" , NODE_ENV : "production" , NODE_PATH : path . join ( app . getAppPath ( ) , "dist" ) , ... process . env , } , silent : true , } ) ; child . on ( "message" , function ( msg ) { if ( msg === "ready" ) { resolve ( ) ; } else { reject ( ) ; } } ) ; child . stdout ?. on ( "data" , function ( data ) { const message = data . toString ( ) ; console . info ( message ) ; } ) ; child . stderr ?. on ( "data" , function ( data ) { const error = data . toString ( ) ; if ( error . includes ( "DeprecationWarning: Buffer()" ) ) return ; console . error ( error ) ; } ) ; child . on ( "error" , function ( err ) { console . error ( err ) ; } ) ; app . on ( "before-quit" , ( ) => { if ( child ) child . kill ( ) ; } ) ; } ) ; } export function stopThoriumServer ( ) { if ( child ) child . kill ( ) ; child = null ; }