getting appName

This commit is contained in:
antelle 2021-04-24 10:26:07 +02:00
parent 698b559935
commit 5caccbd1f5
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
3 changed files with 20 additions and 14 deletions

View File

@ -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);
}

View File

@ -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();
}
}
}
}

12
package-lock.json generated
View File

@ -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",