Skip to content

Commit 06d64bd

Browse files
committed
fix: pressing button twice closes internal port but Websocket remains connected
Port.onDisconnect event only fires when the port is closed from the other end, and not the port is closed by this side (in this case background.js) https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/Port#ondisconnect #2
1 parent d6c2c27 commit 06d64bd

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎src/ghosttext-adaptor/api.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ export type ComposeDetails = {
2929
}
3030

3131
/** Updatable fields of a compose window */
32-
export type SettableComposeDetails =
33-
| { subject: string; body?: string | undefined }
34-
| { subject?: string | undefined; body: string }
32+
export type SettableComposeDetails = { subject: string }
3533

3634
/** an utility to interact with a mail compose window */
3735
export interface IComposeWindow {

‎src/thunderbird/background_util/compose_tab.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export class ComposeTab implements IComposeWindow {
4242
return { isPlainText, subject, body } as ComposeDetails
4343
}
4444

45-
setDetails({ subject, body }: SettableComposeDetails): Promise<void> {
45+
setDetails({ subject }: SettableComposeDetails): Promise<void> {
4646
// TODO edit subject
4747
// TODO edit address lines
48-
let details: messenger.compose.ComposeDetails = { subject, body, plainTextBody: body }
48+
let details: messenger.compose.ComposeDetails = { subject }
4949

5050
return this.compose.setComposeDetails(this.tabId, details)
5151
}

‎src/thunderbird/util/promisified_port.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export class PromisifiedPort<TRequest extends object, TResponse extends object |
3333
})
3434

3535
this.port.onDisconnect.addListener(() => {
36-
this.q.notifyClosed(this.port.error ?? Error("Port disconnected"))
36+
console.info("port closed from the other side")
37+
this.handleClose()
3738
})
3839
}
3940

@@ -54,6 +55,13 @@ export class PromisifiedPort<TRequest extends object, TResponse extends object |
5455
}
5556

5657
close(): void {
58+
console.info("closing port", this.port)
5759
this.port.disconnect()
60+
// we have to call this ourself
61+
this.handleClose()
62+
}
63+
64+
private handleClose() {
65+
this.q.notifyClosed(this.port.error ?? Error("Port disconnected"))
5866
}
5967
}

‎src/thunderbird/util/promisified_web_socket.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export class PromisifiedWebSocket implements IMessagePort<string, string> {
3939
)
4040
this.socket.addEventListener(
4141
"close",
42-
(e) => {
43-
let { code, reason, wasClean } = e
42+
({ code, reason, wasClean }) => {
4443
let info = { code, reason, wasClean }
4544
let err = Error(JSON.stringify(info))
4645

0 commit comments

Comments
 (0)