Clean up the Chrome API implementation code
This commit is contained in:
parent
31628abadc
commit
d55b96fdf5
3 changed files with 54 additions and 50 deletions
|
@ -44,6 +44,7 @@ class Port {
|
|||
constructor (webContentsId, portId, extensionId, name) {
|
||||
this.webContentsId = webContentsId
|
||||
this.portId = portId
|
||||
this.disconnected = false
|
||||
|
||||
this.name = name
|
||||
this.onDisconnect = new Event()
|
||||
|
@ -60,6 +61,8 @@ class Port {
|
|||
}
|
||||
|
||||
disconnect () {
|
||||
if (this.disconnected) return
|
||||
|
||||
ipcRenderer.send('CHROME_PORT_DISCONNECT', this.webContentsId, this.portId)
|
||||
this._onDisconnect()
|
||||
}
|
||||
|
@ -69,6 +72,7 @@ class Port {
|
|||
}
|
||||
|
||||
_onDisconnect () {
|
||||
this.disconnected = true
|
||||
ipcRenderer.removeAllListeners(`CHROME_PORT_ONMESSAGE_${this.portId}`)
|
||||
this.onDisconnect.emit()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue