@lvce-editor/shared-process 0.25.11 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/package.json +4 -4
  2. package/src/parts/ContentSecurityPolicyDiffWorker/ContentSecurityPolicyDiffWorker.js +2 -0
  3. package/src/parts/ContentSecurityPolicyEmbedsWorker/ContentSecurityPolicyEmbedsWorker.js +2 -0
  4. package/src/parts/EmbedsProcess/EmbedsProcess.js +22 -0
  5. package/src/parts/EmbedsProcessPath/EmbedsProcessPath.js +3 -0
  6. package/src/parts/GetHeaders/GetHeaders.js +4 -0
  7. package/src/parts/GetHeadersEmbedsWorker/GetHeadersEmbedsWorker.js +9 -0
  8. package/src/parts/GetPortTuple/GetPortTuple.js +6 -0
  9. package/src/parts/HandleElectronMessagePort/HandleElectronMessagePort.js +8 -0
  10. package/src/parts/HandleIpc/HandleIpc.js +2 -20
  11. package/src/parts/HandleMessage/HandleMessage.js +16 -0
  12. package/src/parts/HandleMessagePortForEmbedsProcess/HandleMessagePortForEmbedsProcess.ipc.js +5 -0
  13. package/src/parts/HandleMessagePortForEmbedsProcess/HandleMessagePortForEmbedsProcess.js +8 -0
  14. package/src/parts/HandleMessagePortForProcessExplorer/HandleMessagePortForProcessExplorer.ipc.js +5 -0
  15. package/src/parts/HandleMessagePortForProcessExplorer/HandleMessagePortForProcessExplorer.js +8 -0
  16. package/src/parts/HandleMessagePortForSearchProcess/HandleMessagePortForSearchProcess.ipc.js +5 -0
  17. package/src/parts/HandleMessagePortForSearchProcess/HandleMessagePortForSearchProcess.js +8 -0
  18. package/src/parts/IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js +3 -0
  19. package/src/parts/IpcChildWithNodeMessagePort/IpcChildWithNodeMessagePort.js +5 -1
  20. package/src/parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js +13 -4
  21. package/src/parts/LaunchEmbedsProcess/LaunchEmbedsProcess.js +21 -0
  22. package/src/parts/LaunchProcessExplorer/LaunchProcessExplorer.js +21 -0
  23. package/src/parts/LaunchPtyHost/LaunchPtyHost.js +37 -0
  24. package/src/parts/LaunchSearchProcess/LaunchSearchProcess.js +15 -0
  25. package/src/parts/Module/Module.js +6 -2
  26. package/src/parts/ModuleId/ModuleId.js +3 -0
  27. package/src/parts/ModuleMap/ModuleMap.js +6 -0
  28. package/src/parts/Platform/Platform.js +3 -3
  29. package/src/parts/ProcessExplorer/ProcessExplorer.js +13 -0
  30. package/src/parts/ProcessExplorerPath/ProcessExplorerPath.js +3 -0
  31. package/src/parts/PtyHost/PtyHost.js +2 -35
  32. package/src/parts/SearchProcess/SearchProcess.js +18 -0
  33. package/src/parts/SearchProcessPath/SearchProcessPath.js +3 -0
  34. package/src/parts/TemporaryMessagePort/TemporaryMessagePort.js +17 -0
  35. package/src/parts/AddAccurateMemoryUsage/AddAccurateMemoryUsage.js +0 -8
  36. package/src/parts/CreatePidMap/CreatePidMap.js +0 -5
  37. package/src/parts/GetAccurateMemoryUsage/GetAccurateMemoryUsage.js +0 -39
  38. package/src/parts/GetPsOutput/GetPsOutput.js +0 -18
  39. package/src/parts/ListProcessGetName/ListProcessGetName.js +0 -56
  40. package/src/parts/ListProcessesWithMemoryUsage/ListProcessesWithMemoryUsage.ipc.js +0 -5
  41. package/src/parts/ListProcessesWithMemoryUsage/ListProcessesWithMemoryUsage.js +0 -11
  42. package/src/parts/ListProcessesWithMemoryUsageUnix/ListProcessesWithMemoryUsageUnix.js +0 -20
  43. package/src/parts/ListProcessesWithMemoryUsageWindows/ListProcessesWithMemoryUsageWindows.js +0 -48
  44. package/src/parts/LoadWindowsProcessTree/LoadWindowsProcessTree.js +0 -13
  45. package/src/parts/ParseMemory/ParseMemory.js +0 -10
  46. package/src/parts/ParsePsOutput/ParsePsOutput.js +0 -47
  47. package/src/parts/WindowsProcessTree/WindowsProcessTree.js +0 -26
  48. package/src/parts/WindowsProcessTreeDataFlag/WindowsProcessTreeDataFlag.js +0 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.25.11",
3
+ "version": "0.26.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -18,12 +18,12 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@lvce-editor/assert": "^1.2.0",
21
- "@lvce-editor/extension-host-helper-process": "0.25.11",
22
- "@lvce-editor/ipc": "^3.7.1",
21
+ "@lvce-editor/extension-host-helper-process": "0.26.0",
22
+ "@lvce-editor/ipc": "^5.1.0",
23
23
  "@lvce-editor/json-rpc": "^1.3.0",
24
24
  "@lvce-editor/jsonc-parser": "^1.2.0",
25
25
  "@lvce-editor/pretty-error": "^1.5.0",
26
- "@lvce-editor/pty-host": "0.25.11",
26
+ "@lvce-editor/pty-host": "0.26.0",
27
27
  "@lvce-editor/verror": "^1.2.0",
28
28
  "@lvce-editor/web-socket-server": "^1.1.0",
29
29
  "debug": "^4.3.4",
