Skip to content

Instantly share code, notes, and snippets.

@cjus
Last active June 9, 2018 23:59
Show Gist options
  • Save cjus/b96d300fec707c0b903edd8c3e806a0f to your computer and use it in GitHub Desktop.
Save cjus/b96d300fec707c0b903edd8c3e806a0f to your computer and use it in GitHub Desktop.
Electron Wait React
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