From 5caccbd1f5e068f2d5af639e76bc70cf1f55da58 Mon Sep 17 00:00:00 2001 From: antelle Date: Sat, 24 Apr 2021 10:26:07 +0200 Subject: [PATCH] getting appName --- .../browser-extension-connector.js | 2 +- desktop/scripts/util/process-utils.js | 20 ++++++++++++------- package-lock.json | 12 +++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/desktop/scripts/ipc-handlers/browser-extension-connector.js b/desktop/scripts/ipc-handlers/browser-extension-connector.js index 196e125c..f63c6d9f 100644 --- a/desktop/scripts/ipc-handlers/browser-extension-connector.js +++ b/desktop/scripts/ipc-handlers/browser-extension-connector.js @@ -289,7 +289,7 @@ async function processFirstMessageFromSocket(socket, message) { return; } - appName = parentProcessInfo.commandLine.split('/').pop(); + appName = parentProcessInfo.appName; appName = appName[0].toUpperCase() + appName.substr(1); } diff --git a/desktop/scripts/util/process-utils.js b/desktop/scripts/util/process-utils.js index 08f92b2b..d0a54abb 100644 --- a/desktop/scripts/util/process-utils.js +++ b/desktop/scripts/util/process-utils.js @@ -10,13 +10,13 @@ function getProcessInfo(pid) { 'where', `ProcessId=${pid}`, 'get', - 'ProcessId,ParentProcessId,CommandLine', + 'ProcessId,ParentProcessId,ExecutablePath', '/format:value' ]; parseOutput = parseWmicOutput; } else { cmd = '/bin/ps'; - args = ['-opid=,ppid=,command=', '-p', pid]; + args = ['-opid=,ppid=,comm=', '-p', pid]; parseOutput = parsePsOutput; } const ps = childProcess.spawn(cmd, args); @@ -31,8 +31,8 @@ function getProcessInfo(pid) { if (result.pid !== pid) { throw new Error(`PID mismatch: ${result.pid} <> ${pid}`); } - if (!result.commandLine) { - throw new Error(`Could not get command line for process ${pid}`); + if (!result.appName) { + throw new Error(`Could not get app name for process ${pid}`); } resolve(result); } catch (e) { @@ -53,7 +53,8 @@ function parsePsOutput(output) { return { pid: match[1] | 0, parentPid: match[2] | 0, - commandLine: match[3] + execPath: match[3], + appName: match[3].split('/').pop() }; } @@ -62,7 +63,7 @@ function parseWmicOutput(output) { const keyMap = { ProcessId: 'pid', ParentProcessId: 'parentPid', - CommandLine: 'commandLine' + ExecutablePath: 'execPath' }; for (const line of output.split(/\n/)) { const match = line.trim().match(/^([^=]+)=(.*)$/); @@ -70,7 +71,12 @@ function parseWmicOutput(output) { const [, key, value] = match; const mapped = keyMap[key]; if (mapped) { - result[mapped] = mapped.endsWith('id') ? value | 0 : value; + if (mapped.endsWith('id')) { + result[mapped] = value | 0; + } else if (mapped === 'execPath') { + result[mapped] = value.replace(/^"([^"]+)"/g, '$1'); + result.appName = value.split('\\').pop(); + } } } } diff --git a/package-lock.json b/package-lock.json index b878c850..fc43d4d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@babel/plugin-proposal-optional-chaining": "^7.13.8", "@babel/preset-env": "^7.13.9", "@fortawesome/fontawesome-free": "^5.15.2", - "@keeweb/keeweb-native-messaging-host": "https://github.com/keeweb/keeweb-connect/releases/download/0.0.3/keeweb-native-messaging-host.tgz", + "@keeweb/keeweb-native-messaging-host": "https://github.com/keeweb/keeweb-connect/releases/download/0.0.4/keeweb-native-messaging-host.tgz", "@keeweb/keeweb-native-modules": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.11.6/keeweb-native-modules.tgz", "adm-zip": "^0.5.3", "argon2-browser": "1.15.3", @@ -1470,9 +1470,9 @@ } }, "node_modules/@keeweb/keeweb-native-messaging-host": { - "version": "0.0.3", - "resolved": "https://github.com/keeweb/keeweb-connect/releases/download/0.0.3/keeweb-native-messaging-host.tgz", - "integrity": "sha512-ofKt+qaqsODgYzzm4AyJPt08N97TS5Vz96M77ARisjGSQxQyz4shYbPGk+ax1tPBSMN7aXZf4bLAxlgDdPbjXQ==", + "version": "0.0.4", + "resolved": "https://github.com/keeweb/keeweb-connect/releases/download/0.0.4/keeweb-native-messaging-host.tgz", + "integrity": "sha512-JHeT35YGx6JNiWcXVMpiVPmh3UqGeYleePxYbyC9FDrb2x5gPUD99conTVl2sAwSMcypf3XJ27Vnl4djzcXfsA==", "license": "MIT" }, "node_modules/@keeweb/keeweb-native-modules": { @@ -22484,8 +22484,8 @@ } }, "@keeweb/keeweb-native-messaging-host": { - "version": "https://github.com/keeweb/keeweb-connect/releases/download/0.0.3/keeweb-native-messaging-host.tgz", - "integrity": "sha512-ofKt+qaqsODgYzzm4AyJPt08N97TS5Vz96M77ARisjGSQxQyz4shYbPGk+ax1tPBSMN7aXZf4bLAxlgDdPbjXQ==" + "version": "https://github.com/keeweb/keeweb-connect/releases/download/0.0.4/keeweb-native-messaging-host.tgz", + "integrity": "sha512-JHeT35YGx6JNiWcXVMpiVPmh3UqGeYleePxYbyC9FDrb2x5gPUD99conTVl2sAwSMcypf3XJ27Vnl4djzcXfsA==" }, "@keeweb/keeweb-native-modules": { "version": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.11.6/keeweb-native-modules.tgz",