I'm with a problem after using electron-builder or electron-packager, I belive that the problem is at asar. If I execute the code with electron . it works nicely, but if I build an executable with electron-builder or electron-packager, when I call a child process it opens another instance of the program, and don't do what was expected.
With electron .
When I click on "Converter" button it starts to convert the .xml files to PDFs as expected.
Built version
Code
Click:
e.onclick = () => {
let path = document.getElementById("pasta").files[0].path.replace(/\\/g, '/');
let c1 = cp.spawn(process.execPath, [__dirname + '/child.js'], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
c1.send(path);
c1.on('message', m => {
if(m.name === 'start') {
document.getElementById("start").className += " disabled";
}
if(m.name === 'process') {
document.getElementById("bar").style.width = m.data + "%";
}
if(m.name === 'end') {
document.getElementById("start").className = document.getElementById("start").className.replace(" disabled", '');
document.getElementById("bar").style.width = "0%";
window.alert("Conversão relizada com sucesso!");
}
});
}
Child.js
'use strict';
const pdf = require('../pdfCreator.js');
const timer = require('timers');
process.on('message', m => {
let path = m;
process.send({name: 'start'});
pdf.readDir(path, status => {
let percent = parseInt((status.now/status.total) * 100);
process.send({name: 'process', data: percent});
}, () => {
timer.setTimeout(() => {
process.send({name:'end'});
}, 1000);
});
});