Skip to content

Commit 3a931d9

Browse files
authored
Don't show dialog if closing tab after Continue On (microsoft#187324)
* Don't show dialog if closing tab after Continue On
1 parent c7195ce commit 3a931d9

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

src/vs/workbench/browser/window.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/envir
2626
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
2727
import { BrowserLifecycleService } from 'vs/workbench/services/lifecycle/browser/lifecycleService';
2828
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
29+
import { IHostService } from 'vs/workbench/services/host/browser/host';
2930

3031
export class BrowserWindow extends Disposable {
3132

@@ -37,7 +38,8 @@ export class BrowserWindow extends Disposable {
3738
@IProductService private readonly productService: IProductService,
3839
@IBrowserWorkbenchEnvironmentService private readonly environmentService: IBrowserWorkbenchEnvironmentService,
3940
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
40-
@IInstantiationService private readonly instantiationService: IInstantiationService
41+
@IInstantiationService private readonly instantiationService: IInstantiationService,
42+
@IHostService private readonly hostService: IHostService
4143
) {
4244
super();
4345

@@ -231,13 +233,15 @@ export class BrowserWindow extends Disposable {
231233
);
232234
}
233235

234-
await this.dialogService.prompt({
236+
// While this dialog shows, closing the tab will not display a confirmation dialog
237+
// to avoid showing the user two dialogs at once
238+
await this.hostService.withExpectedShutdown(() => this.dialogService.prompt({
235239
type: Severity.Info,
236240
message: localize('openExternalDialogTitle', "All done. You can close this tab now."),
237241
detail,
238242
buttons,
239243
cancelButton: true
240-
});
244+
}));
241245
};
242246

243247
// We cannot know whether the protocol handler succeeded.

src/vs/workbench/services/host/browser/browserHostService.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,16 @@ export class BrowserHostService extends Disposable implements IHostService {
521521
window.close();
522522
}
523523

524+
async withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T> {
525+
const previousShutdownReason = this.shutdownReason;
526+
try {
527+
this.shutdownReason = HostShutdownReason.Api;
528+
return await expectedShutdownTask();
529+
} finally {
530+
this.shutdownReason = previousShutdownReason;
531+
}
532+
}
533+
524534
private async handleExpectedShutdown(reason: ShutdownReason): Promise<void> {
525535

526536
// Update shutdown reason in a way that we do

src/vs/workbench/services/host/browser/host.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,11 @@ export interface IHostService {
8888
*/
8989
close(): Promise<void>;
9090

91+
/**
92+
* Execute an asynchronous `expectedShutdownTask`. While this task is
93+
* in progress, attempts to quit the application will not be vetoed with a dialog.
94+
*/
95+
withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T>;
96+
9197
//#endregion
9298
}

src/vs/workbench/services/host/electron-sandbox/nativeHostService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class WorkbenchHostService extends Disposable implements IHostService {
135135
return this.nativeHostService.closeWindow();
136136
}
137137

138+
async withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T> {
139+
return await expectedShutdownTask();
140+
}
141+
138142
//#endregion
139143
}
140144

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,9 @@ export class TestHostService implements IHostService {
14351435
async restart(): Promise<void> { }
14361436
async reload(): Promise<void> { }
14371437
async close(): Promise<void> { }
1438+
async withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T> {
1439+
return await expectedShutdownTask();
1440+
}
14381441

14391442
async focus(options?: { force: boolean }): Promise<void> { }
14401443

0 commit comments

Comments
 (0)