Skip to content

Commit

Permalink
feature: use new rpc (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
levivilet authored Dec 19, 2024
1 parent eac067f commit 09ad2f7
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 76 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
},
"dependencies": {
"@lvce-editor/assert": "^1.3.0",
"@lvce-editor/ipc": "^12.0.0",
"@lvce-editor/json-rpc": "^5.3.0",
"@lvce-editor/rpc": "^1.13.0",
"@lvce-editor/verror": "^1.6.0"
},
Expand Down
1 change: 0 additions & 1 deletion src/parts/Callback/Callback.ts

This file was deleted.

10 changes: 4 additions & 6 deletions src/parts/HandleElectronMessagePort/HandleElectronMessagePort.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as HandleIpc from '../HandleIpc/HandleIpc.ts'
import * as IpcChild from '../IpcChild/IpcChild.ts'
import * as IpcChildType from '../IpcChildType/IpcChildType.ts'
import { ElectronMessagePortRpcClient } from '@lvce-editor/rpc'
import * as CommandMap from '../CommandMap/CommandMap.ts'

export const handleElectronMessagePort = async (messagePort: any) => {
const ipc = await IpcChild.listen({
method: IpcChildType.ElectronMessagePort,
await ElectronMessagePortRpcClient.create({
messagePort,
commandMap: CommandMap.commandMap,
})
HandleIpc.handleIpc(ipc)
}
5 changes: 0 additions & 5 deletions src/parts/HandleIpc/HandleIpc.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/parts/HandleMessage/HandleMessage.ts

This file was deleted.

21 changes: 4 additions & 17 deletions src/parts/IpcChild/IpcChild.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import * as IpcChildModule from '../IpcChildModule/IpcChildModule.ts'

export const listen = async ({
method,
...params
}: {
method: number
[key: string]: any
}) => {
const module = await IpcChildModule.getModule(method)
export const listen = async ({ method, ...params }: { method: number; [key: string]: any }) => {
const module = IpcChildModule.getModule(method)
// @ts-ignore
const rawIpc = await module.listen(params)
const rpc = await module.create(params)
// @ts-ignore
if (module.signal) {
// @ts-ignore
module.signal(rawIpc)
}

// @ts-ignore
const ipc = module.wrap(rawIpc)
return ipc
return rpc
}
21 changes: 9 additions & 12 deletions src/parts/IpcChildModule/IpcChildModule.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import {
IpcChildWithElectronMessagePort,
IpcChildWithElectronUtilityProcess,
IpcChildWithNodeForkedProcess,
IpcChildWithNodeWorker,
IpcChildWithWebSocket,
} from '@lvce-editor/ipc'
ElectronMessagePortRpcClient,
ElectronUtilityProcessRpcClient,
NodeForkedProcessRpcClient,
NodeWorkerRpcClient,
} from '@lvce-editor/rpc'
import * as IpcChildType from '../IpcChildType/IpcChildType.ts'

export const getModule = (method: number) => {
switch (method) {
case IpcChildType.NodeForkedProcess:
return IpcChildWithNodeForkedProcess
return NodeForkedProcessRpcClient
case IpcChildType.NodeWorker:
return IpcChildWithNodeWorker
return NodeWorkerRpcClient
case IpcChildType.ElectronUtilityProcess:
return IpcChildWithElectronUtilityProcess
return ElectronUtilityProcessRpcClient
case IpcChildType.ElectronMessagePort:
return IpcChildWithElectronMessagePort
case IpcChildType.WebSocket:
return IpcChildWithWebSocket
return ElectronMessagePortRpcClient
default:
throw new Error('unexpected ipc type')
}
Expand Down
1 change: 0 additions & 1 deletion src/parts/JsonRpc/JsonRpc.ts

This file was deleted.

8 changes: 5 additions & 3 deletions src/parts/Listen/Listen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as HandleIpc from '../HandleIpc/HandleIpc.ts'
import * as IpcChild from '../IpcChild/IpcChild.ts'
import * as IpcChildType from '../IpcChildType/IpcChildType.ts'
import * as CommandMap from '../CommandMap/CommandMap.ts'

export const listen = async () => {
const ipc = await IpcChild.listen({ method: IpcChildType.Auto() })
HandleIpc.handleIpc(ipc)
await IpcChild.listen({
method: IpcChildType.Auto(),
commandMap: CommandMap.commandMap,
})
}

0 comments on commit 09ad2f7

Please sign in to comment.