diff --git a/README.md b/README.md index 4f386e1..375e181 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ The following events are available: * `tab.on("flash", (tab) => { ... });` * `tab.on("unflash", (tab) => { ... });` * `tab.on("close", (tab) => { ... });` -* `tab.on("closing", (tab) => { ... });` +* `tab.on("closing", (tab, abort) => { ... });` (Use `abort()` function to cancel closing) ## Drag and drop support diff --git a/index.js b/index.js index 4b3b7b0..261f73b 100644 --- a/index.js +++ b/index.js @@ -342,14 +342,20 @@ class Tab extends EventEmitter { } close (force) { - this.emit("closing", this); - if (this.isClosed || (!this.closable && !force)) return; + const abortController = new AbortController(); + const abort = () => abortController.abort(); + this.emit("closing", this, abort); + + const abortSignal = abortController.signal; + if (this.isClosed || (!this.closable && !force) || abortSignal.aborted) return; + this.isClosed = true; let tabGroup = this.tabGroup; tabGroup.tabContainer.removeChild(this.tab); tabGroup.viewContainer.removeChild(this.webview); let activeTab = this.tabGroup.getActiveTab(); TabGroupPrivate.removeTab.bind(tabGroup)(this, true); + this.emit("close", this); if (activeTab.id === this.id) {