@@ -0,0 +1,2 @@
1
+ import * as GetContentSecurityPolicy from '../GetContentSecurityPolicy/GetContentSecurityPolicy.js';
2
+ export const value = GetContentSecurityPolicy.getContentSecurityPolicy([`default-src 'none'`, `script-src 'self'`]);
@@ -0,0 +1,2 @@
1
+ import * as GetContentSecurityPolicy from '../GetContentSecurityPolicy/GetContentSecurityPolicy.js';
2
+ export const value = GetContentSecurityPolicy.getContentSecurityPolicy([`default-src 'none'`, `script-src 'self'`]);
@@ -0,0 +1,22 @@
1
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
2
+ import * as LaunchEmbedsProcess from '../LaunchEmbedsProcess/LaunchEmbedsProcess.js';
3
+ export const state = {
4
+ /**
5
+ * @type {any}
6
+ */
7
+ ipc: undefined,
8
+ };
9
+ export const getOrCreate = async () => {
10
+ if (!state.ipc) {
11
+ state.ipc = LaunchEmbedsProcess.launchEmbedsProcess();
12
+ }
13
+ return state.ipc;
14
+ };
15
+ export const invoke = async (method, ...params) => {
16
+ const ipc = await getOrCreate();
17
+ return JsonRpc.invoke(ipc, method, ...params);
18
+ };
19
+ export const invokeAndTransfer = async (method, transfer, ...params) => {
20
+ const ipc = await getOrCreate();
21
+ return JsonRpc.invokeAndTransfer(ipc, transfer, method, ...params);
22
+ };
@@ -0,0 +1,3 @@
1
+ import * as Path from '../Path/Path.js';
2
+ import * as Root from '../Root/Root.js';
3
+ export const embedsProcessPath = Path.join(Root.root, 'packages', 'embeds-process', 'src', 'embedsProcessMain.js');
@@ -1,5 +1,6 @@
1
1
  import { extname } from 'path';
2
2
  import * as GetHeadersDefault from '../GetHeadersDefault/GetHeadersDefault.js';
3
+ import * as GetHeadersEmbedsWorker from '../GetHeadersEmbedsWorker/GetHeadersEmbedsWorker.js';
3
4
  import * as GetHeadersExtensionHostWorker from '../GetHeadersExtensionHostWorker/GetHeadersExtensionHostWorker.js';
4
5
  import * as GetHeadersMainFrame from '../GetHeadersMainFrame/GetHeadersMainFrame.js';
5
6
  import * as GetHeadersOtherWorker from '../GetHeadersOtherWorker/GetHeadersOtherWorker.js';
