From 2896321076366ecd2071f3715c53b175e007044d Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Tue, 23 Jul 2019 14:40:18 -0700 Subject: [PATCH] Ensure tabs can be closed before executing window closure --- terminus-core/src/components/appRoot.component.ts | 5 ++--- terminus-core/src/components/windowControls.component.ts | 3 +-- terminus-core/src/services/app.service.ts | 8 ++++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/terminus-core/src/components/appRoot.component.ts b/terminus-core/src/components/appRoot.component.ts index 4c25ec7c..3787a7ee 100644 --- a/terminus-core/src/components/appRoot.component.ts +++ b/terminus-core/src/components/appRoot.component.ts @@ -128,9 +128,8 @@ export class AppRootComponent { }) this.hostApp.windowCloseRequest$.subscribe(async () => { - await this.app.closeAllTabs() - this.hostApp.closeWindow() - }) + await this.app.closeAllTabs() && this.hostApp.closeWindow(); + }); if (window['safeModeReason']) { ngbModal.open(SafeModeModalComponent) diff --git a/terminus-core/src/components/windowControls.component.ts b/terminus-core/src/components/windowControls.component.ts index 152382da..e99d58ed 100644 --- a/terminus-core/src/components/windowControls.component.ts +++ b/terminus-core/src/components/windowControls.component.ts @@ -12,7 +12,6 @@ export class WindowControlsComponent { constructor (public hostApp: HostAppService, public app: AppService) { } async closeWindow () { - await this.app.closeAllTabs() - this.hostApp.closeWindow() + await this.app.closeAllTabs() && this.hostApp.closeWindow() } } diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index 69d18325..8c799d89 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -206,15 +206,19 @@ export class AppService { } } - async closeAllTabs () { + /** + * Attempts to close all tabs, returns false if one of the tabs blocked closure + */ + async closeAllTabs () : Promise { for (const tab of this.tabs) { if (!await tab.canClose()) { - return + return false; } } for (const tab of this.tabs) { tab.destroy() } + return true; } /** @hidden */