@lvce-editor/shared-process 0.21.1 → 0.21.3

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 (27) hide show
  1. package/package.json +8 -8
  2. package/src/parts/AppWindow/AppWindow.js +3 -33
  3. package/src/parts/Clamp/Clamp.js +3 -0
  4. package/src/parts/ElectronWindow/ElectronWindow.js +48 -4
  5. package/src/parts/ErrorHandling/ErrorHandling.js +1 -1
  6. package/src/parts/GetAppWindowOptions/GetAppWindowOptions.js +29 -0
  7. package/src/parts/GetBrowserWindowOptions/GetBrowserWindowOptions.js +32 -0
  8. package/src/parts/GetIcon/GetIcon.js +19 -0
  9. package/src/parts/GetPreloadUrl/GetPreloadUrl.js +6 -0
  10. package/src/parts/GetProcessExplorerUrl/GetProcessExplorerUrl.js +1 -1
  11. package/src/parts/HandleIpc/HandleIpc.js +0 -1
  12. package/src/parts/HandleMessagePortForTerminalProcess/HandleMessagePortForTerminalProcess.ipc.js +7 -0
  13. package/src/parts/HandleMessagePortForTerminalProcess/HandleMessagePortForTerminalProcess.js +10 -0
  14. package/src/parts/HandleUncaughtExceptionMonitor/HandleUncaughtExceptionMonitor.js +11 -1
  15. package/src/parts/IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js +8 -1
  16. package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +3 -0
  17. package/src/parts/IpcParentModule/IpcParentModule.js +2 -0
  18. package/src/parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js +40 -4
  19. package/src/parts/Main/Main.js +2 -1
  20. package/src/parts/Module/Module.js +4 -0
  21. package/src/parts/ModuleId/ModuleId.js +2 -0
  22. package/src/parts/ModuleMap/ModuleMap.js +4 -0
  23. package/src/parts/ParentIpc/ParentIpc.js +3 -0
  24. package/src/parts/Platform/Platform.js +11 -3
  25. package/src/parts/PtyHost/PtyHost.js +6 -4
  26. package/src/parts/TemporaryMessagePort/TemporaryMessagePort.ipc.js +7 -0
  27. package/src/parts/TemporaryMessagePort/TemporaryMessagePort.js +24 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.21.1",
3
+ "version": "0.21.3",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -14,16 +14,16 @@
14
14
  "directory": "packages/shared-process"
15
15
  },
16
16
  "engines": {
17
- "node": ">=16"
17
+ "node": ">=18"
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/code-frame": "^7.23.5",
21
- "@lvce-editor/extension-host": "0.21.1",
22
- "@lvce-editor/extension-host-helper-process": "0.21.1",
21
+ "@lvce-editor/extension-host": "0.21.3",
22
+ "@lvce-editor/extension-host-helper-process": "0.21.3",
23
23
  "@lvce-editor/json-rpc": "^0.4.0",
24
24
  "@lvce-editor/jsonc-parser": "^1.1.0",
25
- "@lvce-editor/pretty-error": "^1.2.2",
26
- "@lvce-editor/pty-host": "0.21.1",
25
+ "@lvce-editor/pretty-error": "^1.3.0",
26
+ "@lvce-editor/pty-host": "0.21.3",
27
27
  "@lvce-editor/verror": "^1.1.2",
28
28
  "debug": "^4.3.4",
29
29
  "execa": "^8.0.1",
@@ -31,10 +31,10 @@
31
31
  "got": "^13.0.0",
32
32
  "is-object": "^1.0.2",
33
33
  "lines-and-columns": "^2.0.4",
34
- "p-queue": "^8.0.0",
34
+ "p-queue": "^8.0.1",
35
35
  "parse-json": "^8.1.0",
36
36
  "tar-fs": "^3.0.4",
37
- "ws": "^8.15.0",
37
+ "ws": "^8.15.1",
38
38
  "xdg-basedir": "^5.1.0"
39
39
  },
