@lvce-editor/shared-process 0.22.7 → 0.23.1
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 +6 -5
- package/src/parts/ElectronBrowserView/ElectronBrowserView.js +17 -6
- package/src/parts/ElectronBrowserViewFunctions/ElectronBrowserViewFunctions.js +11 -18
- package/src/parts/ElectronBrowserViewIpcState/ElectronBrowserViewIpcState.js +19 -0
- package/src/parts/ElectronBrowserViewState/ElectronBrowserViewState.js +15 -0
- package/src/parts/ElectronWebContents/ElectronWebContents.ipc.js +14 -0
- package/src/parts/ElectronWebContents/ElectronWebContents.js +73 -0
- package/src/parts/ElectronWindow/ElectronWindow.ipc.js +3 -2
- package/src/parts/ElectronWindow/ElectronWindow.js +9 -0
- package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +1 -45
- package/src/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js +1 -59
- package/src/parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js +1 -53
- package/src/parts/Module/Module.js +2 -0
- package/src/parts/ModuleId/ModuleId.js +1 -0
- package/src/parts/ModuleMap/ModuleMap.js +11 -2
- package/src/parts/Platform/Platform.js +3 -3
- package/src/parts/RequiresSocket/RequiresSocket.js +1 -0
- package/src/parts/AppWindowStates/AppWindowStates.js +0 -62
- package/src/parts/ChildProcess/ChildProcessWithFork.js +0 -19
- package/src/parts/ChildProcessError/ChildProcessError.js +0 -21
- package/src/parts/Configuration/Configuration.ipc.js +0 -6
- package/src/parts/Configuration/Configuration.js +0 -36
- package/src/parts/CreateCpuProfile/CreateCpuProfile.js +0 -59
- package/src/parts/Credentials/Credentials.ipc.js +0 -9
- package/src/parts/Credentials/Credentials.js +0 -61
- package/src/parts/DevtoolsProtocolRpc/DevtoolsProtocolRpc.js +0 -32
- package/src/parts/ErrorType/ErrorType.js +0 -4
- package/src/parts/ExtensionHostIpcWithWorker/ExtensionHostIpcWithWorker.js +0 -34
- package/src/parts/FirstWebSocketEventType/FirstWebSocketEventType.js +0 -2
- package/src/parts/GetActualPath/GetActualPath.js +0 -8
- package/src/parts/GetErrorConstructor/GetErrorConstructor.js +0 -28
- package/src/parts/GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js +0 -41
- package/src/parts/GetFirstWebSocketEvent/GetFirstWebSocketEvent.js +0 -25
- package/src/parts/GetHelpfulChildProcessError/GetHelpfulChildProcessError.js +0 -119
- package/src/parts/GetUtilityProcessPortData/GetUtilityProcessPortData.js +0 -10
- package/src/parts/Header/Header.js +0 -1
- package/src/parts/IsSocket/IsSocket.js +0 -5
- package/src/parts/IsWebSocketOpen/IsWebSocketOpen.js +0 -5
- package/src/parts/JsonParsingError/JsonParsingError.js +0 -19
- package/src/parts/MergeStacks/MergeStacks.js +0 -20
- package/src/parts/NormalizeErrorLine/NormalizeErrorLine.js +0 -9
- package/src/parts/PassThroughElectronMessageForTerminalProcess/PassThroughElectronMessageForTerminalProcess.js +0 -29
- package/src/parts/PassThroughElectronMessagePort/PassThroughElectronMessagePort.ipc.js +0 -7
- package/src/parts/PassThroughElectronMessagePort/PassThroughElectronMessagePort.js +0 -4
- package/src/parts/PassThroughElectronMessagePortModule/PassThroughElectronMessagePortModule.js +0 -8
- package/src/parts/WebSocketReadyState/WebSocketReadyState.js +0 -5
- package/src/parts/WebSocketSerialization/WebSocketSerialization.js +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@lvce-editor/assert": "^1.2.0",
|
|
21
|
-
"@lvce-editor/extension-host-helper-process": "0.
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.23.1",
|
|
22
|
+
"@lvce-editor/ipc": "^2.1.0",
|
|
22
23
|
"@lvce-editor/json-rpc": "^1.0.0",
|
|
23
24
|
"@lvce-editor/jsonc-parser": "^1.1.0",
|
|
24
|
-
"@lvce-editor/pretty-error": "^1.
|
|
25
|
-
"@lvce-editor/pty-host": "0.
|
|
25
|
+
"@lvce-editor/pretty-error": "^1.5.0",
|
|
26
|
+
"@lvce-editor/pty-host": "0.23.1",
|
|
26
27
|
"@lvce-editor/verror": "^1.1.2",
|
|
27
28
|
"@lvce-editor/web-socket-server": "^1.1.0",
|
|
28
29
|
"debug": "^4.3.4",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"got": "^13.0.0",
|
|
32
33
|
"is-object": "^1.0.2",
|
|
33
34
|
"p-queue": "^8.0.1",
|
|
34
|
-
"tar-fs": "^3.0.
|
|
35
|
+
"tar-fs": "^3.0.5",
|
|
35
36
|
"xdg-basedir": "^5.1.0"
|
|
36
37
|
},
|
|
37
38
|
"optionalDependencies": {
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
import * as ElectronBrowserViewIpcState from '../ElectronBrowserViewIpcState/ElectronBrowserViewIpcState.js'
|
|
2
|
+
import * as ElectronBrowserViewState from '../ElectronBrowserViewState/ElectronBrowserViewState.js'
|
|
3
|
+
import * as ElectronWebContents from '../ElectronWebContents/ElectronWebContents.js'
|
|
1
4
|
import * as ParentIpc from '../ParentIpc/ParentIpc.js'
|
|
2
5
|
|
|
3
|
-
export const createBrowserView = (restoreId, fallthroughKeyBindings) => {
|
|
4
|
-
|
|
6
|
+
export const createBrowserView = async (ipc, restoreId, fallthroughKeyBindings) => {
|
|
7
|
+
const webContentsId = await ParentIpc.invoke('ElectronBrowserView.createBrowserView2', restoreId)
|
|
8
|
+
ElectronBrowserViewIpcState.add(webContentsId, ipc)
|
|
9
|
+
// TODO get window id from renderer worker
|
|
10
|
+
await ParentIpc.invoke('ElectronBrowserView.attachEventListeners', webContentsId)
|
|
11
|
+
await ParentIpc.invoke('ElectronBrowserViewFunctions.setBackgroundColor', webContentsId, 'white')
|
|
12
|
+
return webContentsId
|
|
5
13
|
}
|
|
6
14
|
|
|
7
|
-
export const disposeBrowserView = (id) => {
|
|
8
|
-
|
|
15
|
+
export const disposeBrowserView = async (id) => {
|
|
16
|
+
ElectronBrowserViewState.remove(id)
|
|
17
|
+
await ParentIpc.invoke('ElectronBrowserView.disposeBrowserView', id)
|
|
18
|
+
await ElectronWebContents.dispose(id)
|
|
9
19
|
}
|
|
10
20
|
|
|
11
|
-
export const
|
|
12
|
-
|
|
21
|
+
export const handleBrowserViewCreated = (id) => {
|
|
22
|
+
console.log('created', id)
|
|
23
|
+
ElectronBrowserViewState.add(id)
|
|
13
24
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ParentIpc from '../ParentIpc/ParentIpc.js'
|
|
2
|
+
import * as ElectronWebContents from '../ElectronWebContents/ElectronWebContents.js'
|
|
2
3
|
|
|
3
4
|
export const resizeBrowserView = (id, x, y, width, height) => {
|
|
4
5
|
return ParentIpc.invoke('ElectronBrowserViewFunctions.resizeBrowserView', id, x, y, width, height)
|
|
@@ -8,25 +9,19 @@ export const setIframeSrc = async (id, iframeSrc) => {
|
|
|
8
9
|
return ParentIpc.invoke('ElectronBrowserViewFunctions.setIframeSrc', id, iframeSrc)
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
return ParentIpc.invoke('
|
|
12
|
+
const callFunction = (id, functionName) => {
|
|
13
|
+
return ParentIpc.invoke('ElectronWebContents.callFunction', id, functionName)
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export const
|
|
16
|
-
return ParentIpc.invoke('ElectronBrowserViewFunctions.openDevtools', id)
|
|
17
|
-
}
|
|
16
|
+
export const focus = ElectronWebContents.focus
|
|
18
17
|
|
|
19
|
-
export const
|
|
20
|
-
return ParentIpc.invoke('ElectronBrowserViewFunctions.reload', id)
|
|
21
|
-
}
|
|
18
|
+
export const openDevtools = ElectronWebContents.openDevtools
|
|
22
19
|
|
|
23
|
-
export const
|
|
24
|
-
return ParentIpc.invoke('ElectronBrowserViewFunctions.forward', id)
|
|
25
|
-
}
|
|
20
|
+
export const reload = ElectronWebContents.reload
|
|
26
21
|
|
|
27
|
-
export const
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
export const forward = ElectronWebContents.forward
|
|
23
|
+
|
|
24
|
+
export const backward = ElectronWebContents.backward
|
|
30
25
|
|
|
31
26
|
export const cancelNavigation = (id) => {
|
|
32
27
|
return ParentIpc.invoke('ElectronBrowserViewFunctions.cancelNavigation', id)
|
|
@@ -40,9 +35,7 @@ export const hide = (id) => {
|
|
|
40
35
|
return ParentIpc.invoke('ElectronBrowserViewFunctions.hide', id)
|
|
41
36
|
}
|
|
42
37
|
|
|
43
|
-
export const inspectElement =
|
|
44
|
-
return ParentIpc.invoke('ElectronBrowserViewFunctions.inspectElement', id, x, y)
|
|
45
|
-
}
|
|
38
|
+
export const inspectElement = ElectronWebContents.inspectElement
|
|
46
39
|
|
|
47
40
|
export const copyImageAt = (id, x, y) => {
|
|
48
41
|
return ParentIpc.invoke('ElectronBrowserViewFunctions.copyImageAt', id, x, y)
|
|
@@ -53,5 +46,5 @@ export const setFallthroughKeyBindings = (fallthroughKeyBindings) => {
|
|
|
53
46
|
}
|
|
54
47
|
|
|
55
48
|
export const getStats = (id) => {
|
|
56
|
-
return ParentIpc.invoke('
|
|
49
|
+
return ParentIpc.invoke('ElectronWebContents.getStats', id)
|
|
57
50
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const state = {
|
|
2
|
+
ipcMap: Object.create(null),
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const add = (id, ipc) => {
|
|
6
|
+
state.ipcMap[id] = ipc
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const get = (id) => {
|
|
10
|
+
return state.ipcMap[id]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const remove = (id) => {
|
|
14
|
+
delete state.ipcMap[id]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getAll = () => {
|
|
18
|
+
return Object.values(state.ipcMap)
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const state = {
|
|
2
|
+
browserViews: Object.create(null),
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const add = (id) => {
|
|
6
|
+
state.browserViews[id] = id
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const remove = (id) => {
|
|
10
|
+
delete state.browserViews[id]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const getAll = () => {
|
|
14
|
+
return Object.values(state.browserViews)
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as ElectronWebContents from './ElectronWebContents.js'
|
|
2
|
+
|
|
3
|
+
export const name = 'ElectronWebContents'
|
|
4
|
+
|
|
5
|
+
export const Commands = {
|
|
6
|
+
dispose: ElectronWebContents.dispose,
|
|
7
|
+
handleKeyBinding: ElectronWebContents.handleKeyBinding,
|
|
8
|
+
handleWindowOpen: ElectronWebContents.handleWindowOpen,
|
|
9
|
+
handleWillNavigate: ElectronWebContents.handleWillNavigate,
|
|
10
|
+
handleDidNavigate: ElectronWebContents.handleDidNavigate,
|
|
11
|
+
handleContextMenu: ElectronWebContents.handleContextMenu,
|
|
12
|
+
handleTitleUpdated: ElectronWebContents.handleTitleUpdated,
|
|
13
|
+
handleBrowserViewDestroyed: ElectronWebContents.handleBrowserViewDestroyed, // TODO rename to webcontents
|
|
14
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as ElectronBrowserViewIpcState from '../ElectronBrowserViewIpcState/ElectronBrowserViewIpcState.js'
|
|
2
|
+
import * as ElectronBrowserViewState from '../ElectronBrowserViewState/ElectronBrowserViewState.js'
|
|
3
|
+
import * as ParentIpc from '../ParentIpc/ParentIpc.js'
|
|
4
|
+
|
|
5
|
+
export const dispose = async (id) => {
|
|
6
|
+
await ParentIpc.invoke('ElectronWebContents.dispose', id)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const callFunction = (webContentsId, method, ...params) => {
|
|
10
|
+
return ParentIpc.invoke(`ElectronWebContents.callFunction`, webContentsId, method, ...params)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const focus = (webContentsId) => {
|
|
14
|
+
return callFunction(webContentsId, 'focus')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const openDevtools = (webContentsId) => {
|
|
18
|
+
return callFunction(webContentsId, 'openDevTools')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const reload = (webContentsId) => {
|
|
22
|
+
return callFunction(webContentsId, 'reload')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const forward = (webContentsId) => {
|
|
26
|
+
return callFunction(webContentsId, 'goForward')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const backward = (webContentsId) => {
|
|
30
|
+
return callFunction(webContentsId, 'goBack')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const inspectElement = (webContentsId, x, y) => {
|
|
34
|
+
return callFunction(webContentsId, `inspectElement`, x, y)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const handleWindowOpen = (webContentsId, url) => {
|
|
38
|
+
// TODO
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const forwardEvent = (method, webContentsId, ...params) => {
|
|
42
|
+
const ipc = ElectronBrowserViewIpcState.get(webContentsId)
|
|
43
|
+
if (!ipc) {
|
|
44
|
+
console.log('no ipc', { webContentsId })
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
ipc.send({
|
|
48
|
+
jsonrpc: '2.0',
|
|
49
|
+
method: `SimpleBrowser.${method}`,
|
|
50
|
+
params,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const handleWillNavigate = (...args) => {
|
|
55
|
+
return forwardEvent('handleWillNavigate', ...args)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const handleDidNavigate = (...args) => {
|
|
59
|
+
return forwardEvent('handleDidNavigate', ...args)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const handleContextMenu = (...args) => {
|
|
63
|
+
return forwardEvent('handleContextMenu', ...args)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const handleTitleUpdated = (...args) => {
|
|
67
|
+
return forwardEvent('handleTitleUpdated', ...args)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const handleBrowserViewDestroyed = (id) => {
|
|
71
|
+
ElectronBrowserViewState.remove(id)
|
|
72
|
+
ElectronBrowserViewIpcState.remove(id)
|
|
73
|
+
}
|
|
@@ -4,14 +4,15 @@ export const name = 'ElectronWindow'
|
|
|
4
4
|
|
|
5
5
|
export const Commands = {
|
|
6
6
|
close: ElectronWindow.close,
|
|
7
|
+
focus: ElectronWindow.focus,
|
|
8
|
+
getZoom: ElectronWindow.getZoom,
|
|
7
9
|
maximize: ElectronWindow.maximize,
|
|
8
10
|
minimize: ElectronWindow.minimize,
|
|
11
|
+
openNew: ElectronWindow.openNew,
|
|
9
12
|
reload: ElectronWindow.reload,
|
|
10
13
|
toggleDevtools: ElectronWindow.toggleDevtools,
|
|
11
14
|
unmaximize: ElectronWindow.unmaximize,
|
|
12
15
|
zoomIn: ElectronWindow.zoomIn,
|
|
13
16
|
zoomOut: ElectronWindow.zoomOut,
|
|
14
17
|
zoomReset: ElectronWindow.zoomReset,
|
|
15
|
-
openNew: ElectronWindow.openNew,
|
|
16
|
-
focus: ElectronWindow.focus,
|
|
17
18
|
}
|
|
@@ -92,6 +92,11 @@ export const zoomReset = (windowId) => {
|
|
|
92
92
|
return setZoom(windowId, getDefaultZoomLevel(), getMinZoomLevel(), getMaxZoomLevel())
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
export const getZoom = (windowId) => {
|
|
96
|
+
// TODO zoom level should be stored in shared process
|
|
97
|
+
return ParentIpc.invoke('ElectronWindow.getZoom', windowId)
|
|
98
|
+
}
|
|
99
|
+
|
|
95
100
|
export const focus = (windowId) => {
|
|
96
101
|
return ParentIpc.invoke('ElectronWindow.executeWebContentsFunction', windowId, 'focus')
|
|
97
102
|
}
|
|
@@ -99,3 +104,7 @@ export const focus = (windowId) => {
|
|
|
99
104
|
export const handleClose = (windowId) => {
|
|
100
105
|
// TODO
|
|
101
106
|
}
|
|
107
|
+
|
|
108
|
+
export const getFocusedWindowId = () => {
|
|
109
|
+
return ParentIpc.invoke('ElectronWindow.getFocusedWindowId')
|
|
110
|
+
}
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const listen = () => {
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
const { parentPort } = process
|
|
6
|
-
if (!parentPort) {
|
|
7
|
-
throw new Error('parent port must be defined')
|
|
8
|
-
}
|
|
9
|
-
return parentPort
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const signal = (parentPort) => {
|
|
13
|
-
parentPort.postMessage('ready')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const wrap = (parentPort) => {
|
|
17
|
-
return {
|
|
18
|
-
parentPort,
|
|
19
|
-
on(event, listener) {
|
|
20
|
-
if (event === 'message') {
|
|
21
|
-
const wrappedListener = (event) => {
|
|
22
|
-
const actualData = GetUtilityProcessPortData.getUtilityProcessPortData(event)
|
|
23
|
-
listener(actualData)
|
|
24
|
-
}
|
|
25
|
-
this.parentPort.on(event, wrappedListener)
|
|
26
|
-
} else if (event === 'close') {
|
|
27
|
-
this.parentPort.on('close', listener)
|
|
28
|
-
} else {
|
|
29
|
-
throw new Error('unsupported event type')
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
off(event, listener) {
|
|
33
|
-
this.parentPort.off(event, listener)
|
|
34
|
-
},
|
|
35
|
-
send(message) {
|
|
36
|
-
this.parentPort.postMessage(message)
|
|
37
|
-
},
|
|
38
|
-
sendAndTransfer(message, transfer) {
|
|
39
|
-
this.parentPort.postMessage(message, transfer)
|
|
40
|
-
},
|
|
41
|
-
dispose() {
|
|
42
|
-
this.parentPort.close()
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js'
|
|
@@ -1,59 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { IpcError } from '../IpcError/IpcError.js'
|
|
3
|
-
import * as IsWebSocketOpen from '../IsWebSocketOpen/IsWebSocketOpen.js'
|
|
4
|
-
import * as WebSocketSerialization from '../WebSocketSerialization/WebSocketSerialization.js'
|
|
5
|
-
import * as WebSocketServer from '../WebSocketServer/WebSocketServer.js'
|
|
6
|
-
|
|
7
|
-
export const listen = async ({ request, handle }) => {
|
|
8
|
-
if (!request) {
|
|
9
|
-
throw new IpcError('request must be defined')
|
|
10
|
-
}
|
|
11
|
-
if (!handle) {
|
|
12
|
-
throw new IpcError('handle must be defined')
|
|
13
|
-
}
|
|
14
|
-
const webSocket = await WebSocketServer.handleUpgrade(request, handle)
|
|
15
|
-
webSocket.pause()
|
|
16
|
-
if (!IsWebSocketOpen.isWebSocketOpen(webSocket)) {
|
|
17
|
-
const { type, event } = await GetFirstWebSocketEvent.getFirstWebSocketEvent(webSocket)
|
|
18
|
-
}
|
|
19
|
-
return webSocket
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const wrap = (webSocket) => {
|
|
23
|
-
return {
|
|
24
|
-
webSocket,
|
|
25
|
-
/**
|
|
26
|
-
* @type {any}
|
|
27
|
-
*/
|
|
28
|
-
wrappedListener: undefined,
|
|
29
|
-
on(event, listener) {
|
|
30
|
-
switch (event) {
|
|
31
|
-
case 'message':
|
|
32
|
-
const wrappedListener = (message) => {
|
|
33
|
-
const data = WebSocketSerialization.deserialize(message)
|
|
34
|
-
listener(data)
|
|
35
|
-
}
|
|
36
|
-
webSocket.on('message', wrappedListener)
|
|
37
|
-
break
|
|
38
|
-
case 'close':
|
|
39
|
-
webSocket.on('close', listener)
|
|
40
|
-
break
|
|
41
|
-
default:
|
|
42
|
-
throw new Error('unknown event listener type')
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
off(event, listener) {
|
|
46
|
-
this.webSocket.off(event, listener)
|
|
47
|
-
},
|
|
48
|
-
send(message) {
|
|
49
|
-
const stringifiedMessage = WebSocketSerialization.serialize(message)
|
|
50
|
-
this.webSocket.send(stringifiedMessage)
|
|
51
|
-
},
|
|
52
|
-
dispose() {
|
|
53
|
-
this.webSocket.close()
|
|
54
|
-
},
|
|
55
|
-
start() {
|
|
56
|
-
this.webSocket.resume()
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js'
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Assert from '../Assert/Assert.js'
|
|
3
|
-
import { ChildProcessError } from '../ChildProcessError/ChildProcessError.js'
|
|
4
|
-
import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
|
|
5
|
-
import * as GetFirstNodeChildProcessEvent from '../GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js'
|
|
6
|
-
import { VError } from '../VError/VError.js'
|
|
7
|
-
|
|
8
|
-
export const create = async ({ path, argv = [], env, execArgv = [], stdio = 'inherit', name = 'child process' }) => {
|
|
9
|
-
try {
|
|
10
|
-
Assert.string(path)
|
|
11
|
-
const actualArgv = ['--ipc-type=node-forked-process', ...argv]
|
|
12
|
-
const childProcess = fork(path, actualArgv, {
|
|
13
|
-
env,
|
|
14
|
-
execArgv,
|
|
15
|
-
stdio: 'pipe',
|
|
16
|
-
})
|
|
17
|
-
const { type, event, stdout, stderr } = await GetFirstNodeChildProcessEvent.getFirstNodeChildProcessEvent(childProcess)
|
|
18
|
-
if (type === FirstNodeWorkerEventType.Exit) {
|
|
19
|
-
throw new ChildProcessError(stderr)
|
|
20
|
-
}
|
|
21
|
-
if (type === FirstNodeWorkerEventType.Error) {
|
|
22
|
-
throw new Error(`child process had an error ${event}`)
|
|
23
|
-
}
|
|
24
|
-
if (stdio === 'inherit' && childProcess.stdout && childProcess.stderr) {
|
|
25
|
-
childProcess.stdout.pipe(process.stdout)
|
|
26
|
-
childProcess.stderr.pipe(process.stderr)
|
|
27
|
-
}
|
|
28
|
-
return childProcess
|
|
29
|
-
} catch (error) {
|
|
30
|
-
throw new VError(error, `Failed to launch ${name}`)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const wrap = (childProcess) => {
|
|
35
|
-
return {
|
|
36
|
-
childProcess,
|
|
37
|
-
on(event, listener) {
|
|
38
|
-
this.childProcess.on(event, listener)
|
|
39
|
-
},
|
|
40
|
-
off(event, listener) {
|
|
41
|
-
this.childProcess.off(event, listener)
|
|
42
|
-
},
|
|
43
|
-
send(message) {
|
|
44
|
-
this.childProcess.send(message)
|
|
45
|
-
},
|
|
46
|
-
sendAndTransfer(message, handle) {
|
|
47
|
-
this.childProcess.send(message, handle)
|
|
48
|
-
},
|
|
49
|
-
dispose() {
|
|
50
|
-
this.childProcess.kill()
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js'
|
|
@@ -140,6 +140,8 @@ export const load = (moduleId) => {
|
|
|
140
140
|
return import('../HandleRemoteRequest/HandleRemoteRequest.ipc.js')
|
|
141
141
|
case ModuleId.HandleMessagePortForExtensionHostHelperProcess:
|
|
142
142
|
return import('../HandleMessagePortForExtensionHostHelperProcess/HandleMessagePortForExtensionHostHelperProcess.ipc.js')
|
|
143
|
+
case ModuleId.ElectronWebContents:
|
|
144
|
+
return import('../ElectronWebContents/ElectronWebContents.ipc.js')
|
|
143
145
|
default:
|
|
144
146
|
throw new Error(`module ${moduleId} not found`)
|
|
145
147
|
}
|
|
@@ -261,16 +261,17 @@ export const getModuleId = (commandId) => {
|
|
|
261
261
|
case 'WebSocketServer.handleUpgrade':
|
|
262
262
|
return ModuleId.WebSocketServer
|
|
263
263
|
case 'ElectronWindow.close':
|
|
264
|
+
case 'ElectronWindow.focus':
|
|
265
|
+
case 'ElectronWindow.getZoom':
|
|
264
266
|
case 'ElectronWindow.maximize':
|
|
265
267
|
case 'ElectronWindow.minimize':
|
|
268
|
+
case 'ElectronWindow.openNew':
|
|
266
269
|
case 'ElectronWindow.reload':
|
|
267
270
|
case 'ElectronWindow.toggleDevtools':
|
|
268
271
|
case 'ElectronWindow.unmaximize':
|
|
269
272
|
case 'ElectronWindow.zoomIn':
|
|
270
273
|
case 'ElectronWindow.zoomOut':
|
|
271
274
|
case 'ElectronWindow.zoomReset':
|
|
272
|
-
case 'ElectronWindow.focus':
|
|
273
|
-
case 'ElectronWindow.openNew':
|
|
274
275
|
return ModuleId.Window
|
|
275
276
|
case 'Workspace.getHomeDir':
|
|
276
277
|
case 'Workspace.resolveRoot':
|
|
@@ -295,6 +296,14 @@ export const getModuleId = (commandId) => {
|
|
|
295
296
|
return ModuleId.HandleRemoteRequest
|
|
296
297
|
case 'HandleMessagePortForExtensionHostHelperProcess.handleMessagePortForExtensionHostHelperProcess':
|
|
297
298
|
return ModuleId.HandleMessagePortForExtensionHostHelperProcess
|
|
299
|
+
case 'ElectronWebContents.dispose':
|
|
300
|
+
case 'ElectronWebContents.handleKeyBinding':
|
|
301
|
+
case 'ElectronWebContents.handleWindowOpen':
|
|
302
|
+
case 'ElectronWebContents.handleWillNavigate':
|
|
303
|
+
case 'ElectronWebContents.handleDidNavigate':
|
|
304
|
+
case 'ElectronWebContents.handleContextMenu':
|
|
305
|
+
case 'ElectronWebContents.handlePageTitleUpdated':
|
|
306
|
+
return ModuleId.ElectronWebContents
|
|
298
307
|
default:
|
|
299
308
|
throw new CommandNotFoundError(commandId)
|
|
300
309
|
}
|
|
@@ -61,11 +61,11 @@ export const getSetupName = () => {
|
|
|
61
61
|
return 'Lvce-Setup'
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export const version = '0.
|
|
64
|
+
export const version = '0.23.1'
|
|
65
65
|
|
|
66
|
-
export const commit = '
|
|
66
|
+
export const commit = 'b40d3e9'
|
|
67
67
|
|
|
68
|
-
export const date = '2024-
|
|
68
|
+
export const date = '2024-02-11T08:32:28.000Z'
|
|
69
69
|
|
|
70
70
|
export const getVersion = () => {
|
|
71
71
|
return version
|
|
@@ -11,6 +11,7 @@ const METHODS_THAT_REQUIRE_SOCKET = new Set([
|
|
|
11
11
|
'ElectronApplicationMenu.setItems',
|
|
12
12
|
'GetWindowId.getWindowId',
|
|
13
13
|
'HandleMessagePortForExtensionHostHelperProcess.handleMessagePortForExtensionHostHelperProcess',
|
|
14
|
+
'ElectronBrowserView.createBrowserView',
|
|
14
15
|
])
|
|
15
16
|
|
|
16
17
|
export const requiresSocket = (method) => {
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export const state = {
|
|
2
|
-
/**
|
|
3
|
-
* @type {any[]}
|
|
4
|
-
*/
|
|
5
|
-
windowStates: [],
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const findByWindowId = (windowId) => {
|
|
9
|
-
const { windowStates } = state
|
|
10
|
-
for (const windowState of windowStates) {
|
|
11
|
-
if (windowState.windowId === windowId) {
|
|
12
|
-
return windowState
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return undefined
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const findByWebContentsId = (webContentsId) => {
|
|
19
|
-
const { windowStates } = state
|
|
20
|
-
for (const windowState of windowStates) {
|
|
21
|
-
if (windowState.webContentsId === webContentsId) {
|
|
22
|
-
return windowState
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return undefined
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const findIndexById = (id) => {
|
|
29
|
-
const { windowStates } = state
|
|
30
|
-
for (let i = 0; i < windowStates.length; i++) {
|
|
31
|
-
const windowState = windowStates[i]
|
|
32
|
-
if (windowState.windowId === id) {
|
|
33
|
-
return i
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return -1
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const remove = (windowId) => {
|
|
40
|
-
const index = findIndexById(windowId)
|
|
41
|
-
if (index === -1) {
|
|
42
|
-
throw new Error(`expected window ${windowId} to be in windows array`)
|
|
43
|
-
}
|
|
44
|
-
state.windowStates.splice(index, 1)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const getAll = () => {
|
|
48
|
-
return state.windowStates
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const add = (config) => {
|
|
52
|
-
state.windowStates.push(config)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const findByPort = (port) => {
|
|
56
|
-
for (const config of state.windowStates) {
|
|
57
|
-
if (config.port === port) {
|
|
58
|
-
return config
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return undefined
|
|
62
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { fork } from 'node:child_process'
|
|
2
|
-
|
|
3
|
-
export const create = (path) => {
|
|
4
|
-
const childProcess = fork(path)
|
|
5
|
-
let _listener
|
|
6
|
-
return {
|
|
7
|
-
get onmessage() {
|
|
8
|
-
return _listener
|
|
9
|
-
},
|
|
10
|
-
set onmessage(listener) {
|
|
11
|
-
if (listener) {
|
|
12
|
-
childProcess.on('message', listener)
|
|
13
|
-
} else {
|
|
14
|
-
childProcess.off('message', listener)
|
|
15
|
-
}
|
|
16
|
-
_listener = listener
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as GetHelpfulChildProcessError from '../GetHelpfulChildProcessError/GetHelpfulChildProcessError.js'
|
|
2
|
-
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
3
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
4
|
-
|
|
5
|
-
export class ChildProcessError extends Error {
|
|
6
|
-
constructor(stderr) {
|
|
7
|
-
const { message, code, stack } = GetHelpfulChildProcessError.getHelpfulChildProcessError('', stderr)
|
|
8
|
-
super(message || 'child process error')
|
|
9
|
-
this.name = 'ChildProcessError'
|
|
10
|
-
if (code) {
|
|
11
|
-
this.code = code
|
|
12
|
-
}
|
|
13
|
-
if (stack) {
|
|
14
|
-
const lines = SplitLines.splitLines(this.stack)
|
|
15
|
-
const [firstLine, ...stackLines] = lines
|
|
16
|
-
const newStackLines = [firstLine, ...stack, ...stackLines]
|
|
17
|
-
const newStack = JoinLines.joinLines(newStackLines)
|
|
18
|
-
this.stack = newStack
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as Character from '../Character/Character.js'
|
|
2
|
-
import { writeFile } from '../FileSystem/FileSystem.js'
|
|
3
|
-
import * as JsonFile from '../JsonFile/JsonFile.js'
|
|
4
|
-
|
|
5
|
-
let settings
|
|
6
|
-
let settingsPromise
|
|
7
|
-
|
|
8
|
-
const readSettings = async () => {
|
|
9
|
-
// TODO allow jsonc
|
|
10
|
-
if (!settings) {
|
|
11
|
-
if (!settingsPromise) {
|
|
12
|
-
settingsPromise = JsonFile.readJson('/tmp/settings.json')
|
|
13
|
-
}
|
|
14
|
-
await settingsPromise
|
|
15
|
-
}
|
|
16
|
-
return settings
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const writeSettings = async () => {
|
|
20
|
-
// TODO jsonc
|
|
21
|
-
await writeFile('/tmp/settings.json', JSON.stringify(settings, null, 2) + Character.NewLine)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const get = async (key) => {
|
|
25
|
-
await readSettings()
|
|
26
|
-
// TODO allow nested object get
|
|
27
|
-
return settings[key]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const set = async (key, value) => {
|
|
31
|
-
await readSettings()
|
|
32
|
-
// TODO allow nested object set?
|
|
33
|
-
// how does vscode do it?
|
|
34
|
-
settings[key] = value
|
|
35
|
-
await writeSettings()
|
|
36
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'node:fs/promises'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { join } from 'node:path'
|
|
4
|
-
import got from 'got'
|
|
5
|
-
import { WebSocket } from 'ws'
|
|
6
|
-
import * as DevtoolsProtocolRpc from '../DevtoolsProtocolRpc/DevtoolsProtocolRpc.js'
|
|
7
|
-
|
|
8
|
-
const createConnection = (webSocketDebuggerUrl) => {
|
|
9
|
-
const webSocket = new WebSocket(webSocketDebuggerUrl)
|
|
10
|
-
// console.log({ webSocket })
|
|
11
|
-
return {
|
|
12
|
-
on(event, listener) {
|
|
13
|
-
if (event === 'message') {
|
|
14
|
-
const wrappedListener = (string) => {
|
|
15
|
-
listener(JSON.parse(string))
|
|
16
|
-
}
|
|
17
|
-
webSocket.on(event, wrappedListener)
|
|
18
|
-
} else {
|
|
19
|
-
webSocket.on(event, listener)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
send(message) {
|
|
23
|
-
webSocket.send(JSON.stringify(message))
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const createCpuProfile = async (pid) => {
|
|
29
|
-
// AttachDebugger.attachDebugger(pid)
|
|
30
|
-
const response = await got('http://localhost:9229/json/list').json()
|
|
31
|
-
const first = response[0]
|
|
32
|
-
const { webSocketDebuggerUrl } = first
|
|
33
|
-
const ipc = createConnection(webSocketDebuggerUrl)
|
|
34
|
-
|
|
35
|
-
await new Promise((r) => {
|
|
36
|
-
ipc.on('open', r)
|
|
37
|
-
})
|
|
38
|
-
const rpc = DevtoolsProtocolRpc.create(ipc)
|
|
39
|
-
const result = await rpc.invoke('Debugger.enable')
|
|
40
|
-
const { debuggerId } = result.result
|
|
41
|
-
console.log({ debuggerId })
|
|
42
|
-
const p = await rpc.invoke('Profiler.enable')
|
|
43
|
-
await rpc.invoke('Profiler.start')
|
|
44
|
-
await new Promise((r) => {
|
|
45
|
-
setTimeout(r, 10000)
|
|
46
|
-
})
|
|
47
|
-
const profileResult = await rpc.invoke('Profiler.stop')
|
|
48
|
-
console.log({ profileResult })
|
|
49
|
-
const { profile } = profileResult.result
|
|
50
|
-
const profilePath = join(tmpdir(), 'node-profile.cpuprofile')
|
|
51
|
-
const profileString = JSON.stringify(profile)
|
|
52
|
-
await writeFile(profilePath, profileString)
|
|
53
|
-
console.log('finished')
|
|
54
|
-
// const value = await rpc.invoke('Runtime.evaluate', {
|
|
55
|
-
// expression: '1+1',
|
|
56
|
-
// })
|
|
57
|
-
// await rpc.invoke('Debugger.pause')
|
|
58
|
-
// console.log({ value })
|
|
59
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as Credentials from './Credentials.js'
|
|
2
|
-
|
|
3
|
-
export const Commands = {
|
|
4
|
-
deletePassword: Credentials.deletePassword,
|
|
5
|
-
findCredentials: Credentials.findCredentials,
|
|
6
|
-
findPassword: Credentials.findPassword,
|
|
7
|
-
getPassword: Credentials.getPassword,
|
|
8
|
-
setPassword: Credentials.setPassword,
|
|
9
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import keytar from 'keytar'
|
|
2
|
-
import { VError } from '../VError/VError.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} service
|
|
6
|
-
* @param {string} account
|
|
7
|
-
*/
|
|
8
|
-
export const deletePassword = async (service, account) => {
|
|
9
|
-
try {
|
|
10
|
-
return await keytar.deletePassword(service, account)
|
|
11
|
-
} catch (error) {
|
|
12
|
-
throw new VError(error, `Failed to delete password from service ${service}`)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {string} service
|
|
18
|
-
*/
|
|
19
|
-
export const findCredentials = async (service) => {
|
|
20
|
-
try {
|
|
21
|
-
return keytar.findCredentials(service)
|
|
22
|
-
} catch (error) {
|
|
23
|
-
throw new VError(error, `Failed to find credentials from service ${service}`)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {string} service
|
|
29
|
-
*/
|
|
30
|
-
export const findPassword = async (service) => {
|
|
31
|
-
try {
|
|
32
|
-
return await keytar.findPassword(service)
|
|
33
|
-
} catch (error) {
|
|
34
|
-
throw new VError(error, `Failed to find password from service ${service}`)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param {string} service
|
|
40
|
-
* @param {string} account
|
|
41
|
-
*/
|
|
42
|
-
export const getPassword = async (service, account) => {
|
|
43
|
-
try {
|
|
44
|
-
return await keytar.getPassword(service, account)
|
|
45
|
-
} catch (error) {
|
|
46
|
-
throw new VError(error, `Failed to get password from service ${service}`)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @param {string} service
|
|
52
|
-
* @param {string} account
|
|
53
|
-
* @param {string} password
|
|
54
|
-
*/
|
|
55
|
-
export const setPassword = async (service, account, password) => {
|
|
56
|
-
try {
|
|
57
|
-
return await keytar.setPassword(service, account, password)
|
|
58
|
-
} catch (error) {
|
|
59
|
-
throw new VError(error, `Failed to set password for service ${service}`)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const Id = {
|
|
2
|
-
id: 1,
|
|
3
|
-
create() {
|
|
4
|
-
return this.id++
|
|
5
|
-
},
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const create = (ipc) => {
|
|
9
|
-
const callbacks = Object.create(null)
|
|
10
|
-
const handleMessage = (message) => {
|
|
11
|
-
if ('result' in message) {
|
|
12
|
-
const callback = callbacks[message.id]
|
|
13
|
-
callback(message)
|
|
14
|
-
delete callbacks[message.id]
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
ipc.on('message', handleMessage)
|
|
18
|
-
return {
|
|
19
|
-
invoke(method, params = {}) {
|
|
20
|
-
const id = Id.create()
|
|
21
|
-
const promise = new Promise((resolve, reject) => {
|
|
22
|
-
callbacks[id] = resolve
|
|
23
|
-
})
|
|
24
|
-
ipc.send({
|
|
25
|
-
method,
|
|
26
|
-
id,
|
|
27
|
-
params,
|
|
28
|
-
})
|
|
29
|
-
return promise
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Worker } from 'node:worker_threads'
|
|
2
|
-
import * as Platform from '../Platform/Platform.js'
|
|
3
|
-
|
|
4
|
-
export const create = async () => {
|
|
5
|
-
const extensionHostPath = await Platform.getExtensionHostPath()
|
|
6
|
-
const child = new Worker(extensionHostPath, {
|
|
7
|
-
execArgv: ['--experimental-json-modules', '--max-old-space-size=60', '--enable-source-maps'],
|
|
8
|
-
env: {
|
|
9
|
-
...process.env,
|
|
10
|
-
LOGS_DIR: Platform.getLogsDir(),
|
|
11
|
-
CONFIG_DIR: Platform.getConfigDir(),
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
return {
|
|
15
|
-
on(event, listener) {
|
|
16
|
-
switch (event) {
|
|
17
|
-
case 'message':
|
|
18
|
-
child.on('message', listener)
|
|
19
|
-
break
|
|
20
|
-
case 'error':
|
|
21
|
-
child.on('error', listener)
|
|
22
|
-
break
|
|
23
|
-
default:
|
|
24
|
-
break
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
send(message) {
|
|
28
|
-
child.postMessage(message)
|
|
29
|
-
},
|
|
30
|
-
dispose() {
|
|
31
|
-
child.terminate()
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as ErrorType from '../ErrorType/ErrorType.js'
|
|
2
|
-
|
|
3
|
-
export const getErrorConstructor = (message, type) => {
|
|
4
|
-
if (type) {
|
|
5
|
-
switch (type) {
|
|
6
|
-
case ErrorType.DomException:
|
|
7
|
-
return DOMException
|
|
8
|
-
case ErrorType.TypeError:
|
|
9
|
-
return TypeError
|
|
10
|
-
case ErrorType.SyntaxError:
|
|
11
|
-
return SyntaxError
|
|
12
|
-
case ErrorType.ReferenceError:
|
|
13
|
-
return ReferenceError
|
|
14
|
-
default:
|
|
15
|
-
return Error
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (message.startsWith('TypeError: ')) {
|
|
19
|
-
return TypeError
|
|
20
|
-
}
|
|
21
|
-
if (message.startsWith('SyntaxError: ')) {
|
|
22
|
-
return SyntaxError
|
|
23
|
-
}
|
|
24
|
-
if (message.startsWith('ReferenceError: ')) {
|
|
25
|
-
return ReferenceError
|
|
26
|
-
}
|
|
27
|
-
return Error
|
|
28
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
|
|
2
|
-
|
|
3
|
-
export const getFirstNodeChildProcessEvent = async (childProcess) => {
|
|
4
|
-
const { type, event, stdout, stderr } = await new Promise((resolve, reject) => {
|
|
5
|
-
let stderr = ''
|
|
6
|
-
let stdout = ''
|
|
7
|
-
const cleanup = (value) => {
|
|
8
|
-
if (childProcess.stdout && childProcess.stderr) {
|
|
9
|
-
childProcess.stderr.off('data', handleStdErrData)
|
|
10
|
-
childProcess.stdout.off('data', handleStdoutData)
|
|
11
|
-
}
|
|
12
|
-
childProcess.off('message', handleMessage)
|
|
13
|
-
childProcess.off('exit', handleExit)
|
|
14
|
-
childProcess.off('error', handleError)
|
|
15
|
-
resolve(value)
|
|
16
|
-
}
|
|
17
|
-
const handleStdErrData = (data) => {
|
|
18
|
-
stderr += data
|
|
19
|
-
}
|
|
20
|
-
const handleStdoutData = (data) => {
|
|
21
|
-
stdout += data
|
|
22
|
-
}
|
|
23
|
-
const handleMessage = (event) => {
|
|
24
|
-
cleanup({ type: FirstNodeWorkerEventType.Message, event, stdout, stderr })
|
|
25
|
-
}
|
|
26
|
-
const handleExit = (event) => {
|
|
27
|
-
cleanup({ type: FirstNodeWorkerEventType.Exit, event, stdout, stderr })
|
|
28
|
-
}
|
|
29
|
-
const handleError = (event) => {
|
|
30
|
-
cleanup({ type: FirstNodeWorkerEventType.Error, event, stdout, stderr })
|
|
31
|
-
}
|
|
32
|
-
if (childProcess.stdout && childProcess.stderr) {
|
|
33
|
-
childProcess.stderr.on('data', handleStdErrData)
|
|
34
|
-
childProcess.stdout.on('data', handleStdoutData)
|
|
35
|
-
}
|
|
36
|
-
childProcess.on('message', handleMessage)
|
|
37
|
-
childProcess.on('exit', handleExit)
|
|
38
|
-
childProcess.on('error', handleError)
|
|
39
|
-
})
|
|
40
|
-
return { type, event, stdout, stderr }
|
|
41
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as FirstWebSocketEventType from '../FirstWebSocketEventType/FirstWebSocketEventType.js'
|
|
2
|
-
import * as GetFirstEvent from '../GetFirstEvent/GetFirstEvent.js'
|
|
3
|
-
import * as WebSocketReadyState from '../WebSocketReadyState/WebSocketReadyState.js'
|
|
4
|
-
|
|
5
|
-
export const getFirstWebSocketEvent = async (webSocket) => {
|
|
6
|
-
switch (webSocket.readyState) {
|
|
7
|
-
case WebSocketReadyState.Open:
|
|
8
|
-
return {
|
|
9
|
-
type: FirstWebSocketEventType.Open,
|
|
10
|
-
event: undefined,
|
|
11
|
-
}
|
|
12
|
-
case WebSocketReadyState.Closed:
|
|
13
|
-
return {
|
|
14
|
-
type: FirstWebSocketEventType.Close,
|
|
15
|
-
event: undefined,
|
|
16
|
-
}
|
|
17
|
-
default:
|
|
18
|
-
break
|
|
19
|
-
}
|
|
20
|
-
const { type, event } = await GetFirstEvent.getFirstEvent(webSocket, {
|
|
21
|
-
open: FirstWebSocketEventType.Open,
|
|
22
|
-
close: FirstWebSocketEventType.Close,
|
|
23
|
-
})
|
|
24
|
-
return { type, event }
|
|
25
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
2
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
3
|
-
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
4
|
-
|
|
5
|
-
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/
|
|
6
|
-
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/
|
|
7
|
-
|
|
8
|
-
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/
|
|
9
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/
|
|
10
|
-
|
|
11
|
-
const RE_AT = /^\s+at/
|
|
12
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/
|
|
13
|
-
|
|
14
|
-
const isUnhelpfulNativeModuleError = (stderr) => {
|
|
15
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const isMessageCodeBlockStartIndex = (line) => {
|
|
19
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const isMessageCodeBlockEndIndex = (line) => {
|
|
23
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const getMessageCodeBlock = (stderr) => {
|
|
27
|
-
const lines = SplitLines.splitLines(stderr)
|
|
28
|
-
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex)
|
|
29
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex)
|
|
30
|
-
const relevantLines = lines.slice(startIndex, endIndex)
|
|
31
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length)
|
|
32
|
-
return relevantMessage
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const getNativeModuleErrorMessage = (stderr) => {
|
|
36
|
-
const message = getMessageCodeBlock(stderr)
|
|
37
|
-
return {
|
|
38
|
-
message: `Incompatible native node module: ${message}`,
|
|
39
|
-
code: ErrorCodes.E_INCOMPATIBLE_NATIVE_MODULE,
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const isModulesSyntaxError = (stderr) => {
|
|
44
|
-
if (!stderr) {
|
|
45
|
-
return false
|
|
46
|
-
}
|
|
47
|
-
return stderr.includes('SyntaxError: Cannot use import statement outside a module')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const getModuleSyntaxError = (stderr) => {
|
|
51
|
-
return {
|
|
52
|
-
message: `ES Modules are not supported in electron`,
|
|
53
|
-
code: ErrorCodes.E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const isModuleNotFoundError = (stderr) => {
|
|
58
|
-
if (!stderr) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
return stderr.includes('ERR_MODULE_NOT_FOUND')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const isModuleNotFoundMessage = (line) => {
|
|
65
|
-
return line.includes('ERR_MODULE_NOT_FOUND')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const getModuleNotFoundError = (stderr) => {
|
|
69
|
-
const lines = SplitLines.splitLines(stderr)
|
|
70
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage)
|
|
71
|
-
const message = lines[messageIndex]
|
|
72
|
-
return {
|
|
73
|
-
message,
|
|
74
|
-
code: ErrorCodes.ERR_MODULE_NOT_FOUND,
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const isNormalStackLine = (line) => {
|
|
79
|
-
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const getDetails = (lines) => {
|
|
83
|
-
const index = lines.findIndex(isNormalStackLine)
|
|
84
|
-
if (index === -1) {
|
|
85
|
-
return {
|
|
86
|
-
actualMessage: JoinLines.joinLines(lines),
|
|
87
|
-
rest: [],
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
let lastIndex = index - 1
|
|
91
|
-
while (++lastIndex < lines.length) {
|
|
92
|
-
if (!isNormalStackLine(lines[lastIndex])) {
|
|
93
|
-
break
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
actualMessage: lines[index - 1],
|
|
98
|
-
rest: lines.slice(index, lastIndex),
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
103
|
-
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
104
|
-
return getNativeModuleErrorMessage(stderr)
|
|
105
|
-
}
|
|
106
|
-
if (isModulesSyntaxError(stderr)) {
|
|
107
|
-
return getModuleSyntaxError(stderr)
|
|
108
|
-
}
|
|
109
|
-
if (isModuleNotFoundError(stderr)) {
|
|
110
|
-
return getModuleNotFoundError(stderr)
|
|
111
|
-
}
|
|
112
|
-
const lines = SplitLines.splitLines(stderr)
|
|
113
|
-
const { actualMessage, rest } = getDetails(lines)
|
|
114
|
-
return {
|
|
115
|
-
message: `${actualMessage}`,
|
|
116
|
-
code: '',
|
|
117
|
-
stack: rest,
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ContentType = 'Content-Type'
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
2
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
3
|
-
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
4
|
-
|
|
5
|
-
export class JsonParsingError extends Error {
|
|
6
|
-
constructor(message, codeFrame, stack) {
|
|
7
|
-
super(message)
|
|
8
|
-
this.name = 'JsonParsingError'
|
|
9
|
-
this.code = ErrorCodes.E_JSON_PARSE
|
|
10
|
-
if (codeFrame) {
|
|
11
|
-
this.codeFrame = codeFrame
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (stack) {
|
|
15
|
-
const parentStack = JoinLines.joinLines(SplitLines.splitLines(this.stack).slice(1))
|
|
16
|
-
this.stack = this.name + ': ' + this.message + '\n' + stack + '\n' + parentStack
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as GetNewLineIndex from '../GetNewLineIndex/GetNewLineIndex.js'
|
|
2
|
-
import * as NormalizeErrorLine from '../NormalizeErrorLine/NormalizeErrorLine.js'
|
|
3
|
-
|
|
4
|
-
export const mergeStacks = (parent, child) => {
|
|
5
|
-
if (!child) {
|
|
6
|
-
return parent
|
|
7
|
-
}
|
|
8
|
-
const parentNewLineIndex = GetNewLineIndex.getNewLineIndex(parent)
|
|
9
|
-
const childNewLineIndex = GetNewLineIndex.getNewLineIndex(child)
|
|
10
|
-
if (childNewLineIndex === -1) {
|
|
11
|
-
return parent
|
|
12
|
-
}
|
|
13
|
-
const parentFirstLine = parent.slice(0, parentNewLineIndex)
|
|
14
|
-
const childRest = child.slice(childNewLineIndex)
|
|
15
|
-
const childFirstLine = NormalizeErrorLine.normalizeLine(child.slice(0, childNewLineIndex))
|
|
16
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
17
|
-
return parentFirstLine + childRest
|
|
18
|
-
}
|
|
19
|
-
return child
|
|
20
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import * as GetTerminalProcessPath from '../GetTerminalProcessPath/GetTerminalProcessPath.js'
|
|
3
|
-
import * as IpcParent from '../IpcParent/IpcParent.js'
|
|
4
|
-
import * as IpcParentType from '../IpcParentType/IpcParentType.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export const handlePort = async (browserWindowPort, type, name) => {
|
|
11
|
-
Assert.object(browserWindowPort)
|
|
12
|
-
Assert.string(type)
|
|
13
|
-
Assert.string(name)
|
|
14
|
-
const ptyHostPath = GetTerminalProcessPath.getTerminalProcessPath()
|
|
15
|
-
const ipc = await IpcParent.create({
|
|
16
|
-
method: IpcParentType.ElectronUtilityProcess,
|
|
17
|
-
path: ptyHostPath,
|
|
18
|
-
name,
|
|
19
|
-
})
|
|
20
|
-
// TODO use connectIpc for better error handling
|
|
21
|
-
ipc.sendAndTransfer(
|
|
22
|
-
{
|
|
23
|
-
jsonrpc: '2.0',
|
|
24
|
-
method: 'HandleElectronMessagePort.handleElectronMessagePort',
|
|
25
|
-
params: [],
|
|
26
|
-
},
|
|
27
|
-
[browserWindowPort]
|
|
28
|
-
)
|
|
29
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as PassThroughElectronMessagePort from './PassThroughElectronMessagePort.js'
|
|
2
|
-
|
|
3
|
-
export const name = 'PassThroughElectronMessagePort'
|
|
4
|
-
|
|
5
|
-
export const Commands = {
|
|
6
|
-
passThroughElectronMessagePort: PassThroughElectronMessagePort.passThroughElectronMessagePort,
|
|
7
|
-
}
|