From e0cdaf91aa6d7ab98e84350f2f28fb3a4f86a585 Mon Sep 17 00:00:00 2001 From: Victor Tseng Date: Tue, 16 May 2023 23:54:31 +0800 Subject: parse sing-box `processPath` into `process` (#37) clash-api for sing-box use `processPath` field which is the full-path of the captured process. - On Windows: `\Device\HarddiskVolume3\Path\To\Program.exe` - On Linux: `/path/to/program (username)` grab the last part of the full path and render as `process`. --- src/api/connections.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/api') diff --git a/src/api/connections.ts b/src/api/connections.ts index a9b8eaf..fd0901b 100644 --- a/src/api/connections.ts +++ b/src/api/connections.ts @@ -29,6 +29,7 @@ export type ConnectionItem = { destinationPort: string; host: string; process?: string; + processPath?: string; sniffHost?: string; }; upload: number; @@ -50,6 +51,14 @@ function appendData(s: string) { let o: ConnectionsData; try { o = JSON.parse(s); + o.connections.forEach(conn => { + let m = conn.metadata; + if (m.process == null) { + if (m.processPath != null) { + m.process = m.processPath.replace(/^.*[/\\](.*)$/, "$1"); + } + } + }); } catch (err) { // eslint-disable-next-line no-console console.log('JSON.parse error', JSON.parse(s)); -- cgit v1.3.1