From 1dbcfc672e6bf01837b03ab6dfaa9e831e4df9ff Mon Sep 17 00:00:00 2001 From: dj2ls Date: Tue, 4 Oct 2022 10:55:42 +0200 Subject: [PATCH 1/6] fixed windows rigctld list command --- gui/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/main.js b/gui/main.js index dab66fc9..1683c873 100644 --- a/gui/main.js +++ b/gui/main.js @@ -829,7 +829,7 @@ ipcMain.on('request-check-rigctld',(data)=>{ try { if(os.platform()=='win32' || os.platform()=='win64'){ - var state = exec('tasklist', ['/svc', '/FI', 'ImageName eq rigctld*']) + var state = exec('tasklist', ['/svc', '/FI', '"ImageName eq rigctld*"']) state.on('close', function(code) { if(code == 0){ let Data = { From 81d68076076a33e3436d7beda793a458ecc849be Mon Sep 17 00:00:00 2001 From: dj2ls Date: Wed, 5 Oct 2022 10:56:58 +0200 Subject: [PATCH 2/6] another way of checking if process is running --- gui/main.js | 132 +++++++++++++++++++++++----------------------------- 1 file changed, 58 insertions(+), 74 deletions(-) diff --git a/gui/main.js b/gui/main.js index 1683c873..e750b921 100644 --- a/gui/main.js +++ b/gui/main.js @@ -9,7 +9,9 @@ const { autoUpdater } = require('electron-updater'); const path = require('path'); const fs = require('fs'); const os = require('os'); -const exec = require('child_process').spawn; +const spawn = require('child_process').spawn; +const exec = require('child_process').exec; + const log = require('electron-log'); const mainLog = log.scope('main'); const daemonProcessLog = log.scope('freedata-daemon'); @@ -285,7 +287,7 @@ app.whenReady().then(() => { mainLog.info('Starting freedata-daemon binary'); if(os.platform()=='darwin'){ - daemonProcess = exec(path.join(process.resourcesPath, 'tnc', 'freedata-daemon'), [], + daemonProcess = spawn(path.join(process.resourcesPath, 'tnc', 'freedata-daemon'), [], { cwd: path.join(process.resourcesPath, 'tnc'), }); @@ -310,7 +312,7 @@ app.whenReady().then(() => { }); */ - daemonProcess = exec(path.join(process.resourcesPath, 'tnc', 'freedata-daemon'), [], + daemonProcess = spawn(path.join(process.resourcesPath, 'tnc', 'freedata-daemon'), [], { cwd: path.join(process.resourcesPath, 'tnc'), }); @@ -321,7 +323,7 @@ app.whenReady().then(() => { // for windows the relative path via path.join(__dirname) is not needed for some reason //daemonProcess = exec('\\tnc\\daemon.exe', []) - daemonProcess = exec(path.join(process.resourcesPath, 'tnc', 'freedata-daemon.exe'), [], + daemonProcess = spawn(path.join(process.resourcesPath, 'tnc', 'freedata-daemon.exe'), [], { cwd: path.join(process.resourcesPath, 'tnc'), }); @@ -735,20 +737,20 @@ function close_sub_processes(){ try { if(os.platform()=='win32' || os.platform()=='win64'){ - exec('Taskkill', ['/IM', 'freedata-tnc.exe', '/F']) - exec('Taskkill', ['/IM', 'freedata-daemon.exe', '/F']) + spawn('Taskkill', ['/IM', 'freedata-tnc.exe', '/F']) + spawn('Taskkill', ['/IM', 'freedata-daemon.exe', '/F']) } if(os.platform()=='linux'){ - exec('pkill', ['-9', 'freedata-tnc']) - exec('pkill', ['-9', 'freedata-daemon']) + spawn('pkill', ['-9', 'freedata-tnc']) + spawn('pkill', ['-9', 'freedata-daemon']) } if(os.platform()=='darwin'){ - exec('pkill', ['-9', 'freedata-tnc']) - exec('pkill', ['-9', 'freedata-daemon']) + spawn('pkill', ['-9', 'freedata-tnc']) + spawn('pkill', ['-9', 'freedata-daemon']) } } catch (e) { @@ -779,7 +781,7 @@ ipcMain.on('request-start-rigctld',(event, data)=>{ try{ - exec(data.path, data.parameters); + spawn(data.path, data.parameters); } catch (e) { console.log(e); } @@ -803,18 +805,18 @@ ipcMain.on('request-stop-rigctld',(event,data)=>{ try { if(os.platform()=='win32' || os.platform()=='win64'){ - exec('Taskkill', ['/IM', 'rigctld.exe', '/F']) + spawn('Taskkill', ['/IM', 'rigctld.exe', '/F']) } if(os.platform()=='linux'){ - exec('pkill', ['-9', 'rigctld']) + spawn('pkill', ['-9', 'rigctld']) } if(os.platform()=='darwin'){ - exec('pkill', ['-9', 'rigctld']) + spawn('pkill', ['-9', 'rigctld']) } } catch (e) { @@ -827,68 +829,50 @@ ipcMain.on('request-stop-rigctld',(event,data)=>{ // CHECK RIGCTLD ipcMain.on('request-check-rigctld',(data)=>{ try { + let Data = { + state: "unknown", + }; - if(os.platform()=='win32' || os.platform()=='win64'){ - var state = exec('tasklist', ['/svc', '/FI', '"ImageName eq rigctld*"']) - state.on('close', function(code) { - if(code == 0){ - let Data = { - state: "running", - }; - win.webContents.send('action-check-rigctld', Data); + isRunning('rigctld', (status) => { + if (status){ + Data["state"] = "running"; + } else { + Data["state"] = "unknown"; + } + win.webContents.send('action-check-rigctld', Data); + }) - } else { - let Data = { - state: "unknown", - }; - win.webContents.send('action-check-rigctld', Data); - - } - }); - } - - if(os.platform()=='linux'){ - - var state = exec('pgrep', ['rigctld']) - state.on('close', function(code) { - if(code == 0){ - let Data = { - state: "running", - }; - win.webContents.send('action-check-rigctld', Data); - - } else { - let Data = { - state: "unknown", - }; - win.webContents.send('action-check-rigctld', Data); - - } - }); - - } - - if(os.platform()=='darwin'){ - - var state = exec('pgrep', ['rigctld']) - state.on('close', function(code) { - if(code == 0){ - let Data = { - state: "running", - }; - win.webContents.send('action-check-rigctld', Data); - - } else { - let Data = { - state: "unknown", - }; - win.webContents.send('action-check-rigctld', Data); - - } - }); - - } } catch (e) { mainLog.error(e) } -}); \ No newline at end of file +}); + + + + +// https://stackoverflow.com/a/51084163 +// Function for checking if a process is running or not +/* +isRunning('rigctld', (status) => { + if (status){ + Data["state"] = "running"; + } else { + Data["state"] = "unknown"; + } + win.webContents.send('action-check-rigctld', Data); + }) +*/ +const isRunning = (query, cb) => { + let platform = process.platform; + let cmd = ''; + switch (platform) { + case 'win32' : cmd = `tasklist`; break; + case 'darwin' : cmd = `ps -ax | grep ${query}`; break; + case 'linux' : cmd = `ps -A`; break; + default: break; + } + exec(cmd, (err, stdout, stderr) => { + cb(stdout.toLowerCase().indexOf(query.toLowerCase()) > -1); + }); +} + From a4f133e434123a18a1a049ca6fdbab6c91e3cf24 Mon Sep 17 00:00:00 2001 From: dj2ls Date: Wed, 5 Oct 2022 10:58:38 +0200 Subject: [PATCH 3/6] added stopped information --- gui/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/main.js b/gui/main.js index e750b921..269c84eb 100644 --- a/gui/main.js +++ b/gui/main.js @@ -837,7 +837,7 @@ ipcMain.on('request-check-rigctld',(data)=>{ if (status){ Data["state"] = "running"; } else { - Data["state"] = "unknown"; + Data["state"] = "unknown/stopped"; } win.webContents.send('action-check-rigctld', Data); }) From a7c3764fbe6442aa8a26b93c9e526cd30fc38954 Mon Sep 17 00:00:00 2001 From: dj2ls Date: Wed, 5 Oct 2022 11:00:05 +0200 Subject: [PATCH 4/6] removed stderr --- gui/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/main.js b/gui/main.js index 269c84eb..48a1b3b1 100644 --- a/gui/main.js +++ b/gui/main.js @@ -871,7 +871,7 @@ const isRunning = (query, cb) => { case 'linux' : cmd = `ps -A`; break; default: break; } - exec(cmd, (err, stdout, stderr) => { + exec(cmd, (err, stdout) => { cb(stdout.toLowerCase().indexOf(query.toLowerCase()) > -1); }); } From 0fb632394bbeaf7332ec148533f0ae3ac5e740ac Mon Sep 17 00:00:00 2001 From: dj2ls Date: Wed, 5 Oct 2022 12:19:28 +0200 Subject: [PATCH 5/6] changed 500Hz to 563Hz mode --- gui/src/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/src/index.html b/gui/src/index.html index 8d52e57c..31c72198 100644 --- a/gui/src/index.html +++ b/gui/src/index.html @@ -1185,11 +1185,11 @@
- +
From ee6aeb1f784501a0503b844841bca684c23fea11 Mon Sep 17 00:00:00 2001 From: dj2ls Date: Wed, 5 Oct 2022 12:41:36 +0200 Subject: [PATCH 6/6] fixed tnc state --- gui/preload-main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/preload-main.js b/gui/preload-main.js index c0c52235..58b475bb 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -1788,7 +1788,7 @@ ipcRenderer.on('action-update-daemon-connection', (event, arg) => { }); -ipcRenderer.on('action-update-tnc-connection', (arg) => { +ipcRenderer.on('action-update-tnc-connection', (event, arg) => { if (arg.tnc_connection == "open") { /*