film-exif/src/electron/wait-inferno.js

29 lines
608 B
JavaScript

const net = require('net');
const port = process.env.PORT ? (process.env.PORT - 100) : 3000;
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) => {
if (error) {
console.error(error);
return;
}
setTimeout(tryConnection, 1000);
});