| 56 | }) |
| 57 | |
| 58 | const createHandleURLServer = (getWindow) => net |
| 59 | .createServer((socket) => { |
| 60 | socket.setEncoding('utf-8') |
| 61 | socket.on('data', async (data) => { |
| 62 | try { |
| 63 | const obj = JSON.parse(data) |
| 64 | if (typeof obj.path === 'string') { |
| 65 | await handleURL(getWindow, obj.path) |
| 66 | } |
| 67 | socket.write('success') |
| 68 | } catch (e) { |
| 69 | socket.write('fail') |
| 70 | } finally { |
| 71 | socket.end() |
| 72 | } |
| 73 | }) |
| 74 | }) |
| 75 | .listen(0, '127.0.0.1') |
| 76 | .on('listening', function server() { |
| 77 | const { port } = this.address() |
| 78 | portfile.write(port) |
| 79 | portfile.watchExists(port) |
| 80 | process.on('exit', () => portfile.unlink()) |
| 81 | |
| 82 | console.log(`Starting listen set-debugger-loc request on port ${port}`) |
| 83 | console.log('Will save port to `$HOME/.rndebugger_port` file') |
| 84 | }) |
| 85 | |
| 86 | export default (getWindow) => { |
| 87 | // Handle set-debugger-loc for macOS |