(cmd: string, args: unknown[])
| 117 | } |
| 118 | |
| 119 | private sendRequest(cmd: string, args: unknown[]): Promise<unknown> { |
| 120 | const ps = this.ps |
| 121 | if (!ps?.connected) return Promise.reject(new Error('Electron IPC is not connected')) |
| 122 | const invocationId = this.invocationId++ |
| 123 | return new Promise((resolve, reject) => { |
| 124 | const fail = (error: Error): void => { |
| 125 | const pending = this.rpcMap.get(invocationId) |
| 126 | if (!pending) return |
| 127 | clearTimeout(pending.timer) |
| 128 | this.rpcMap.delete(invocationId) |
| 129 | reject(this.withStderr(error)) |
| 130 | } |
| 131 | const timer = setTimeout(() => fail(new Error('Electron RPC timed out: ' + cmd)), RPC_TIMEOUT) |
| 132 | this.rpcMap.set(invocationId, { resolve, reject, timer }) |
| 133 | try { |
| 134 | ps.send({ type: 'request', invocationId, cmd, args }, error => { |
| 135 | if (error) fail(error) |
| 136 | }) |
| 137 | } catch (error) { |
| 138 | fail(error instanceof Error ? error : new Error(String(error))) |
| 139 | } |
| 140 | }) |
| 141 | } |
| 142 | |
| 143 | private rejectPending(error: Error): void { |
| 144 | this.ready = false |
no test coverage detected