40
40
  "optionalDependencies": {
@@ -1,42 +1,12 @@
1
1
  import * as DefaultUrl from '../DefaultUrl/DefaultUrl.js'
2
+ import * as GetAppWindowOptions from '../GetAppWindowOptions/GetAppWindowOptions.js'
2
3
  import * as ParentIpc from '../ParentIpc/ParentIpc.js'
3
- import * as Platform from '../Platform/Platform.js'
4
4
  import * as Preferences from '../Preferences/Preferences.js'
5
5
  import * as Screen from '../Screen/Screen.js'
6
6
 
7
- const getWindowOptions = (preferencs, screenWidth, screenHeight) => {
8
- const titleBarPreference = preferencs['window.titleBarStyle']
9
- const frame = titleBarPreference !== 'custom'
10
- const titleBarStyle = titleBarPreference === 'custom' ? 'hidden' : undefined
11
- const zoomLevelPreference = preferencs['window.zoomLevel']
12
- const zoomLevel = zoomLevelPreference
13
- const windowControlsOverlayPreference = Platform.isWindows && preferencs['window.controlsOverlay.enabled']
14
-
15
- const titleBarOverlay = windowControlsOverlayPreference
16
- ? {
17
- color: '#1e2324',
18
- symbolColor: '#74b1be',
19
- height: 29,
20
- }
21
- : undefined
22
- return {
23
- y: 0,
24
- x: screenWidth - 800,
25
- width: 800,
26
- height: screenHeight,
27
- menu: true,
28
- background: '#1e2324',
29
- titleBarStyle,
30
- frame,
31
- zoomLevel,
32
- titleBarOverlay,
33
- }
34
- }
35
-
36
7
  export const createAppWindow = async (preferences, parsedArgs, workingDirectory, url = DefaultUrl.defaultUrl) => {
37
- const screenWidth = await Screen.getWidth()
38
- const screenHeight = await Screen.getHeight()
39
- const windowOptions = getWindowOptions(preferences, screenWidth, screenHeight)
8
+ const { width, height } = await Screen.getBounds()
9
+ const windowOptions = GetAppWindowOptions.getAppWindowOptions(preferences, width, height)
40
10
  return ParentIpc.invoke('AppWindow.createAppWindow2', windowOptions, parsedArgs, workingDirectory, url)
41
11
  }
42
12
 
@@ -0,0 +1,3 @@
1
+ export const clamp = (number_, min, max) => {
2
+ return Math.min(Math.max(number_, min), max)
3
+ }
@@ -1,6 +1,7 @@
1
+ import * as AppWindow from '../AppWindow/AppWindow.js'
1
2
  import * as Assert from '../Assert/Assert.js'
3
+ import * as Clamp from '../Clamp/Clamp.js'
2
4
  import * as ParentIpc from '../ParentIpc/ParentIpc.js'
3
- import * as AppWindow from '../AppWindow/AppWindow.js'
4
5
 
5
6
  export const openNew = () => {
6
7
  return AppWindow.openNew()
@@ -36,16 +37,59 @@ export const reload = (windowId) => {
36
37
  return ParentIpc.invoke('ElectronWindow.executeWindowFunction', windowId, 'reload')
37
38
  }
38
39
 
40
+ const setZoom = async (windowId, zoomFactor, minZoomLevel, maxZoomLevel) => {
41
+ const newZoomFactor = Clamp.clamp(zoomFactor, minZoomLevel, maxZoomLevel)
42
+ await ParentIpc.invoke('ElectronWindow.executeWebContentsFunction', windowId, 'setZoomLevel', newZoomFactor)
43
+ // TODO
44
+ // await Preferences.update('window.zoomLevel', newZoomFactor)
45
+ }
46
+
47
+ /**
48
+ *
49
+ * @param {number} windowId
50
+ * @param {*} getDelta
51
+ * @param {*} getMinZoomLevel
52
+ * @param {*} getMaxZoomLevel
53
+ * @returns
54
+ */
55
+ const setZoomDelta = async (windowId, getDelta, getMinZoomLevel, getMaxZoomLevel) => {
56
+ const delta = getDelta()
57
+ const minZoomLevel = getMinZoomLevel()
58
+ const maxZoomLevel = getMaxZoomLevel()
59
+ const currentZoomLevel = await ParentIpc.invoke('ElectronWindow.executeWebContentsFunction', windowId, 'getZoomLevel')
60
+ return setZoom(windowId, currentZoomLevel + delta, minZoomLevel, maxZoomLevel)
61
+ }
62
+
63
+ const getMinZoomLevel = () => {
64
+ return -3
65
+ }
66
+
67
+ const getMaxZoomLevel = () => {
68
+ return 3
69
+ }
70
+
71
+ const getZoomInDelta = () => {
72
+ return 0.2
73
+ }
74
+
75
+ const getZoomOutDelta = () => {
76
+ return -0.2
77
+ }
78
+
79
+ const getDefaultZoomLevel = () => {
80
+ return 0
81
+ }
82
+
39
83
  export const zoomIn = (windowId) => {
40
- return ParentIpc.invoke('ElectronWindow.zoomIn', windowId)
84
+ return setZoomDelta(windowId, getZoomInDelta, getMinZoomLevel, getMaxZoomLevel)
41
85
  }
42
86
 
43
87
  export const zoomOut = (windowId) => {
44
- return ParentIpc.invoke('ElectronWindow.zoomOut', windowId)
88
+ return setZoomDelta(windowId, getZoomOutDelta, getMinZoomLevel, getMaxZoomLevel)
45
89
  }
46
90
 
47
91
  export const zoomReset = (windowId) => {
48
- return ParentIpc.invoke('ElectronWindow.zoomReset', windowId)
92
+ return setZoom(windowId, getDefaultZoomLevel(), getMinZoomLevel(), getMaxZoomLevel())
49
93
  }
50
94
 
51
95
  export const focus = (windowId) => {
@@ -58,7 +58,7 @@ const firstErrorLine = (error) => {
58
58
  }
59
59
 
60
60
  export const handleUncaughtExceptionMonitor = (error, origin) => {
61
- Logger.info(`[shared process] uncaught exception: ${firstErrorLine(error)}`)
61
+ Logger.info(`[shared process] Uncaught exception: ${firstErrorLine(error)}`)
62
62
  if (IsIgnoredError.isIgnoredError(error)) {
63
63
  return
64
64
  }
@@ -0,0 +1,29 @@
1
+ import * as GetBrowserWindowOptions from '../GetBrowserWindowOptions/GetBrowserWindowOptions.js'
2
+ import * as Platform from '../Platform/Platform.js'
3
+
4
+ export const getAppWindowOptions = (preferences, screenWidth, screenHeight) => {
5
+ const titleBarPreference = preferences['window.titleBarStyle']
6
+ const frame = titleBarPreference !== 'custom'
7
+ const titleBarStyle = titleBarPreference === 'custom' ? 'hidden' : undefined
8
+ const zoomLevelPreference = preferences['window.zoomLevel']
9
+ const zoomLevel = zoomLevelPreference
10
+ const windowControlsOverlayPreference = Platform.isWindows && preferences['window.controlsOverlay.enabled']
11
+
12
+ const titleBarOverlay = windowControlsOverlayPreference
13
+ ? {
14
+ color: '#1e2324',
15
+ symbolColor: '#74b1be',
16
+ height: 29,
17
+ }
18
+ : undefined
19
+ return GetBrowserWindowOptions.getBrowserWindowOptions({
20
+ y: 0,
21
+ x: screenWidth - 800,
22
+ width: 800,
23
+ height: screenHeight,
24
+ background: '#1e2324',
25
+ titleBarStyle,
26
+ frame,
27
+ titleBarOverlay,
28
+ })
29
+ }
@@ -0,0 +1,32 @@
1
+ import * as GetIcon from '../GetIcon/GetIcon.js'
2
+ import * as GetPreloadUrl from '../GetPreloadUrl/GetPreloadUrl.js'
3
+
4
+ /**
5
+ *
6
+ * @returns {any}
7
+ */
8
+ export const getBrowserWindowOptions = ({ x, y, width, height, titleBarStyle, titleBarOverlay, frame, background }) => {
9
+ const icon = GetIcon.getIcon()
10
+ return {
11
+ x,
12
+ y,
13
+ width,
14
+ height,
15
+ autoHideMenuBar: true,
16
+ titleBarStyle,
17
+ titleBarOverlay,
18
+ frame,
19
+ webPreferences: {
20
+ enableWebSQL: false,
21
+ spellcheck: false,
22
+ sandbox: true,
23
+ contextIsolation: true,
24
+ v8CacheOptions: 'bypassHeatCheck', // TODO this is what vscode uses, but it doesn't work properly in electron https://github.com/electron/electron/issues/27075
25
+ preload: GetPreloadUrl.getPreloadUrl(),
26
+ additionalArguments: ['--lvce-window-kind'],
27
+ },
28
+ backgroundColor: background,
29
+ show: false,
30
+ icon,
31
+ }
32
+ }
@@ -0,0 +1,19 @@
1
+ import * as Path from '../Path/Path.js'
2
+ import * as Platform from '../Platform/Platform.js'
3
+ import * as Root from '../Root/Root.js'
4
+
5
+ export const getIcon = () => {
6
+ if (!Platform.isProduction && Platform.isLinux) {
7
+ return Path.join(Root.root, 'build', 'files', 'icon.png')
8
+ }
9
+ if (!Platform.isProduction && Platform.isWindows) {
10
+ return Path.join(Root.root, 'build', 'files', 'icon.png')
11
+ }
12
+ if (Platform.isProduction && Platform.isArchLinux) {
13
+ return Path.join(Root.root, 'static', 'icons', 'icon.png')
14
+ }
15
+ if (Platform.isProduction && Platform.isAppImage) {
16
+ return Path.join(Root.root, 'static', 'icons', 'icon.png')
17
+ }
18
+ return undefined
19
+ }
@@ -0,0 +1,6 @@
1
+ import { join } from 'node:path'
2
+ import * as Root from '../Root/Root.js'
3
+
4
+ export const getPreloadUrl = () => {
5
+ return join(Root.root, 'packages', 'main-process', 'src', 'preload.js')
6
+ }
@@ -7,5 +7,5 @@ export const getProcessExplorerUrl = () => {
7
7
  }
8
8
 
9
9
  export const getProcessExplorerPreloadUrl = () => {
10
- return Path.join(Root.root, 'packages', 'main-process', 'pages', 'process-explorer', 'process-explorer-preload.js')
10
+ return Path.join(Root.root, 'packages', 'main-process', 'src', 'preload.js')
11
11
  }
@@ -16,7 +16,6 @@ const logError = (error, prettyError) => {
16
16
 
17
17
  export const handleIpc = (ipc) => {
18
18
  const handleMessage = (message) => {
19
- // @ts-ignore
20
19
  return JsonRpc.handleJsonRpcMessage(ipc, message, Command.execute, Callback.resolve, preparePrettyError, logError, RequiresSocket.requiresSocket)
21
20
  }
22
21
  ipc.on('message', handleMessage)
@@ -0,0 +1,7 @@
1
+ import * as HandleMessagePortForTerminalProcess from './HandleMessagePortForTerminalProcess.js'
2
+
3
+ export const name = 'HandleMessagePortForTerminalProcess'
4
+
5
+ export const Commands = {
6
+ handleMessagePortForTerminalProcess: HandleMessagePortForTerminalProcess.handleMessagePortForTerminalProcess,
7
+ }
@@ -0,0 +1,10 @@
1
+ import * as Assert from '../Assert/Assert.js'
2
+ import * as IpcParentType from '../IpcParentType/IpcParentType.js'
3
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js'
4
+ import * as PtyHost from '../PtyHost/PtyHost.js'
5
+
6
+ export const handleMessagePortForTerminalProcess = async (port) => {
7
+ Assert.object(port)
8
+ const ptyHost = await PtyHost.getOrCreate(IpcParentType.ElectronUtilityProcess)
9
+ await JsonRpc.invokeAndTransfer(ptyHost, [port], 'HandleElectronMessagePort.handleElectronMessagePort')
10
+ }
@@ -1,5 +1,15 @@
1
1
  import * as ErrorHandling from '../ErrorHandling/ErrorHandling.js'
2
2
 
3
- export const handleUncaughtExceptionMonitor = (error) => {
3
+ const handleUncaughtExceptionMonitor = (error) => {
4
4
  ErrorHandling.handleUncaughtExceptionMonitor(error)
5
5
  }
6
+
7
+ export const handleUncaughtException = (error) => {
8
+ handleUncaughtExceptionMonitor(error)
9
+ process.exit(1)
10
+ }
11
+
12
+ export const handleUnhandledRejection = (error) => {
13
+ handleUncaughtExceptionMonitor(error)
14
+ process.exit(1)
15
+ }
@@ -9,7 +9,14 @@ export const listen = ({ messagePort }) => {
9
9
  }
10
10
 
11
11
  const getActualData = (event) => {
12
- return event.data
12
+ const { data, ports } = event
13
+ if (ports.length === 0) {
14
+ return data
15
+ }
16
+ return {
17
+ ...data,
18
+ params: [...ports, ...data.params],
19
+ }
13
20
  }
14
21
 
15
22
  export const wrap = (messagePort) => {
@@ -44,6 +44,9 @@ export const wrap = (parentPort) => {
44
44
  send(message) {
45
45
  this.parentPort.postMessage(message)
46
46
  },
47
+ sendAndTransfer(message, transfer) {
48
+ this.parentPort.postMessage(message, transfer)
49
+ },
47
50
  dispose() {
48
51
  this.parentPort.close()
49
52
  },
@@ -6,6 +6,8 @@ export const getModule = (method) => {
6
6
  return import('../IpcParentWithNodeWorker/IpcParentWithNodeWorker.js')
7
7
  case IpcParentType.NodeForkedProcess:
8
8
  return import('../IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js')
9
+ case IpcParentType.ElectronUtilityProcess:
10
+ return import('../IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js')
9
11
  default:
10
12
  throw new Error('unexpected ipc type')
11
13
  }
@@ -1,12 +1,48 @@
1
1
  import * as ParentIpc from '../ParentIpc/ParentIpc.js'
2
+ import * as TemporaryMessagePort from '../TemporaryMessagePort/TemporaryMessagePort.js'
3
+
4
+ const ElectronUtilityProcess = 3
2
5
 
3
6
  export const create = async (options) => {
4
7
  // TODO how to launch process without race condition?
5
8
  // when promise resolves, process might have already exited
6
- const messagePort = await ParentIpc.invoke('IpcParent.create', { ...options })
7
- return messagePort
9
+ await ParentIpc.invoke('IpcParent.create', {
10
+ ...options,
11
+ method: ElectronUtilityProcess,
12
+ noReturn: true,
13
+ })
14
+ // TODO use uuid instead of name
15
+ const port = await TemporaryMessagePort.create(options.name)
16
+ return port
8
17
  }
9
18
 
10
- export const wrap = (messagePort) => {
11
- return {}
19
+ export const wrap = (port) => {
20
+ return {
21
+ port,
22
+ send(message) {
23
+ this.port.postMessage(message)
24
+ },
25
+ async sendAndTransfer(message, transfer) {
26
+ this.port.postMessage(message, transfer)
27
+ },
28
+ on(event, listener) {
29
+ switch (event) {
30
+ case 'close':
31
+ this.port.on(event, listener)
32
+ break
33
+ case 'message':
34
+ const wrapped = (event) => {
35
+ listener(event.data)
36
+ }
37
+ this.port.on(event, wrapped)
38
+ break
39
+ default:
40
+ break
41
+ }
42
+ },
43
+ off(event, listener) {},
44
+ dispose() {
45
+ this.port.close()
46
+ },
47
+ }
12
48
  }
@@ -9,6 +9,7 @@ export const main = async () => {
9
9
  Command.setLoad(Module.load)
10
10
  process.on('disconnect', ProcessListeners.handleDisconnect)
11
11
  process.on(Signal.SIGTERM, ProcessListeners.handleSigTerm)
12
- process.on('uncaughtExceptionMonitor', HandleUncaughtExceptionMonitor.handleUncaughtExceptionMonitor)
12
+ process.on('uncaughtException', HandleUncaughtExceptionMonitor.handleUncaughtException)
13
+ process.on('unhandledRejection', HandleUncaughtExceptionMonitor.handleUnhandledRejection)
13
14
  await ParentIpc.listen()
14
15
  }
@@ -130,6 +130,10 @@ export const load = (moduleId) => {
130
130
  return import('../HandleElectronReady/HandleElectronReady.ipc.js')
131
131
  case ModuleId.HandleWindowAllClosed:
132
132
  return import('../HandleWindowAllClosed/HandleWindowAllClosed.ipc.js')
133
+ case ModuleId.HandleMessagePortForTerminalProcess:
134
+ return import('../HandleMessagePortForTerminalProcess/HandleMessagePortForTerminalProcess.ipc.js')
135
+ case ModuleId.TemporaryMessagePort:
136
+ return import('../TemporaryMessagePort/TemporaryMessagePort.ipc.js')
133
137
  default:
134
138
  throw new Error(`module ${moduleId} not found`)
135
139
  }
@@ -64,3 +64,5 @@ export const ElectronNet = 57
64
64
  export const Screen = 58
65
65
  export const HandleElectronReady = 59
66
66
  export const HandleWindowAllClosed = 60
67
+ export const HandleMessagePortForTerminalProcess = 61
68
+ export const TemporaryMessagePort = 62
@@ -285,6 +285,10 @@ export const getModuleId = (commandId) => {
285
285
  return ModuleId.HandleElectronReady
286
286
  case 'HandleWindowAllClosed.handleWindowAllClosed':
287
287
  return ModuleId.HandleWindowAllClosed
288
+ case 'HandleMessagePortForTerminalProcess.handleMessagePortForTerminalProcess':
289
+ return ModuleId.HandleMessagePortForTerminalProcess
290
+ case 'TemporaryMessagePort.handlePort':
291
+ return ModuleId.TemporaryMessagePort
288
292
  default:
289
293
  throw new CommandNotFoundError(commandId)
290
294
  }
@@ -28,3 +28,6 @@ export const listen = async () => {
28
28
  export const invoke = (method, ...params) => {
29
29
  return JsonRpc.invoke(state.ipc, method, ...params)
30
30
  }
31
+ export const invokeAndTransfer = (method, transfer, ...params) => {
32
+ return JsonRpc.invokeAndTransfer(state.ipc, transfer, method, ...params)
33
+ }
@@ -13,6 +13,14 @@ export const isMacOs = platform === 'darwin'
13
13
 
14
14
  export const isDeb = false
15
15
 
16
+ export const isLinux = platform === 'linux'
17
+
18
+ export const isProduction = false
19
+
20
+ export const isArchLinux = false
21
+
22
+ export const isAppImage = false
23
+
16
24
  export const scheme = 'lvce-oss'
17
25
 
18
26
  export const getPathSeparator = () => {
@@ -53,11 +61,11 @@ export const getSetupName = () => {
53
61
  return 'Lvce-Setup'
54
62
  }
55
63
 
56
- export const version = '0.21.1'
64
+ export const version = '0.21.3'
57
65
 
58
- export const commit = '1aea3f8'
66
+ export const commit = '21796c8'
59
67
 
60
- export const date = '2023-12-12T20:15:17.000Z'
68
+ export const date = '2023-12-16T09:10:52.000Z'
61
69
 
62
70
  export const getVersion = () => {
63
71
  return version
@@ -1,5 +1,6 @@
1
1
  import exitHook from 'exit-hook'
2
2
  import * as Debug from '../Debug/Debug.js'
3
+ import * as HandleIpc from '../HandleIpc/HandleIpc.js'
3
4
  import * as IpcParent from '../IpcParent/IpcParent.js'
4
5
  import * as IpcParentType from '../IpcParentType/IpcParentType.js'
5
6
  import * as JsonRpc from '../JsonRpc/JsonRpc.js'
@@ -18,16 +19,17 @@ const handleProcessExit = () => {
18
19
  cleanUpAll()
19
20
  }
20
21
 
21
- const createPtyHost = async () => {
22
+ const createPtyHost = async (method) => {
22
23
  exitHook(handleProcessExit)
23
24
  const ptyHostPath = await PtyHostPath.getPtyHostPath()
24
25
  const ptyHost = await IpcParent.create({
25
- method: IpcParentType.NodeForkedProcess,
26
+ method,
26
27
  path: ptyHostPath,
27
28
  argv: [],
28
29
  stdio: 'inherit',
29
30
  name: 'Terminal Process',
30
31
  })
32
+ HandleIpc.handleIpc(ptyHost)
31
33
  const handleClose = () => {
32
34
  ptyHost.off('close', handleClose)
33
35
  PtyHostState.state.ipc = undefined
@@ -38,10 +40,10 @@ const createPtyHost = async () => {
38
40
  return ptyHost
39
41
  }
40
42
 
41
- export const getOrCreate = () => {
43
+ export const getOrCreate = (method = IpcParentType.NodeForkedProcess) => {
42
44
  Debug.debug('creating pty host')
43
45
  if (!PtyHostState.state.ptyHostPromise) {
44
- PtyHostState.state.ptyHostPromise = createPtyHost()
46
+ PtyHostState.state.ptyHostPromise = createPtyHost(method)
45
47
  }
46
48
  return PtyHostState.state.ptyHostPromise
47
49
  }
@@ -0,0 +1,7 @@
1
+ import * as TemporaryMessagePort from './TemporaryMessagePort.js'
2
+
3
+ export const name = 'TemporaryMessagePort'
4
+
5
+ export const Commands = {
6
+ handlePort: TemporaryMessagePort.handlePort,
7
+ }
@@ -0,0 +1,24 @@
1
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js'
2
+ import * as Assert from '../Assert/Assert.js'
3
+
4
+ export const state = {
5
+ ports: Object.create(null),
6
+ }
7
+
8
+ export const create = async (name) => {
9
+ Assert.string(name)
10
+ await ParentIpc.invoke('TemporaryMessagePort.create', name)
11
+ const port = state.ports[name]
12
+ if (!port) {
13
+ throw new Error(`port was not created`)
14
+ }
15
+ delete state.ports[name]
16
+ port.start()
17
+ return port
18
+ }
19
+
20
+ export const handlePort = (port, name) => {
21
+ Assert.string(name)
22
+ Assert.object(port)
23
+ state.ports[name] = port
24
+ }