| 7 | win: BrowserWindow; |
| 8 | id!: string; |
| 9 | constructor(win: BrowserWindow) { |
| 10 | super(); |
| 11 | this.win = win; |
| 12 | this.ipcListener = this.ipcListener.bind(this); |
| 13 | |
| 14 | if (this.destroyed) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | const uid = uuidv4(); |
| 19 | this.id = uid; |
| 20 | |
| 21 | // eslint-disable-next-line @typescript-eslint/unbound-method |
| 22 | ipcMain.on(uid, this.ipcListener); |
| 23 | |
| 24 | // we intentionally subscribe to `on` instead of `once` |
| 25 | // to support reloading the window and re-initializing |
| 26 | // the channel |
| 27 | this.wc.on('did-finish-load', () => { |
| 28 | this.wc.send('init', uid); |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | get wc() { |
| 33 | return this.win.webContents; |