@@ -30,6 +31,9 @@ const getExtraHeaders = (pathName, fileExtension) => {
30
31
  if (pathName.endsWith('syntaxHighlightingWorkerMain.js') || pathName.endsWith('syntaxHighlightingWorkerMain.ts')) {
31
32
  return GetHeadersSyntaxHighlightingWorker.getHeadersSyntaxHighlightingWorker();
32
33
  }
34
+ if (pathName.endsWith('embedsWorkerMain.js') || pathName.endsWith('embedsWorkerMain.ts')) {
35
+ return GetHeadersEmbedsWorker.getHeadersEmbedsWorker();
36
+ }
33
37
  if (pathName.endsWith('WorkerMain.js') || pathName.endsWith('WorkerMain.ts')) {
34
38
  return GetHeadersOtherWorker.getHeadersOtherWorker(pathName);
35
39
  }
@@ -0,0 +1,9 @@
1
+ import * as ContentSecurityPolicyEmbedsWorker from '../ContentSecurityPolicyEmbedsWorker/ContentSecurityPolicyEmbedsWorker.js';
2
+ import * as CrossOriginEmbedderPolicy from '../CrossOriginEmbedderPolicy/CrossOriginEmbedderPolicy.js';
3
+ import * as HttpHeader from '../HttpHeader/HttpHeader.js';
4
+ export const getHeadersEmbedsWorker = () => {
5
+ return {
6
+ [HttpHeader.CrossOriginEmbedderPolicy]: CrossOriginEmbedderPolicy.value,
7
+ [HttpHeader.ContentSecurityPolicy]: ContentSecurityPolicyEmbedsWorker.value,
8
+ };
9
+ };
@@ -0,0 +1,6 @@
1
+ import * as TemporaryMessagePort from '../TemporaryMessagePort/TemporaryMessagePort.js';
2
+ // workaround for MessageChannelMain not being available in utility process
3
+ export const getPortTuple = async () => {
4
+ const { port1, port2 } = await TemporaryMessagePort.getPortTuple();
5
+ return { port1, port2 };
6
+ };
@@ -2,6 +2,8 @@ import * as Assert from '../Assert/Assert.js';
2
2
  import * as HandleIpc from '../HandleIpc/HandleIpc.js';
3
3
  import * as IpcChild from '../IpcChild/IpcChild.js';
4
4
  import * as IpcChildType from '../IpcChildType/IpcChildType.js';
5
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js';
6
+ const mainProcessSpecialId = -5;
5
7
  export const handleElectronMessagePort = async (messagePort, ...params) => {
6
8
  Assert.object(messagePort);
7
9
  const ipc = await IpcChild.listen({
@@ -9,6 +11,12 @@ export const handleElectronMessagePort = async (messagePort, ...params) => {
9
11
  messagePort,
10
12
  });
11
13
  HandleIpc.handleIpc(ipc);
14
+ if (params[0] === mainProcessSpecialId) {
15
+ // update ipc with message port ipc that supports transferring objects
16
+ // @ts-ignore
17
+ ParentIpc.state.ipc = ipc;
18
+ }
12
19
  // TODO find better way to associate configuration with ipc
20
+ // @ts-ignore
13
21
  ipc.windowId = params[1];
14
22
  };
@@ -1,22 +1,4 @@
1
- import * as Callback from '../Callback/Callback.js';
2
- import * as Command from '../Command/Command.js';
3
- import * as JsonRpc from '../JsonRpc/JsonRpc.js';
4
- import * as PrettyError from '../PrettyError/PrettyError.js';
5
- import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js';
6
- import * as RequiresSocket from '../RequiresSocket/RequiresSocket.js';
7
- import * as ShouldLogError from '../ShouldLogError/ShouldLogError.js';
8
- const preparePrettyError = PrettyError.prepare;
9
- const logError = (error, prettyError) => {
10
- if (ShouldLogError.shouldLogError(error)) {
11
- PrintPrettyError.printPrettyError(prettyError, `[shared-process] `);
12
- }
13
- };
1
+ import * as HandleMessage from '../HandleMessage/HandleMessage.js';
14
2
  export const handleIpc = (ipc) => {
15
- const handleMessage = (message) => {
16
- return JsonRpc.handleJsonRpcMessage(ipc, message, Command.execute, Callback.resolve, preparePrettyError, logError, RequiresSocket.requiresSocket);
17
- };
18
- ipc.on('message', handleMessage);
19
- if (ipc.start) {
20
- ipc.start();
21
- }
3
+ ipc.on('message', HandleMessage.handleMessage);
22
4
  };
@@ -0,0 +1,16 @@
1
+ import * as Callback from '../Callback/Callback.js';
2
+ import * as Command from '../Command/Command.js';
3
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
4
+ import * as PrettyError from '../PrettyError/PrettyError.js';
5
+ import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js';
6
+ import * as RequiresSocket from '../RequiresSocket/RequiresSocket.js';
7
+ import * as ShouldLogError from '../ShouldLogError/ShouldLogError.js';
8
+ const preparePrettyError = PrettyError.prepare;
9
+ const logError = (error, prettyError) => {
10
+ if (ShouldLogError.shouldLogError(error)) {
11
+ PrintPrettyError.printPrettyError(prettyError, `[shared-process] `);
12
+ }
13
+ };
14
+ export const handleMessage = (event) => {
15
+ return JsonRpc.handleJsonRpcMessage(event.target, event.data, Command.execute, Callback.resolve, preparePrettyError, logError, RequiresSocket.requiresSocket);
16
+ };
@@ -0,0 +1,5 @@
1
+ import * as HandleMessagePortForEmbedsProcess from './HandleMessagePortForEmbedsProcess.js';
2
+ export const name = 'HandleMessagePortForEmbedsProcess';
3
+ export const Commands = {
4
+ handleMessagePortForEmbedsProcess: HandleMessagePortForEmbedsProcess.handleMessagePortForEmbedsProcess,
5
+ };
@@ -0,0 +1,8 @@
1
+ import * as Assert from '../Assert/Assert.js';
2
+ import * as EmbedsProcess from '../EmbedsProcess/EmbedsProcess.js';
3
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
4
+ export const handleMessagePortForEmbedsProcess = async (port) => {
5
+ Assert.object(port);
6
+ const embedsProcess = await EmbedsProcess.getOrCreate();
7
+ await JsonRpc.invokeAndTransfer(embedsProcess, [port], 'HandleElectronMessagePort.handleElectronMessagePort');
8
+ };
@@ -0,0 +1,5 @@
1
+ import * as HandleMessagePortForProcessExplorer from './HandleMessagePortForProcessExplorer.js';
2
+ export const name = 'HandleMessagePortForProcessExplorer';
3
+ export const Commands = {
4
+ handleMessagePortForProcessExplorer: HandleMessagePortForProcessExplorer.handleMessagePortForProcessExplorer,
5
+ };
@@ -0,0 +1,8 @@
1
+ import * as Assert from '../Assert/Assert.js';
2
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
3
+ import * as ProcessExplorer from '../ProcessExplorer/ProcessExplorer.js';
4
+ export const handleMessagePortForProcessExplorer = async (port) => {
5
+ Assert.object(port);
6
+ const ipc = await ProcessExplorer.getOrCreate();
7
+ await JsonRpc.invokeAndTransfer(ipc, [port], 'HandleElectronMessagePort.handleElectronMessagePort');
8
+ };
@@ -0,0 +1,5 @@
1
+ import * as HandleMessagePortForSearchProcess from './HandleMessagePortForSearchProcess.js';
2
+ export const name = 'HandleMessagePortForSearchProcess';
3
+ export const Commands = {
4
+ handleMessagePortForSearchProcess: HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess,
5
+ };
@@ -0,0 +1,8 @@
1
+ import * as Assert from '../Assert/Assert.js';
2
+ import * as SearchProcess from '../SearchProcess/SearchProcess.js';
3
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
4
+ export const handleMessagePortForSearchProcess = async (port) => {
5
+ Assert.object(port);
6
+ const ipc = await SearchProcess.getOrCreate();
7
+ await JsonRpc.invokeAndTransfer(ipc, [port], 'HandleElectronMessagePort.handleElectronMessagePort');
8
+ };
@@ -40,6 +40,9 @@ export const wrap = (messagePort) => {
40
40
  send(message) {
41
41
  this.messagePort.postMessage(message);
42
42
  },
43
+ sendAndTransfer(message, transfer) {
44
+ this.messagePort.postMessage(message, transfer);
45
+ },
43
46
  dispose() {
44
47
  this.messagePort.close();
45
48
  },
@@ -16,7 +16,11 @@ export const wrap = (messagePort) => {
16
16
  if (event === 'message') {
17
17
  const wrappedListener = (event) => {
18
18
  const actualData = getActualData(event);
19
- listener(actualData);
19
+ const syntheticEvent = {
20
+ data: actualData,
21
+ target: this,
22
+ };
23
+ listener(syntheticEvent);
20
24
  };
21
25
  this.messagePort.on(event, wrappedListener);
22
26
  }
@@ -1,3 +1,4 @@
1
+ import * as GetPortTuple from '../GetPortTuple/GetPortTuple.js';
1
2
  import * as ParentIpc from '../ParentIpc/ParentIpc.js';
2
3
  import * as TemporaryMessagePort from '../TemporaryMessagePort/TemporaryMessagePort.js';
3
4
  const ElectronUtilityProcess = 3;
@@ -9,10 +10,14 @@ export const create = async (options) => {
9
10
  method: ElectronUtilityProcess,
10
11
  noReturn: true,
11
12
  });
13
+ const { port1, port2 } = await GetPortTuple.getPortTuple();
12
14
  // TODO use uuid instead of name
13
- const port = await TemporaryMessagePort.create(options.name);
14
- port.name = options.name;
15
- return port;
15
+ await TemporaryMessagePort.sendTo(options.name, port2);
16
+ port1.start();
17
+ return port1;
18
+ };
19
+ export const signal = (port) => {
20
+ port.start();
16
21
  };
17
22
  export const wrap = (port) => {
18
23
  return {
@@ -30,7 +35,11 @@ export const wrap = (port) => {
30
35
  break;
31
36
  case 'message':
32
37
  const wrapped = (event) => {
33
- listener(event.data);
38
+ const syntheticEvent = {
39
+ data: event.data,
40
+ target: this,
41
+ };
42
+ listener(syntheticEvent);
34
43
  };
35
44
  this.port.on(event, wrapped);
36
45
  break;
@@ -0,0 +1,21 @@
1
+ import * as EmbedsProcessPath from '../EmbedsProcessPath/EmbedsProcessPath.js';
2
+ import * as GetPortTuple from '../GetPortTuple/GetPortTuple.js';
3
+ import * as HandleIpc from '../HandleIpc/HandleIpc.js';
4
+ import * as IpcParent from '../IpcParent/IpcParent.js';
5
+ import * as IpcParentType from '../IpcParentType/IpcParentType.js';
6
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
7
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js';
8
+ export const launchEmbedsProcess = async () => {
9
+ const embedsProcess = await IpcParent.create({
10
+ method: IpcParentType.ElectronUtilityProcess,
11
+ path: EmbedsProcessPath.embedsProcessPath,
12
+ argv: [],
13
+ stdio: 'inherit',
14
+ name: 'Embeds Process',
15
+ });
16
+ HandleIpc.handleIpc(embedsProcess);
17
+ const { port1, port2 } = await GetPortTuple.getPortTuple();
18
+ await JsonRpc.invokeAndTransfer(embedsProcess, [port1], 'HandleElectronMessagePort.handleElectronMessagePort', /* isElectron */ true);
19
+ await ParentIpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', [port2]);
20
+ return embedsProcess;
21
+ };
@@ -0,0 +1,21 @@
1
+ import * as GetPortTuple from '../GetPortTuple/GetPortTuple.js';
2
+ import * as HandleIpc from '../HandleIpc/HandleIpc.js';
3
+ import * as IpcParent from '../IpcParent/IpcParent.js';
4
+ import * as IpcParentType from '../IpcParentType/IpcParentType.js';
5
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
6
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js';
7
+ import * as ProcessExplorerPath from '../ProcessExplorerPath/ProcessExplorerPath.js';
8
+ export const launchProcessExplorer = async () => {
9
+ const ipc = await IpcParent.create({
10
+ method: IpcParentType.ElectronUtilityProcess,
11
+ path: ProcessExplorerPath.processExplorerPath,
12
+ argv: [],
13
+ stdio: 'inherit',
14
+ name: 'Process Process',
15
+ });
16
+ HandleIpc.handleIpc(ipc);
17
+ const { port1, port2 } = await GetPortTuple.getPortTuple();
18
+ await JsonRpc.invokeAndTransfer(ipc, [port1], 'HandleElectronMessagePort.handleElectronMessagePort');
19
+ await ParentIpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', [port2]);
20
+ return ipc;
21
+ };
@@ -0,0 +1,37 @@
1
+ import exitHook from 'exit-hook';
2
+ import * as Debug from '../Debug/Debug.js';
3
+ import * as HandleIpc from '../HandleIpc/HandleIpc.js';
4
+ import * as IpcParent from '../IpcParent/IpcParent.js';
5
+ import * as PtyHostPath from '../PtyHostPath/PtyHostPath.js';
6
+ import * as PtyHostState from '../PtyHostState/PtyHostState.js';
7
+ const cleanUpAll = () => {
8
+ if (PtyHostState.state.ipc) {
9
+ PtyHostState.state.ipc.dispose();
10
+ PtyHostState.state.ipc = undefined;
11
+ }
12
+ };
13
+ const handleProcessExit = () => {
14
+ Debug.debug('shared process exit, clean terminals');
15
+ cleanUpAll();
16
+ };
17
+ export const launchPtyHost = async (method) => {
18
+ exitHook(handleProcessExit);
19
+ const ptyHostPath = await PtyHostPath.getPtyHostPath();
20
+ const ptyHost = await IpcParent.create({
21
+ method,
22
+ path: ptyHostPath,
23
+ argv: [],
24
+ stdio: 'inherit',
25
+ name: 'Terminal Process',
26
+ });
27
+ HandleIpc.handleIpc(ptyHost);
28
+ const handleClose = () => {
29
+ // @ts-ignore
30
+ ptyHost.off('close', handleClose);
31
+ PtyHostState.state.ipc = undefined;
32
+ PtyHostState.state.ptyHostPromise = undefined;
33
+ };
34
+ ptyHost.on('close', handleClose);
35
+ PtyHostState.state.ipc = ptyHost;
36
+ return ptyHost;
37
+ };
@@ -0,0 +1,15 @@
1
+ import * as SearchProcessPath from '../SearchProcessPath/SearchProcessPath.js';
2
+ import * as HandleIpc from '../HandleIpc/HandleIpc.js';
3
+ import * as IpcParent from '../IpcParent/IpcParent.js';
4
+ import * as IpcParentType from '../IpcParentType/IpcParentType.js';
5
+ export const launchSearchProcess = async () => {
6
+ const embedsProcess = await IpcParent.create({
7
+ method: IpcParentType.ElectronUtilityProcess,
8
+ path: SearchProcessPath.searchProcessPath,
9
+ argv: [],
10
+ stdio: 'inherit',
11
+ name: 'Search Process',
12
+ });
13
+ HandleIpc.handleIpc(embedsProcess);
14
+ return embedsProcess;
15
+ };
@@ -79,8 +79,6 @@ export const load = (moduleId) => {
79
79
  return import('../InstallExtension/InstallExtension.ipc.js');
80
80
  case ModuleId.IsAutoUpdateSupported:
81
81
  return import('../IsAutoUpdateSupported/IsAutoUpdateSupported.ipc.js');
82
- case ModuleId.ListProcessesWithMemoryUsage:
83
- return import('../ListProcessesWithMemoryUsage/ListProcessesWithMemoryUsage.ipc.js');
84
82
  case ModuleId.OpenExternal:
85
83
  return import('../OpenExternal/OpenExternal.ipc.js');
86
84
  case ModuleId.OpenNativeFolder:
@@ -129,6 +127,8 @@ export const load = (moduleId) => {
129
127
  return import('../HandleWindowAllClosed/HandleWindowAllClosed.ipc.js');
130
128
  case ModuleId.HandleMessagePortForTerminalProcess:
131
129
  return import('../HandleMessagePortForTerminalProcess/HandleMessagePortForTerminalProcess.ipc.js');
130
+ case ModuleId.HandleMessagePortForEmbedsProcess:
131
+ return import('../HandleMessagePortForEmbedsProcess/HandleMessagePortForEmbedsProcess.ipc.js');
132
132
  case ModuleId.TemporaryMessagePort:
133
133
  return import('../TemporaryMessagePort/TemporaryMessagePort.ipc.js');
134
134
  case ModuleId.GetElectronFileResponse:
@@ -145,6 +145,10 @@ export const load = (moduleId) => {
145
145
  return import('../ElectronWebContentsViewFunctions/ElectronWebContentsViewFunctions.ipc.js');
146
146
  case ModuleId.ContentSecurityPolicy:
147
147
  return import('../ContentSecurityPolicy/ContentSecurityPolicy.ipc.js');
148
+ case ModuleId.HandleMessagePortForProcessExplorer:
149
+ return import('../HandleMessagePortForProcessExplorer/HandleMessagePortForProcessExplorer.ipc.js');
150
+ case ModuleId.HandleMessagePortForSearchProcess:
151
+ return import('../HandleMessagePortForSearchProcess/HandleMessagePortForSearchProcess.ipc.js');
148
152
  default:
149
153
  throw new Error(`module ${moduleId} not found`);
150
154
  }
@@ -74,3 +74,6 @@ export const ElectronWebContentsView = 67;
74
74
  export const ElectronWebContentsViewFunctions = 68;
75
75
  export const HandleRequestTest = 69;
76
76
  export const ContentSecurityPolicy = 70;
77
+ export const HandleMessagePortForEmbedsProcess = 72;
78
+ export const HandleMessagePortForProcessExplorer = 73;
79
+ export const HandleMessagePortForSearchProcess = 74;
@@ -324,6 +324,12 @@ export const getModuleId = (commandId) => {
324
324
  return ModuleId.HandleRequestTest;
325
325
  case 'ContentSecurityPolicy.set':
326
326
  return ModuleId.ContentSecurityPolicy;
327
+ case 'HandleMessagePortForEmbedsProcess.handleMessagePortForEmbedsProcess':
328
+ return ModuleId.HandleMessagePortForEmbedsProcess;
329
+ case 'HandleMessagePortForProcessExplorer.handleMessagePortForProcessExplorer':
330
+ return ModuleId.HandleMessagePortForProcessExplorer;
331
+ case 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess':
332
+ return ModuleId.HandleMessagePortForSearchProcess;
327
333
  default:
328
334
  throw new CommandNotFoundError(commandId);
329
335
  }
@@ -41,9 +41,9 @@ export const getAppImageName = () => {
41
41
  export const getSetupName = () => {
42
42
  return 'Lvce-Setup';
43
43
  };
44
- export const version = '0.25.11';
45
- export const commit = 'da5cd48';
46
- export const date = '2024-04-15T19:21:13.000Z';
44
+ export const version = '0.26.0';
45
+ export const commit = '019c142';
46
+ export const date = '2024-04-20T21:44:51.000Z';
47
47
  export const getVersion = () => {
48
48
  return version;
49
49
  };
@@ -0,0 +1,13 @@
1
+ import * as LaunchProcessExplorer from '../LaunchProcessExplorer/LaunchProcessExplorer.js';
2
+ export const state = {
3
+ /**
4
+ * @type {any}
5
+ */
6
+ ipc: undefined,
7
+ };
8
+ export const getOrCreate = async () => {
9
+ if (!state.ipc) {
10
+ state.ipc = LaunchProcessExplorer.launchProcessExplorer();
11
+ }
12
+ return state.ipc;
13
+ };
@@ -0,0 +1,3 @@
1
+ import * as Path from '../Path/Path.js';
2
+ import * as Root from '../Root/Root.js';
3
+ export const processExplorerPath = Path.join(Root.root, 'packages', 'process-explorer', 'src', 'processExplorerMain.js');
@@ -1,45 +1,12 @@
1
- import exitHook from 'exit-hook';
2
1
  import * as Debug from '../Debug/Debug.js';
3
- import * as HandleIpc from '../HandleIpc/HandleIpc.js';
4
- import * as IpcParent from '../IpcParent/IpcParent.js';
5
2
  import * as IpcParentType from '../IpcParentType/IpcParentType.js';
6
3
  import * as JsonRpc from '../JsonRpc/JsonRpc.js';
7
- import * as PtyHostPath from '../PtyHostPath/PtyHostPath.js';
4
+ import * as LaunchPtyHost from '../LaunchPtyHost/LaunchPtyHost.js';
8
5
  import * as PtyHostState from '../PtyHostState/PtyHostState.js';
9
- const cleanUpAll = () => {
10
- if (PtyHostState.state.ipc) {
11
- PtyHostState.state.ipc.dispose();
12
- PtyHostState.state.ipc = undefined;
13
- }
14
- };
15
- const handleProcessExit = () => {
16
- Debug.debug('shared process exit, clean terminals');
17
- cleanUpAll();
18
- };
19
- const createPtyHost = async (method) => {
20
- exitHook(handleProcessExit);
21
- const ptyHostPath = await PtyHostPath.getPtyHostPath();
22
- const ptyHost = await IpcParent.create({
23
- method,
24
- path: ptyHostPath,
25
- argv: [],
26
- stdio: 'inherit',
27
- name: 'Terminal Process',
28
- });
29
- HandleIpc.handleIpc(ptyHost);
30
- const handleClose = () => {
31
- ptyHost.off('close', handleClose);
32
- PtyHostState.state.ipc = undefined;
33
- PtyHostState.state.ptyHostPromise = undefined;
34
- };
35
- ptyHost.on('close', handleClose);
36
- PtyHostState.state.ipc = ptyHost;
37
- return ptyHost;
38
- };
39
6
  export const getOrCreate = (method = IpcParentType.NodeForkedProcess) => {
40
7
  Debug.debug('creating pty host');
41
8
  if (!PtyHostState.state.ptyHostPromise) {
42
- PtyHostState.state.ptyHostPromise = createPtyHost(method);
9
+ PtyHostState.state.ptyHostPromise = LaunchPtyHost.launchPtyHost(method);
43
10
  }
44
11
  return PtyHostState.state.ptyHostPromise;
45
12
  };
@@ -0,0 +1,18 @@
1
+ import * as LaunchSearchProcess from '../LaunchSearchProcess/LaunchSearchProcess.js';
2
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js';
3
+ export const state = {
4
+ /**
5
+ * @type {any}
6
+ */
7
+ ipc: undefined,
8
+ };
9
+ export const getOrCreate = async () => {
10
+ if (!state.ipc) {
11
+ state.ipc = LaunchSearchProcess.launchSearchProcess();
12
+ }
13
+ return state.ipc;
14
+ };
15
+ export const invoke = async (method, ...params) => {
16
+ const ipc = await getOrCreate();
17
+ return JsonRpc.invoke(ipc, method, ...params);
18
+ };
@@ -0,0 +1,3 @@
1
+ import * as Path from '../Path/Path.js';
2
+ import * as Root from '../Root/Root.js';
3
+ export const searchProcessPath = Path.join(Root.root, 'packages', 'search-process', 'src', 'searchProcessMain.js');
@@ -1,5 +1,6 @@
1
1
  import * as ParentIpc from '../ParentIpc/ParentIpc.js';
2
2
  import * as Assert from '../Assert/Assert.js';
3
+ import * as Id from '../Id/Id.js';
3
4
  export const state = {
4
5
  ports: Object.create(null),
5
6
  };
@@ -14,6 +15,22 @@ export const create = async (name) => {
14
15
  port.start();
15
16
  return port;
16
17
  };
18
+ export const getPortTuple = async () => {
19
+ const id1 = `${Id.create()}`;
20
+ const id2 = `${Id.create()}`;
21
+ await ParentIpc.invoke('TemporaryMessagePort.createPortTuple', id1, id2);
22
+ const port1 = state.ports[id1];
23
+ const port2 = state.ports[id2];
24
+ return {
25
+ port1,
26
+ port2,
27
+ };
28
+ };
29
+ export const sendTo = async (name, port) => {
30
+ Assert.string(name);
31
+ Assert.object(port);
32
+ await ParentIpc.invokeAndTransfer('TemporaryMessagePort.sendTo', [port], name);
33
+ };
17
34
  export const handlePort = (port, name) => {
18
35
  Assert.string(name);
19
36
  Assert.object(port);
@@ -1,8 +0,0 @@
1
- import * as GetAccurateMemoryUsage from '../GetAccurateMemoryUsage/GetAccurateMemoryUsage.js';
2
- export const addAccurateMemoryUsage = async (process) => {
3
- const accurateMemoryUsage = await GetAccurateMemoryUsage.getAccurateMemoryUsage(process.pid);
4
- return {
5
- ...process,
6
- memory: accurateMemoryUsage,
7
- };
8
- };
@@ -1,5 +0,0 @@
1
- import * as ParentIpc from '../ParentIpc/ParentIpc.js';
2
- export const createPidMap = async () => {
3
- const pidMap = await ParentIpc.invoke('CreatePidMap.createPidMap');
4
- return pidMap;
5
- };
@@ -1,39 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import * as Assert from '../Assert/Assert.js';
4
- import * as EncodingType from '../EncodingType/EncodingType.js';
5
- import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js';
6
- import * as IsEsrchError from '../IsEsrchError/IsEsrchError.js';
7
- import * as ParseMemory from '../ParseMemory/ParseMemory.js';
8
- import * as Platform from '../Platform/Platform.js';
9
- import { VError } from '../VError/VError.js';
10
- const getContent = async (pid) => {
11
- try {
12
- const filePath = join('/proc', `${pid}`, 'statm');
13
- const content = await readFile(filePath, EncodingType.Utf8);
14
- return content;
15
- }
16
- catch (error) {
17
- if (IsEnoentError.isEnoentError(error) || IsEsrchError.isEsrchError(error)) {
18
- return '';
19
- }
20
- throw error;
21
- }
22
- };
23
- export const getAccurateMemoryUsage = async (pid) => {
24
- try {
25
- Assert.number(pid);
26
- if (Platform.isMacOs) {
27
- return 0;
28
- }
29
- const content = await getContent(pid);
30
- if (!content) {
31
- return -1;
32
- }
33
- const memory = ParseMemory.parseMemory(content);
34
- return memory;
35
- }
36
- catch (error) {
37
- throw new VError(error, 'Failed to get accurate memory usage');
38
- }
39
- };
@@ -1,18 +0,0 @@
1
- import { execFile as _execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
- import * as Signal from '../Signal/Signal.js';
4
- import { VError } from '../VError/VError.js';
5
- const execFile = promisify(_execFile);
6
- export const getPsOutput = async () => {
7
- try {
8
- const { stdout } = await execFile('ps', ['-ax', '-o', 'pid=,ppid=,pcpu=,pmem=,command=']);
9
- return stdout.trim();
10
- }
11
- catch (error) {
12
- // @ts-ignore
13
- if (error && error.signal === Signal.SIGINT) {
14
- return '';
15
- }
16
- throw new VError(error, `Failed to execute ps`);
17
- }
18
- };
@@ -1,56 +0,0 @@
1
- import * as Assert from '../Assert/Assert.js';
2
- export const getName = (pid, cmd, rootPid, pidMap) => {
3
- Assert.number(pid);
4
- Assert.string(cmd);
5
- Assert.number(rootPid);
6
- Assert.object(pidMap);
7
- if (pid === rootPid) {
8
- return 'main';
9
- }
10
- if (cmd.includes('--type=zygote')) {
11
- return 'zygote';
12
- }
13
- if (cmd.includes('--type=gpu-process')) {
14
- return 'gpu-process';
15
- }
16
- if (cmd.includes('extensionHostMain.js')) {
17
- return 'extension-host';
18
- }
19
- if (cmd.includes('ptyHostMain.js')) {
20
- return 'pty-host';
21
- }
22
- if (cmd.includes('--lvce-window-kind=process-explorer')) {
23
- return 'process-explorer';
24
- }
25
- if (pid in pidMap) {
26
- return pidMap[pid] || `<unknown>`;
27
- }
28
- if (cmd.includes('--type=renderer')) {
29
- return `renderer`;
30
- }
31
- if (cmd.includes('--type=utility')) {
32
- return 'utility';
33
- }
34
- if (cmd.includes('tsserver.js')) {
35
- return 'tsserver.js';
36
- }
37
- if (cmd.includes('typingsInstaller.js')) {
38
- return 'typingsInstaller.js';
39
- }
40
- if (cmd.includes('extensionHostHelperProcessMain.js')) {
41
- return 'extension-host-helper-process';
42
- }
43
- if (cmd.includes('/bin/rg') || cmd.includes('rg.exe')) {
44
- return 'ripgrep';
45
- }
46
- if (cmd.startsWith('bash')) {
47
- return 'bash';
48
- }
49
- if (cmd.startsWith(`/opt/sublime_text/sublime_text `)) {
50
- return 'sublime-text';
51
- }
52
- if (cmd.includes('\\conhost.exe')) {
53
- return 'conhost.exe';
54
- }
55
- return `${cmd}`;
56
- };
@@ -1,5 +0,0 @@
1
- import * as ListProcessesWithMemoryUsage from './ListProcessesWithMemoryUsage.js';
2
- export const name = 'ListProcessesWithMemoryUsage';
3
- export const Commands = {
4
- listProcessesWithMemoryUsage: ListProcessesWithMemoryUsage.listProcessesWithMemoryUsage,
5
- };
@@ -1,11 +0,0 @@
1
- import * as Platform from '../Platform/Platform.js';
2
- const getModule = () => {
3
- if (Platform.isWindows) {
4
- return import('../ListProcessesWithMemoryUsageWindows/ListProcessesWithMemoryUsageWindows.js');
5
- }
6
- return import('../ListProcessesWithMemoryUsageUnix/ListProcessesWithMemoryUsageUnix.js');
7
- };
8
- export const listProcessesWithMemoryUsage = async (rootPid) => {
9
- const module = await getModule();
10
- return module.listProcessesWithMemoryUsage(rootPid);
11
- };
@@ -1,20 +0,0 @@
1
- import * as AddAccurateMemoryUsage from '../AddAccurateMemoryUsage/AddAccurateMemoryUsage.js';
2
- import * as CreatePidMap from '../CreatePidMap/CreatePidMap.js';
3
- import * as GetPsOutput from '../GetPsOutput/GetPsOutput.js';
4
- import * as HasPositiveMemoryUsage from '../HasPositiveMemoryUsage/HasPositiveMemoryUsage.js';
5
- import * as ParsePsOutput from '../ParsePsOutput/ParsePsOutput.js';
6
- export const listProcessesWithMemoryUsage = async (rootPid) => {
7
- // console.time('getPsOutput')
8
- const stdout = await GetPsOutput.getPsOutput();
9
- const pidMap = await CreatePidMap.createPidMap();
10
- // console.log({ stdout })
11
- // console.timeEnd('getPsOutput')
12
- // console.time('parsePsOutput')
13
- const parsed = ParsePsOutput.parsePsOutput(stdout, rootPid, pidMap);
14
- // console.timeEnd('parsePsOutput')
15
- // console.time('addAccurateMemoryUsage')
16
- const parsedWithAccurateMemoryUsage = await Promise.all(parsed.map(AddAccurateMemoryUsage.addAccurateMemoryUsage));
17
- // console.timeEnd('addAccurateMemoryUsage')
18
- const filtered = parsedWithAccurateMemoryUsage.filter(HasPositiveMemoryUsage.hasPositiveMemoryUsage);
19
- return filtered;
20
- };
@@ -1,48 +0,0 @@
1
- // listProcesses windows implementation based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/node/ps.ts (License MIT)
2
- import { VError } from '../VError/VError.js';
3
- import * as ListProcessGetName from '../ListProcessGetName/ListProcessGetName.js';
4
- import * as WindowsProcessTree from '../WindowsProcessTree/WindowsProcessTree.js';
5
- import * as WindowsProcessTreeDataFlag from '../WindowsProcessTreeDataFlag/WindowsProcessTreeDataFlag.js';
6
- import * as CreatePidMap from '../CreatePidMap/CreatePidMap.js';
7
- /**
8
- * @param {import('@vscode/windows-process-tree').IProcessCpuInfo} item
9
- * @param {number} rootPid
10
- * @param {object} pidMap
11
- */
12
- const toResultItem = (item, rootPid, pidMap) => {
13
- return {
14
- name: ListProcessGetName.getName(item.pid, item.commandLine, rootPid, pidMap),
15
- pid: item.pid,
16
- ppid: item.ppid,
17
- memory: item.memory,
18
- cmd: item.commandLine,
19
- };
20
- };
21
- /**
22
- *
23
- * @param {import('@vscode/windows-process-tree').IProcessCpuInfo[]} completeProcessList
24
- * @param {number} rootPid
25
- */
26
- const toResult = (completeProcessList, rootPid, pidMap) => {
27
- const results = [];
28
- for (const item of completeProcessList) {
29
- results.push(toResultItem(item, rootPid, pidMap));
30
- }
31
- return results;
32
- };
33
- export const listProcessesWithMemoryUsage = async (rootPid) => {
34
- try {
35
- const processList = await WindowsProcessTree.getProcessList(rootPid, WindowsProcessTreeDataFlag.CommandLine | WindowsProcessTreeDataFlag.Memory);
36
- if (!processList) {
37
- throw new VError(`Root process ${rootPid} not found`);
38
- }
39
- const pidMap = await CreatePidMap.createPidMap();
40
- const completeProcessList = await WindowsProcessTree.addCpuUsage(processList);
41
- const result = toResult(completeProcessList, rootPid, pidMap);
42
- return result;
43
- }
44
- catch (error) {
45
- // @ts-ignore
46
- throw new VError(error, `Failed to list processes`);
47
- }
48
- };
@@ -1,13 +0,0 @@
1
- import * as IsDlOpenError from '../IsDlOpenError/IsDlOpenError.js';
2
- import { VError } from '../VError/VError.js';
3
- export const loadWindowProcessTree = async () => {
4
- try {
5
- return await import('@vscode/windows-process-tree');
6
- }
7
- catch (error) {
8
- if (IsDlOpenError.isDlOpenError(error)) {
9
- throw new VError(`Failed to load windows process tree: The native module "@vscode/windows-process-tree" is not compatible with this node version and must be compiled against a matching electron version using electron-rebuild`);
10
- }
11
- throw new VError(error, `Failed to load windows process tree`);
12
- }
13
- };
@@ -1,10 +0,0 @@
1
- import * as Character from '../Character/Character.js';
2
- export const parseMemory = (content) => {
3
- const trimmedContent = content.trim();
4
- const numberBlocks = trimmedContent.split(Character.Space);
5
- const pageSize = 4096;
6
- const rss = Number.parseInt(numberBlocks[1]) * pageSize;
7
- const shared = Number.parseInt(numberBlocks[2]) * pageSize;
8
- const memory = rss - shared;
9
- return memory;
10
- };
@@ -1,47 +0,0 @@
1
- // parse ps output based on vscode https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/node/ps.ts (License MIT)
2
- import * as Assert from '../Assert/Assert.js';
3
- import * as Character from '../Character/Character.js';
4
- import * as ListProcessGetName from '../ListProcessGetName/ListProcessGetName.js';
5
- import * as SplitLines from '../SplitLines/SplitLines.js';
6
- const PID_CMD = /^\s*(\d+)\s+(\d+)\s+([\d.]+)\s+([\d.]+)\s+(.+)$/s;
7
- const parsePsOutputLine = (line) => {
8
- Assert.string(line);
9
- const matches = PID_CMD.exec(line.trim());
10
- if (matches && matches.length === 6) {
11
- return {
12
- pid: Number.parseInt(matches[1]),
13
- ppid: Number.parseInt(matches[2]),
14
- cmd: matches[5],
15
- // load: parseInt(matches[3]),
16
- // mem: parseInt(matches[4]),
17
- };
18
- }
19
- throw new Error(`line could not be parsed: ${line}`);
20
- };
21
- export const parsePsOutput = (stdout, rootPid, pidMap) => {
22
- Assert.string(stdout);
23
- Assert.number(rootPid);
24
- Assert.object(pidMap);
25
- if (stdout === Character.EmptyString) {
26
- return [];
27
- }
28
- const lines = SplitLines.splitLines(stdout);
29
- const result = [];
30
- const depthMap = Object.create(null);
31
- depthMap[rootPid] = 1;
32
- const parsedLines = lines.map(parsePsOutputLine);
33
- for (const parsedLine of parsedLines) {
34
- const { pid, ppid, cmd } = parsedLine;
35
- const depth = pid === rootPid ? 1 : depthMap[ppid];
36
- if (!depth) {
37
- continue;
38
- }
39
- result.push({
40
- ...parsedLine,
41
- depth,
42
- name: ListProcessGetName.getName(pid, cmd, rootPid, pidMap),
43
- });
44
- depthMap[pid] = depth + 1;
45
- }
46
- return result;
47
- };
@@ -1,26 +0,0 @@
1
- // @ts-nocheck
2
- import * as LoadWindowsProcessTree from '../LoadWindowsProcessTree/LoadWindowsProcessTree.js';
3
- import * as Promises from '../Promises/Promises.js';
4
- /**
5
- *
6
- * @param {number} rootPid
7
- * @param {WindowsProcessTree.ProcessDataFlag} flags
8
- * @returns {Promise<WindowsProcessTree.IProcessInfo[] | undefined>}
9
- */
10
- export const getProcessList = async (rootPid, flags) => {
11
- const WindowsProcessTree = await LoadWindowsProcessTree.loadWindowProcessTree();
12
- const { resolve, promise } = Promises.withResolvers();
13
- WindowsProcessTree.getProcessList(rootPid, resolve, flags);
14
- return promise;
15
- };
16
- /**
17
- *
18
- * @param {WindowsProcessTree.IProcessInfo[]} processList
19
- * @returns Promise< WindowsProcessTree.IProcessCpuInfo[]>
20
- */
21
- export const addCpuUsage = async (processList) => {
22
- const WindowsProcessTree = await LoadWindowsProcessTree.loadWindowProcessTree();
23
- const { resolve, promise } = Promises.withResolvers();
24
- WindowsProcessTree.getProcessCpuUsage(processList, resolve);
25
- return promise;
26
- };
@@ -1,3 +0,0 @@
1
- export const None = 0;
2
- export const Memory = 1;
3
- export const CommandLine = 2;