mirror of https://github.com/keeweb/keeweb
moved spawn to the main process
parent
7d1e343d25
commit
92da783e82
@ -0,0 +1,60 @@
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
module.exports = {
|
||||
spawnProcess
|
||||
};
|
||||
|
||||
function spawnProcess(e, config) {
|
||||
return new Promise((resolve) => {
|
||||
const ps = spawn(config.cmd, config.args, config.options);
|
||||
[ps.stdin, ps.stdout, ps.stderr].forEach((s) => s.setEncoding('utf-8'));
|
||||
let stderr = '';
|
||||
let stdout = '';
|
||||
ps.stderr.on('data', (d) => {
|
||||
stderr += d.toString('utf-8');
|
||||
if (config.throwOnStdErr) {
|
||||
try {
|
||||
ps.kill();
|
||||
} catch {}
|
||||
}
|
||||
});
|
||||
ps.stdout.on('data', (d) => {
|
||||
stdout += d.toString('utf-8');
|
||||
});
|
||||
ps.on('close', (code) => {
|
||||
if (config.trim !== false) {
|
||||
stdout = stdout.trim();
|
||||
stderr = stderr.trim();
|
||||
}
|
||||
resolve?.({
|
||||
code,
|
||||
stdout,
|
||||
stderr
|
||||
});
|
||||
resolve = null;
|
||||
});
|
||||
ps.on('error', (err) => {
|
||||
resolve?.({
|
||||
err
|
||||
});
|
||||
resolve = null;
|
||||
});
|
||||
if (config.data) {
|
||||
try {
|
||||
ps.stdin.end(config.data);
|
||||
} catch (err) {
|
||||
resolve?.({
|
||||
err
|
||||
});
|
||||
resolve = null;
|
||||
}
|
||||
}
|
||||
process.nextTick(() => {
|
||||
// it should work without destroy, but a process doesn't get launched
|
||||
// xubuntu-desktop 19.04 / xfce
|
||||
// see https://github.com/keeweb/keeweb/issues/1234
|
||||
ps.stdin.destroy();
|
||||
});
|
||||
return ps;
|
||||
});
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
const { ipcMain } = require('electron');
|
||||
const { hardwareEncrypt, hardwareDecrypt } = require('./ipc-handlers/hardware-crypto');
|
||||
const { spawnProcess } = require('./ipc-handlers/spawn-process');
|
||||
const { nativeModuleCall } = require('./ipc-handlers/native-module-host-proxy');
|
||||
|
||||
module.exports.setupIpcHandlers = () => {
|
||||
ipcMain.handle('hardwareEncrypt', hardwareEncrypt);
|
||||
ipcMain.handle('hardwareDecrypt', hardwareDecrypt);
|
||||
ipcMain.handle('spawnProcess', spawnProcess);
|
||||
ipcMain.on('nativeModuleCall', nativeModuleCall);
|
||||
};
|
||||
|
Loading…
Reference in New Issue