const { spawn } = require('child_process')
const electronBinary = require('electron')

const electronArgs = ['.']

if(process.platform === 'linux'){
    electronArgs.push('--no-sandbox', '--disable-gpu')
}

const child = spawn(electronBinary, electronArgs, {
    stdio: 'inherit',
    env: {
        ...process.env,
        LAUNCHER_SMOKE_EXIT: '1',
        LAUNCHER_SMOKE_EXIT_DELAY_MS: process.env.LAUNCHER_SMOKE_EXIT_DELAY_MS || '5000'
    }
})

child.on('exit', (code, signal) => {
    if(signal != null){
        process.exit(1)
    }
    process.exit(code ?? 0)
})
