Last active
June 9, 2018 23:59
-
-
Save cjus/b96d300fec707c0b903edd8c3e806a0f to your computer and use it in GitHub Desktop.
Electron Wait React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net'); | |
const port = process.env.PORT ? (process.env.PORT - 100) : 5000; | |
process.env.ELECTRON_START_URL = `http://localhost:${port}`; | |
const client = new net.Socket(); | |
let startedElectron = false; | |
const tryConnection = () => client.connect({port: port}, () => { | |
client.end(); | |
if (!startedElectron) { | |
console.log('starting electron'); | |
startedElectron = true; | |
const exec = require('child_process').exec; | |
exec('npm run electron'); | |
} | |
}); | |
tryConnection(); | |
client.on('error', (_error) => { | |
setTimeout(tryConnection, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment