(proxy: T, key: string)
| 2 | import { isPromise } from "./helper"; |
| 3 | |
| 4 | export function startService<T>(proxy: T, key: string) { |
| 5 | ipcMain.on("proxy-service", (event: any, arg: any) => { |
| 6 | if (arg.type === key) { |
| 7 | const res = (proxy as any)[arg.method](...arg.args); |
| 8 | if (isPromise(res)) { |
| 9 | res.then((result: any) => { |
| 10 | event.sender.send(`proxy-service-res-${arg.promiseCounter}`, { |
| 11 | succeed: true, |
| 12 | result, |
| 13 | promiseCounter: arg.promiseCounter, |
| 14 | }); |
| 15 | }); |
| 16 | } else { |
| 17 | event.sender.send(`proxy-service-res-${arg.promiseCounter}`, { |
| 18 | succeed: true, |
| 19 | result: res, |
| 20 | promiseCounter: arg.promiseCounter, |
| 21 | }); |
| 22 | } |
| 23 | } |
| 24 | }); |
| 25 | } |
no test coverage detected