@lvce-editor/shared-process 0.26.1 → 0.26.2
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.
- package/package.json +4 -4
- package/src/parts/ConnectIpcToElectron/ConnectIpcToElectron.js +2 -1
- package/src/parts/EmbedsProcess/EmbedsProcess.js +0 -9
- package/src/parts/HandleElectronMessagePort/HandleElectronMessagePort.js +10 -21
- package/src/parts/HandleIncomingIpc/HandleIncomingIpc.js +44 -0
- package/src/parts/HandleIpc/HandleIpc.js +22 -1
- package/src/parts/HandleIpcEmbedsProcess/HandleIpcEmbedsProcess.js +12 -0
- package/src/parts/HandleIpcExtensionHostHelperProcess/HandleIpcExtensionHostHelperProcess.js +30 -0
- package/src/parts/HandleIpcModule/HandleIpcModule.js +27 -0
- package/src/parts/HandleIpcProcessExplorer/HandleIpcProcessExplorer.js +14 -0
- package/src/parts/HandleIpcSearchProcess/HandleIpcSearchProcess.js +1 -0
- package/src/parts/HandleIpcSharedProcess/HandleIpcSharedProcess.js +41 -0
- package/src/parts/HandleIpcTerminalProcess/HandleIpcTerminalProcess.js +24 -0
- package/src/parts/HandleMessagePortForEmbedsProcess/HandleMessagePortForEmbedsProcess.js +6 -7
- package/src/parts/HandleMessagePortForExtensionHostHelperProcess/HandleMessagePortForExtensionHostHelperProcess.js +5 -5
- package/src/parts/HandleMessagePortForProcessExplorer/HandleMessagePortForProcessExplorer.js +4 -7
- package/src/parts/HandleMessagePortForTerminalProcess/HandleMessagePortForTerminalProcess.js +4 -8
- package/src/parts/HandleWebSocketForExtensionHostHelperProcess/HandleWebSocketForExtensionHostHelperProcess.js +4 -8
- package/src/parts/HandleWebSocketForSharedProcess/HandleWebSocketForSharedProcess.js +4 -15
- package/src/parts/HandleWebSocketForTerminalProcess/HandleWebSocketForTerminalProcess.js +4 -17
- package/src/parts/IpcId/IpcId.js +8 -0
- package/src/parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js +17 -3
- package/src/parts/LaunchEmbedsProcess/LaunchEmbedsProcess.js +1 -0
- package/src/parts/LaunchProcessExplorer/LaunchProcessExplorer.js +1 -0
- package/src/parts/LaunchPtyHost/LaunchPtyHost.js +10 -9
- package/src/parts/ModuleMap/ModuleMap.js +1 -1
- package/src/parts/Platform/Platform.js +3 -3
- package/src/parts/SendIncomingIpc/SendIncomingIpc.js +46 -0
- package/src/parts/TemporaryMessagePort/TemporaryMessagePort.ipc.js +1 -1
- package/src/parts/TemporaryMessagePort/TemporaryMessagePort.js +12 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.2",
|
|
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.26.
|
|
22
|
-
"@lvce-editor/ipc": "^
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.26.2",
|
|
22
|
+
"@lvce-editor/ipc": "^7.2.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.26.
|
|
26
|
+
"@lvce-editor/pty-host": "0.26.2",
|
|
27
27
|
"@lvce-editor/verror": "^1.2.0",
|
|
28
28
|
"@lvce-editor/web-socket-server": "^1.1.0",
|
|
29
29
|
"debug": "^4.3.4",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as GetPortTuple from '../GetPortTuple/GetPortTuple.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
2
3
|
import * as JsonRpc from '../JsonRpc/JsonRpc.js';
|
|
3
4
|
import * as ParentIpc from '../ParentIpc/ParentIpc.js';
|
|
4
5
|
export const connectIpcToElectron = async (ipc) => {
|
|
5
6
|
const { port1, port2 } = await GetPortTuple.getPortTuple();
|
|
6
|
-
await JsonRpc.invokeAndTransfer(ipc, [port1], 'HandleElectronMessagePort.handleElectronMessagePort',
|
|
7
|
+
await JsonRpc.invokeAndTransfer(ipc, [port1], 'HandleElectronMessagePort.handleElectronMessagePort', IpcId.MainProcess);
|
|
7
8
|
await ParentIpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', [port2]);
|
|
8
9
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as JsonRpc from '../JsonRpc/JsonRpc.js';
|
|
2
1
|
import * as LaunchEmbedsProcess from '../LaunchEmbedsProcess/LaunchEmbedsProcess.js';
|
|
3
2
|
export const state = {
|
|
4
3
|
/**
|
|
@@ -12,11 +11,3 @@ export const getOrCreate = async () => {
|
|
|
12
11
|
}
|
|
13
12
|
return state.ipc;
|
|
14
13
|
};
|
|
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
|
-
};
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
messagePort,
|
|
12
|
-
});
|
|
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
|
-
}
|
|
19
|
-
// TODO find better way to associate configuration with ipc
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
ipc.windowId = params[1];
|
|
1
|
+
import * as HandleIncomingIpc from '../HandleIncomingIpc/HandleIncomingIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
export const handleElectronMessagePort = (messagePort, ...params) => {
|
|
4
|
+
const ipcId = params[0];
|
|
5
|
+
const windowId = params[1];
|
|
6
|
+
const message = {
|
|
7
|
+
ipcId,
|
|
8
|
+
windowId,
|
|
9
|
+
};
|
|
10
|
+
return HandleIncomingIpc.handleIncomingIpc(IpcId.SharedProcess, messagePort, message);
|
|
22
11
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as Assert from '../Assert/Assert.js';
|
|
2
|
+
import * as HandleIpc from '../HandleIpc/HandleIpc.js';
|
|
3
|
+
import * as HandleIpcModule from '../HandleIpcModule/HandleIpcModule.js';
|
|
4
|
+
import * as IsMessagePortMain from '../IsMessagePortMain/IsMessagePortMain.js';
|
|
5
|
+
import * as SendIncomingIpc from '../SendIncomingIpc/SendIncomingIpc.js';
|
|
6
|
+
const handleIncomingIpcMessagePort = async (module, handle, message) => {
|
|
7
|
+
const target = await module.targetMessagePort(handle, message);
|
|
8
|
+
const response = module.upgradeMessagePort(handle, message);
|
|
9
|
+
return {
|
|
10
|
+
target,
|
|
11
|
+
response,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const handleIncomingIpcWebSocket = async (module, handle, message) => {
|
|
15
|
+
const target = await module.targetWebSocket(handle, message);
|
|
16
|
+
const response = module.upgradeWebSocket(handle, message);
|
|
17
|
+
return {
|
|
18
|
+
target,
|
|
19
|
+
response,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const getIpcAndResponse = (module, handle, message) => {
|
|
23
|
+
if (IsMessagePortMain.isMessagePortMain(handle)) {
|
|
24
|
+
return handleIncomingIpcMessagePort(module, handle, message);
|
|
25
|
+
}
|
|
26
|
+
return handleIncomingIpcWebSocket(module, handle, message);
|
|
27
|
+
};
|
|
28
|
+
const applyResponse = async (target, response, ipcId) => {
|
|
29
|
+
switch (response.type) {
|
|
30
|
+
case 'handle':
|
|
31
|
+
HandleIpc.handleIpc(target);
|
|
32
|
+
break;
|
|
33
|
+
case 'send':
|
|
34
|
+
return SendIncomingIpc.sendIncomingIpc(target, response, ipcId);
|
|
35
|
+
default:
|
|
36
|
+
throw new Error('unexpected response');
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const handleIncomingIpc = async (ipcId, handle, message) => {
|
|
40
|
+
Assert.number(ipcId);
|
|
41
|
+
const module = HandleIpcModule.getModule(ipcId);
|
|
42
|
+
const { target, response } = await getIpcAndResponse(module, handle, message);
|
|
43
|
+
await applyResponse(target, response, ipcId);
|
|
44
|
+
};
|
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import * as HandleMessage from '../HandleMessage/HandleMessage.js';
|
|
2
|
+
const handled = new WeakSet();
|
|
2
3
|
export const handleIpc = (ipc) => {
|
|
3
|
-
|
|
4
|
+
if (handled.has(ipc)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
handled.add(ipc);
|
|
8
|
+
if ('addEventListener' in ipc) {
|
|
9
|
+
ipc.addEventListener('message', HandleMessage.handleMessage);
|
|
10
|
+
}
|
|
11
|
+
else if ('on' in ipc) {
|
|
12
|
+
// deprecated
|
|
13
|
+
ipc.on('message', HandleMessage.handleMessage);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const unhandleIpc = (ipc) => {
|
|
17
|
+
handled.delete(ipc);
|
|
18
|
+
if ('removeEventListener' in ipc) {
|
|
19
|
+
ipc.removeEventListener('message', HandleMessage.handleMessage);
|
|
20
|
+
}
|
|
21
|
+
else if ('off' in ipc) {
|
|
22
|
+
// deprecated
|
|
23
|
+
ipc.off('message', HandleMessage.handleMessage);
|
|
24
|
+
}
|
|
4
25
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as EmbedsProcess from '../EmbedsProcess/EmbedsProcess.js';
|
|
2
|
+
export const targetMessagePort = () => {
|
|
3
|
+
return EmbedsProcess.getOrCreate();
|
|
4
|
+
};
|
|
5
|
+
export const upgradeMessagePort = (port, message) => {
|
|
6
|
+
return {
|
|
7
|
+
type: 'send',
|
|
8
|
+
method: 'HandleElectronMessagePort.handleElectronMessagePort',
|
|
9
|
+
params: [message.ipcId],
|
|
10
|
+
transfer: [port],
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as ExtensionHostHelperProcessIpc from '../ExtensionHostHelperProcessIpc/ExtensionHostHelperProcessIpc.js';
|
|
2
|
+
import * as IpcParentType from '../IpcParentType/IpcParentType.js';
|
|
3
|
+
export const targetWebSocket = async () => {
|
|
4
|
+
const ipc = await ExtensionHostHelperProcessIpc.create({
|
|
5
|
+
method: IpcParentType.NodeForkedProcess,
|
|
6
|
+
});
|
|
7
|
+
return ipc;
|
|
8
|
+
};
|
|
9
|
+
export const upgradeWebSocket = (handle, message) => {
|
|
10
|
+
return {
|
|
11
|
+
type: 'send',
|
|
12
|
+
method: 'HandleWebSocket.handleWebSocket',
|
|
13
|
+
params: [message],
|
|
14
|
+
transfer: handle,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export const targetMessagePort = async () => {
|
|
18
|
+
const ipc = await ExtensionHostHelperProcessIpc.create({
|
|
19
|
+
method: IpcParentType.ElectronUtilityProcess,
|
|
20
|
+
});
|
|
21
|
+
return ipc;
|
|
22
|
+
};
|
|
23
|
+
export const upgradeMessagePort = (port) => {
|
|
24
|
+
return {
|
|
25
|
+
type: 'send',
|
|
26
|
+
method: 'HandleElectronMessagePort.handleElectronMessagePort',
|
|
27
|
+
params: [],
|
|
28
|
+
transfer: [port],
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Assert from '../Assert/Assert.js';
|
|
2
|
+
import * as HandleIpcEmbedsProcess from '../HandleIpcEmbedsProcess/HandleIpcEmbedsProcess.js';
|
|
3
|
+
import * as HandleIpcExtensionHostHelperProcess from '../HandleIpcExtensionHostHelperProcess/HandleIpcExtensionHostHelperProcess.js';
|
|
4
|
+
import * as HandleIpcProcessExplorer from '../HandleIpcProcessExplorer/HandleIpcProcessExplorer.js';
|
|
5
|
+
import * as HandleIpcSearchProcess from '../HandleIpcSearchProcess/HandleIpcSearchProcess.js';
|
|
6
|
+
import * as HandleIpcSharedProcess from '../HandleIpcSharedProcess/HandleIpcSharedProcess.js';
|
|
7
|
+
import * as HandleIpcTerminalProcess from '../HandleIpcTerminalProcess/HandleIpcTerminalProcess.js';
|
|
8
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
9
|
+
export const getModule = (ipcId) => {
|
|
10
|
+
Assert.number(ipcId);
|
|
11
|
+
switch (ipcId) {
|
|
12
|
+
case IpcId.SharedProcess:
|
|
13
|
+
return HandleIpcSharedProcess;
|
|
14
|
+
case IpcId.EmbedsProcess:
|
|
15
|
+
return HandleIpcEmbedsProcess;
|
|
16
|
+
case IpcId.TerminalProcess:
|
|
17
|
+
return HandleIpcTerminalProcess;
|
|
18
|
+
case IpcId.ExtensionHostHelperProcess:
|
|
19
|
+
return HandleIpcExtensionHostHelperProcess;
|
|
20
|
+
case IpcId.ProcessExplorer:
|
|
21
|
+
return HandleIpcProcessExplorer;
|
|
22
|
+
case IpcId.SearchProcess:
|
|
23
|
+
return HandleIpcSearchProcess;
|
|
24
|
+
default:
|
|
25
|
+
throw new Error(`unexpected incoming ipc`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as ProcessExplorer from '../ProcessExplorer/ProcessExplorer.js';
|
|
2
|
+
import * as Assert from '../Assert/Assert.js';
|
|
3
|
+
export const targetMessagePort = () => {
|
|
4
|
+
return ProcessExplorer.getOrCreate();
|
|
5
|
+
};
|
|
6
|
+
export const upgradeMessagePort = (port) => {
|
|
7
|
+
Assert.object(port);
|
|
8
|
+
return {
|
|
9
|
+
type: 'send',
|
|
10
|
+
method: 'HandleElectronMessagePort.handleElectronMessagePort',
|
|
11
|
+
params: [],
|
|
12
|
+
transfer: [port],
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Assert from '../Assert/Assert.js';
|
|
2
|
+
import * as HandleSocketError from '../HandleSocketError/HandleSocketError.js';
|
|
3
|
+
import * as IpcChild from '../IpcChild/IpcChild.js';
|
|
4
|
+
import * as IpcChildType from '../IpcChildType/IpcChildType.js';
|
|
5
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
6
|
+
import * as ParentIpc from '../ParentIpc/ParentIpc.js';
|
|
7
|
+
export const targetWebSocket = async (handle, message) => {
|
|
8
|
+
handle.on('error', HandleSocketError.handleSocketError);
|
|
9
|
+
const ipc = await IpcChild.listen({
|
|
10
|
+
method: IpcChildType.WebSocket,
|
|
11
|
+
request: message,
|
|
12
|
+
handle,
|
|
13
|
+
});
|
|
14
|
+
return ipc;
|
|
15
|
+
};
|
|
16
|
+
export const upgradeWebSocket = () => {
|
|
17
|
+
return {
|
|
18
|
+
type: 'handle',
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const targetMessagePort = async (messagePort, message) => {
|
|
22
|
+
Assert.object(messagePort);
|
|
23
|
+
const ipc = await IpcChild.listen({
|
|
24
|
+
method: IpcChildType.ElectronMessagePort,
|
|
25
|
+
messagePort,
|
|
26
|
+
});
|
|
27
|
+
if (message.ipcId === IpcId.MainProcess) {
|
|
28
|
+
// update ipc with message port ipc that supports transferring objects
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
ParentIpc.state.ipc = ipc;
|
|
31
|
+
}
|
|
32
|
+
// TODO find better way to associate configuration with ipc
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
ipc.windowId = message.windowId;
|
|
35
|
+
return ipc;
|
|
36
|
+
};
|
|
37
|
+
export const upgradeMessagePort = () => {
|
|
38
|
+
return {
|
|
39
|
+
type: 'handle',
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as PtyHost from '../PtyHost/PtyHost.js';
|
|
2
|
+
import * as IpcParentType from '../IpcParentType/IpcParentType.js';
|
|
3
|
+
export const targetWebSocket = () => {
|
|
4
|
+
return PtyHost.getOrCreate(IpcParentType.NodeForkedProcess);
|
|
5
|
+
};
|
|
6
|
+
export const upgradeWebSocket = (handle, message) => {
|
|
7
|
+
return {
|
|
8
|
+
type: 'send',
|
|
9
|
+
method: 'HandleWebSocket.handleWebSocket',
|
|
10
|
+
params: [message],
|
|
11
|
+
transfer: handle,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export const targetMessagePort = () => {
|
|
15
|
+
return PtyHost.getOrCreate(IpcParentType.ElectronUtilityProcess);
|
|
16
|
+
};
|
|
17
|
+
export const upgradeMessagePort = (port) => {
|
|
18
|
+
return {
|
|
19
|
+
type: 'send',
|
|
20
|
+
method: 'HandleElectronMessagePort.handleElectronMessagePort',
|
|
21
|
+
params: [],
|
|
22
|
+
transfer: [port],
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
await JsonRpc.invokeAndTransfer(embedsProcess, [port], 'HandleElectronMessagePort.handleElectronMessagePort');
|
|
1
|
+
import * as HandleIncomingIpc from '../HandleIncomingIpc/HandleIncomingIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
export const handleMessagePortForEmbedsProcess = (port, ipcId) => {
|
|
4
|
+
return HandleIncomingIpc.handleIncomingIpc(IpcId.EmbedsProcess, port, {
|
|
5
|
+
ipcId,
|
|
6
|
+
});
|
|
8
7
|
};
|
|
@@ -15,9 +15,9 @@ export const handleMessagePortForExtensionHostHelperProcess = async (rendererWor
|
|
|
15
15
|
});
|
|
16
16
|
HandleIpc.handleIpc(ipc);
|
|
17
17
|
await JsonRpc.invokeAndTransfer(ipc, [port], 'HandleElectronMessagePort.handleElectronMessagePort');
|
|
18
|
-
const cleanup = () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
rendererWorkerIpc.on('close', cleanup)
|
|
18
|
+
// const cleanup = () => {
|
|
19
|
+
// ipc.dispose()
|
|
20
|
+
// rendererWorkerIpc.off('close', cleanup)
|
|
21
|
+
// }
|
|
22
|
+
// rendererWorkerIpc.on('close', cleanup)
|
|
23
23
|
};
|
package/src/parts/HandleMessagePortForProcessExplorer/HandleMessagePortForProcessExplorer.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Assert.object(port);
|
|
6
|
-
const ipc = await ProcessExplorer.getOrCreate();
|
|
7
|
-
await JsonRpc.invokeAndTransfer(ipc, [port], 'HandleElectronMessagePort.handleElectronMessagePort');
|
|
1
|
+
import * as HandleIncomingIpc from '../HandleIncomingIpc/HandleIncomingIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
export const handleMessagePortForProcessExplorer = (port) => {
|
|
4
|
+
return HandleIncomingIpc.handleIncomingIpc(IpcId.ProcessExplorer, port, {});
|
|
8
5
|
};
|
package/src/parts/HandleMessagePortForTerminalProcess/HandleMessagePortForTerminalProcess.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const handleMessagePortForTerminalProcess = async (port) => {
|
|
6
|
-
Assert.object(port);
|
|
7
|
-
const ptyHost = await PtyHost.getOrCreate(IpcParentType.ElectronUtilityProcess);
|
|
8
|
-
await JsonRpc.invokeAndTransfer(ptyHost, [port], 'HandleElectronMessagePort.handleElectronMessagePort');
|
|
1
|
+
import * as HandleIncomingIpc from '../HandleIncomingIpc/HandleIncomingIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
export const handleMessagePortForTerminalProcess = (port) => {
|
|
4
|
+
return HandleIncomingIpc.handleIncomingIpc(IpcId.TerminalProcess, port, {});
|
|
9
5
|
};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const ipc = await ExtensionHostHelperProcessIpc.create({
|
|
6
|
-
method: IpcParentType.NodeForkedProcess,
|
|
7
|
-
});
|
|
8
|
-
await JsonRpc.invokeAndTransfer(ipc, handle, 'HandleWebSocket.handleWebSocket', message);
|
|
1
|
+
import * as HandleIncomingIpc from '../HandleIncomingIpc/HandleIncomingIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
export const handleWebSocket = (message, handle) => {
|
|
4
|
+
return HandleIncomingIpc.handleIncomingIpc(IpcId.ExtensionHostHelperProcess, handle, message);
|
|
9
5
|
};
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import * as IpcChildType from '../IpcChildType/IpcChildType.js';
|
|
6
|
-
export const handleWebSocket = async (request, handle) => {
|
|
7
|
-
Assert.object(request);
|
|
8
|
-
Assert.object(handle);
|
|
9
|
-
handle.on('error', HandleSocketError.handleSocketError);
|
|
10
|
-
const ipc = await IpcChild.listen({
|
|
11
|
-
method: IpcChildType.WebSocket,
|
|
12
|
-
request,
|
|
13
|
-
handle,
|
|
14
|
-
});
|
|
15
|
-
HandleIpc.handleIpc(ipc);
|
|
1
|
+
import * as HandleIncomingIpc from '../HandleIncomingIpc/HandleIncomingIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
export const handleWebSocket = (request, handle) => {
|
|
4
|
+
return HandleIncomingIpc.handleIncomingIpc(IpcId.SharedProcess, handle, request);
|
|
16
5
|
};
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
jsonrpc: '2.0',
|
|
6
|
-
method: 'HandleWebSocket.handleWebSocket',
|
|
7
|
-
params: [message],
|
|
8
|
-
}, handle);
|
|
9
|
-
// console.log({ instance })
|
|
10
|
-
// const ipc = await PtyHost.getOrCreate()
|
|
11
|
-
// console.info('[sharedprocess] creating extension ipc')
|
|
12
|
-
// const rpc = await ExtensionHostRpc.create(ipc, handle)
|
|
13
|
-
// console.info('[sharedprocess] created extension host rpc')
|
|
14
|
-
// ipc._process.send(message, handle)
|
|
15
|
-
// rpc.send(message)
|
|
16
|
-
// console.log('spawned extension host')
|
|
17
|
-
// console.log(rpc)
|
|
1
|
+
import * as HandleIncomingIpc from '../HandleIncomingIpc/HandleIncomingIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
export const handleWebSocket = (message, handle) => {
|
|
4
|
+
return HandleIncomingIpc.handleIncomingIpc(IpcId.TerminalProcess, handle, message);
|
|
18
5
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const SharedProcess = 1;
|
|
2
|
+
export const MainProcess = -5;
|
|
3
|
+
export const EmbedsProcess = 2;
|
|
4
|
+
export const TerminalProcess = 7;
|
|
5
|
+
export const ExtensionHostHelperProcess = 3;
|
|
6
|
+
export const ProcessExplorer = 11;
|
|
7
|
+
export const SearchProcess = 13;
|
|
8
|
+
export const Unknown = 0;
|
package/src/parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js
CHANGED
|
@@ -22,6 +22,7 @@ export const signal = (port) => {
|
|
|
22
22
|
export const wrap = (port) => {
|
|
23
23
|
return {
|
|
24
24
|
port,
|
|
25
|
+
wrappedListener: undefined,
|
|
25
26
|
send(message) {
|
|
26
27
|
this.port.postMessage(message);
|
|
27
28
|
},
|
|
@@ -34,20 +35,33 @@ export const wrap = (port) => {
|
|
|
34
35
|
this.port.on(event, listener);
|
|
35
36
|
break;
|
|
36
37
|
case 'message':
|
|
37
|
-
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
this.wrappedListener = (event) => {
|
|
38
40
|
const syntheticEvent = {
|
|
39
41
|
data: event.data,
|
|
40
42
|
target: this,
|
|
41
43
|
};
|
|
42
44
|
listener(syntheticEvent);
|
|
43
45
|
};
|
|
44
|
-
this.port.on(event,
|
|
46
|
+
this.port.on(event, this.wrappedListener);
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
off(event, listener) {
|
|
53
|
+
switch (event) {
|
|
54
|
+
case 'close':
|
|
55
|
+
this.port.off(event, listener);
|
|
56
|
+
break;
|
|
57
|
+
case 'message':
|
|
58
|
+
this.port.off(event, this.wrappedListener);
|
|
59
|
+
this.wrappedListener = undefined;
|
|
45
60
|
break;
|
|
46
61
|
default:
|
|
47
62
|
break;
|
|
48
63
|
}
|
|
49
64
|
},
|
|
50
|
-
off(event, listener) { },
|
|
51
65
|
dispose() {
|
|
52
66
|
this.port.close();
|
|
53
67
|
ParentIpc.invoke('TemporaryMessagePort.dispose', this.port.name);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import exitHook from 'exit-hook';
|
|
2
2
|
import * as Debug from '../Debug/Debug.js';
|
|
3
|
-
import * as HandleIpc from '../HandleIpc/HandleIpc.js';
|
|
4
3
|
import * as IpcParent from '../IpcParent/IpcParent.js';
|
|
5
4
|
import * as PtyHostPath from '../PtyHostPath/PtyHostPath.js';
|
|
6
5
|
import * as PtyHostState from '../PtyHostState/PtyHostState.js';
|
|
@@ -24,14 +23,16 @@ export const launchPtyHost = async (method) => {
|
|
|
24
23
|
stdio: 'inherit',
|
|
25
24
|
name: 'Terminal Process',
|
|
26
25
|
});
|
|
27
|
-
HandleIpc.handleIpc(ptyHost)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
// HandleIpc.handleIpc(ptyHost)
|
|
27
|
+
// TODO
|
|
28
|
+
// const handleClose = () => {
|
|
29
|
+
// // @ts-ignore
|
|
30
|
+
// ptyHost._rawIpc.off('close', handleClose)
|
|
31
|
+
// PtyHostState.state.ipc = undefined
|
|
32
|
+
// PtyHostState.state.ptyHostPromise = undefined
|
|
33
|
+
// }
|
|
34
|
+
// // @ts-ignore
|
|
35
|
+
// ptyHost._rawIpc.on('close', handleClose)
|
|
35
36
|
PtyHostState.state.ipc = ptyHost;
|
|
36
37
|
return ptyHost;
|
|
37
38
|
};
|
|
@@ -262,7 +262,7 @@ export const getModuleId = (commandId) => {
|
|
|
262
262
|
return ModuleId.HandleWindowAllClosed;
|
|
263
263
|
case 'HandleMessagePortForTerminalProcess.handleMessagePortForTerminalProcess':
|
|
264
264
|
return ModuleId.HandleMessagePortForTerminalProcess;
|
|
265
|
-
case 'TemporaryMessagePort.
|
|
265
|
+
case 'TemporaryMessagePort.handlePorts':
|
|
266
266
|
return ModuleId.TemporaryMessagePort;
|
|
267
267
|
case 'GetElectronFileResponse.getElectronFileResponse':
|
|
268
268
|
return ModuleId.GetElectronFileResponse;
|
|
@@ -41,9 +41,9 @@ export const getAppImageName = () => {
|
|
|
41
41
|
export const getSetupName = () => {
|
|
42
42
|
return 'Lvce-Setup';
|
|
43
43
|
};
|
|
44
|
-
export const version = '0.26.
|
|
45
|
-
export const commit = '
|
|
46
|
-
export const date = '2024-04-
|
|
44
|
+
export const version = '0.26.2';
|
|
45
|
+
export const commit = 'efc5b0f';
|
|
46
|
+
export const date = '2024-04-23T20:38:06.000Z';
|
|
47
47
|
export const getVersion = () => {
|
|
48
48
|
return version;
|
|
49
49
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as HandleIpc from '../HandleIpc/HandleIpc.js';
|
|
2
|
+
import * as IpcId from '../IpcId/IpcId.js';
|
|
3
|
+
import * as JsonRpc from '../JsonRpc/JsonRpc.js';
|
|
4
|
+
const state = {
|
|
5
|
+
pendingCount: Object.create(null),
|
|
6
|
+
};
|
|
7
|
+
const addState = (ipcId) => {
|
|
8
|
+
state.pendingCount[ipcId] ||= 0;
|
|
9
|
+
state.pendingCount[ipcId]++;
|
|
10
|
+
};
|
|
11
|
+
const removeState = (ipcId) => {
|
|
12
|
+
state.pendingCount[ipcId]--;
|
|
13
|
+
if (state.pendingCount[ipcId] === 0) {
|
|
14
|
+
delete state.pendingCount[ipcId];
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const hasState = (ipcId) => {
|
|
18
|
+
return ipcId in state.pendingCount;
|
|
19
|
+
};
|
|
20
|
+
const supportsPartialIpcHandling = (ipcId) => {
|
|
21
|
+
switch (ipcId) {
|
|
22
|
+
case IpcId.TerminalProcess:
|
|
23
|
+
case IpcId.ProcessExplorer:
|
|
24
|
+
case IpcId.EmbedsProcess:
|
|
25
|
+
return true;
|
|
26
|
+
default:
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
// TODO fork ipc object instead of ref counting
|
|
31
|
+
// duplicated ipc object sends and receives one message
|
|
32
|
+
// original ipc object is never used and can
|
|
33
|
+
// be collected after being out of scope
|
|
34
|
+
// duplicated ipc can also be collected
|
|
35
|
+
// when it is out of scope
|
|
36
|
+
export const sendIncomingIpc = async (target, response, ipcId) => {
|
|
37
|
+
if (!hasState(ipcId) && supportsPartialIpcHandling(ipcId)) {
|
|
38
|
+
HandleIpc.handleIpc(target);
|
|
39
|
+
}
|
|
40
|
+
addState(ipcId);
|
|
41
|
+
await JsonRpc.invokeAndTransfer(target, response.transfer, response.method, ...response.params);
|
|
42
|
+
removeState(ipcId);
|
|
43
|
+
if (!hasState(ipcId) && supportsPartialIpcHandling(ipcId)) {
|
|
44
|
+
HandleIpc.unhandleIpc(target);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
import * as ParentIpc from '../ParentIpc/ParentIpc.js';
|
|
2
1
|
import * as Assert from '../Assert/Assert.js';
|
|
3
2
|
import * as Id from '../Id/Id.js';
|
|
3
|
+
import * as ParentIpc from '../ParentIpc/ParentIpc.js';
|
|
4
4
|
export const state = {
|
|
5
5
|
ports: Object.create(null),
|
|
6
6
|
};
|
|
7
|
-
export const create = async (name) => {
|
|
8
|
-
Assert.string(name);
|
|
9
|
-
await ParentIpc.invoke('TemporaryMessagePort.create', name);
|
|
10
|
-
const port = state.ports[name];
|
|
11
|
-
if (!port) {
|
|
12
|
-
throw new Error(`port was not created`);
|
|
13
|
-
}
|
|
14
|
-
delete state.ports[name];
|
|
15
|
-
port.start();
|
|
16
|
-
return port;
|
|
17
|
-
};
|
|
18
7
|
export const getPortTuple = async () => {
|
|
19
|
-
const id1 =
|
|
20
|
-
const id2 =
|
|
8
|
+
const id1 = Id.create();
|
|
9
|
+
const id2 = Id.create();
|
|
21
10
|
await ParentIpc.invoke('TemporaryMessagePort.createPortTuple', id1, id2);
|
|
22
11
|
const port1 = state.ports[id1];
|
|
23
12
|
const port2 = state.ports[id2];
|
|
13
|
+
delete state.ports[id1];
|
|
14
|
+
delete state.ports[id2];
|
|
24
15
|
return {
|
|
25
16
|
port1,
|
|
26
17
|
port2,
|
|
@@ -31,8 +22,11 @@ export const sendTo = async (name, port) => {
|
|
|
31
22
|
Assert.object(port);
|
|
32
23
|
await ParentIpc.invokeAndTransfer('TemporaryMessagePort.sendTo', [port], name);
|
|
33
24
|
};
|
|
34
|
-
export const
|
|
35
|
-
Assert.
|
|
36
|
-
Assert.
|
|
37
|
-
|
|
25
|
+
export const handlePorts = (port1, port2, id1, id2) => {
|
|
26
|
+
Assert.number(id1);
|
|
27
|
+
Assert.number(id2);
|
|
28
|
+
Assert.object(port1);
|
|
29
|
+
Assert.object(port2);
|
|
30
|
+
state.ports[id1] = port1;
|
|
31
|
+
state.ports[id2] = port2;
|
|
38
32
|
};
|