Add code to get process IDs for daemon on Windows
This commit is contained in:
parent
31e3b3006b
commit
3e33f78235
1 changed files with 14 additions and 2 deletions
16
app/main.js
16
app/main.js
|
@ -47,6 +47,19 @@ function openItem(fullPath) {
|
||||||
child.unref();
|
child.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPidsForProcessName(name) {
|
||||||
|
if (process.platform == 'windows') {
|
||||||
|
const tasklistOut = child_process.execSync('tasklist',
|
||||||
|
['/fi', `Imagename eq ${name}.exe`, '/nh'],
|
||||||
|
{encoding: 'utf8'}
|
||||||
|
).stdout;
|
||||||
|
return tasklistOut.match(/[^\n]+/g).map((line) => line.split(/\s+/)[1]); // Second column of every non-empty line
|
||||||
|
} else {
|
||||||
|
const pgrepOut = child_process.spawnSync('pgrep', ['-x', name], {encoding: 'utf8'}).stdout;
|
||||||
|
return pgrepOut.match(/\d+/g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow () {
|
||||||
win = new BrowserWindow({backgroundColor: '#155b4a'})
|
win = new BrowserWindow({backgroundColor: '#155b4a'})
|
||||||
win.maximize()
|
win.maximize()
|
||||||
|
@ -137,8 +150,7 @@ function launchDaemonIfNotRunning() {
|
||||||
function forceKillAllDaemonsAndQuit() {
|
function forceKillAllDaemonsAndQuit() {
|
||||||
console.log('Attempting to force kill any running lbrynet-daemon instances...');
|
console.log('Attempting to force kill any running lbrynet-daemon instances...');
|
||||||
|
|
||||||
const fgrepOut = child_process.spawnSync('pgrep', ['-x', 'lbrynet-daemon'], {encoding: 'utf8'}).stdout;
|
const daemonPids = getPidsForProcessName('lbrynet-daemon');
|
||||||
const daemonPids = fgrepOut.match(/\d+/g);
|
|
||||||
if (!daemonPids) {
|
if (!daemonPids) {
|
||||||
console.log('No lbrynet-daemon found running.');
|
console.log('No lbrynet-daemon found running.');
|
||||||
quitNow();
|
quitNow();
|
||||||
|
|
Loading…
Add table
Reference in a new issue