Add a way to abort closing (#53)
This commit is contained in:
parent
601c7fc24c
commit
a34fc68469
2 changed files with 9 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
10
index.js
10
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) {
|
||||
|
|
Loading…
Reference in a new issue