diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 9746ba60a43..b3c2af9cc48 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -70,6 +70,9 @@ export class CodeWindow extends Disposable implements ICodeWindow { private readonly _onDestroy = this._register(new Emitter()); readonly onDestroy: CommonEvent = this._onDestroy.event; + private readonly _onLoad = this._register(new Emitter()); + readonly onLoad: CommonEvent = this._onLoad.event; + private hiddenTitleBarStyle: boolean; private showTimeoutHandle: NodeJS.Timeout; private _id: number; @@ -324,6 +327,21 @@ export class CodeWindow extends Disposable implements ICodeWindow { return this._readyState === ReadyState.READY; } + get whenClosedOrLoaded(): Promise { + return new Promise(resolve => { + + function handle() { + closeListener.dispose(); + loadListener.dispose(); + + resolve(); + } + + const closeListener = this.onClose(() => handle()); + const loadListener = this.onLoad(() => handle()); + }); + } + private handleMarketplaceRequests(): void { // Resolve marketplace headers @@ -349,7 +367,11 @@ export class CodeWindow extends Disposable implements ICodeWindow { this._win.on('unresponsive', () => this.onWindowError(WindowError.UNRESPONSIVE)); // Window close - this._win.on('closed', () => this._onClose.fire()); + this._win.on('closed', () => { + this._onClose.fire(); + + this.dispose(); + }); // Prevent loading of svgs this._win.webContents.session.webRequest.onBeforeRequest(null!, (details, callback) => { @@ -606,6 +628,9 @@ export class CodeWindow extends Disposable implements ICodeWindow { } }, 10000); } + + // Event + this._onLoad.fire(); } reload(configurationIn?: IWindowConfiguration, cli?: ParsedArgs): void { diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 4b2a3ccf233..eda372de529 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -166,9 +166,6 @@ export class WindowsManager extends Disposable implements IWindowsMainService { private readonly _onWindowClose = this._register(new Emitter()); readonly onWindowClose: CommonEvent = this._onWindowClose.event; - private readonly _onWindowLoad = this._register(new Emitter()); - readonly onWindowLoad: CommonEvent = this._onWindowLoad.event; - private readonly _onWindowsCountChanged = this._register(new Emitter()); readonly onWindowsCountChanged: CommonEvent = this._onWindowsCountChanged.event; @@ -502,7 +499,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService { // process can continue. We do this by deleting the waitMarkerFilePath. const waitMarkerFileURI = openConfig.waitMarkerFileURI; if (openConfig.context === OpenContext.CLI && waitMarkerFileURI && usedWindows.length === 1 && usedWindows[0]) { - this.waitForWindowCloseOrLoad(usedWindows[0].id).then(() => fs.unlink(waitMarkerFileURI.fsPath, _error => undefined)); + usedWindows[0].whenClosedOrLoaded.then(() => fs.unlink(waitMarkerFileURI.fsPath, _error => undefined)); } return usedWindows; @@ -1456,9 +1453,6 @@ export class WindowsManager extends Disposable implements IWindowsMainService { // Load it window.load(configuration); - - // Signal event - this._onWindowLoad.fire(window.id); } private getNewWindowState(configuration: IWindowConfiguration): INewWindowState { @@ -1642,22 +1636,6 @@ export class WindowsManager extends Disposable implements IWindowsMainService { return this.open({ context, cli, forceEmpty: true, forceNewWindow, forceReuseWindow }); } - waitForWindowCloseOrLoad(windowId: number): Promise { - return new Promise(resolve => { - function handler(id: number) { - if (id === windowId) { - closeListener.dispose(); - loadListener.dispose(); - - resolve(); - } - } - - const closeListener = this.onWindowClose(id => handler(id)); - const loadListener = this.onWindowLoad(id => handler(id)); - }); - } - sendToFocused(channel: string, ...args: any[]): void { const focusedWindow = this.getFocusedWindow() || this.getLastActiveWindow(); @@ -1700,9 +1678,6 @@ export class WindowsManager extends Disposable implements IWindowsMainService { private onWindowClosed(win: ICodeWindow): void { - // Tell window - win.dispose(); - // Remove from our list so that Electron can clean it up const index = WindowsManager.WINDOWS.indexOf(win); WindowsManager.WINDOWS.splice(index, 1); diff --git a/src/vs/platform/launch/electron-main/launchMainService.ts b/src/vs/platform/launch/electron-main/launchMainService.ts index 9c94d83e152..026ed424e78 100644 --- a/src/vs/platform/launch/electron-main/launchMainService.ts +++ b/src/vs/platform/launch/electron-main/launchMainService.ts @@ -188,7 +188,7 @@ export class LaunchMainService implements ILaunchMainService { // In addition, we poll for the wait marker file to be deleted to return. if (waitMarkerFileURI && usedWindows.length === 1 && usedWindows[0]) { return Promise.race([ - this.windowsMainService.waitForWindowCloseOrLoad(usedWindows[0].id), + usedWindows[0].whenClosedOrLoaded, whenDeleted(waitMarkerFileURI.fsPath) ]).then(() => undefined, () => undefined); } diff --git a/src/vs/platform/windows/electron-main/windows.ts b/src/vs/platform/windows/electron-main/windows.ts index 7058b846784..8b5280ae719 100644 --- a/src/vs/platform/windows/electron-main/windows.ts +++ b/src/vs/platform/windows/electron-main/windows.ts @@ -35,6 +35,8 @@ export interface ICodeWindow extends IDisposable { readonly onClose: Event; readonly onDestroy: Event; + readonly whenClosedOrLoaded: Promise; + readonly id: number; readonly win: BrowserWindow; readonly config: IWindowConfiguration; @@ -96,12 +98,15 @@ export interface IWindowsMainService { readonly onWindowReady: Event; readonly onWindowsCountChanged: Event; - readonly onWindowClose: Event; open(openConfig: IOpenConfiguration): ICodeWindow[]; openEmptyWindow(context: OpenContext, options?: IOpenEmptyWindowOptions): ICodeWindow[]; openExtensionDevelopmentHostWindow(extensionDevelopmentPath: string[], openConfig: IOpenConfiguration): ICodeWindow[]; + closeWorkspace(win: ICodeWindow): void; + + reload(win: ICodeWindow, cli?: ParsedArgs): void; + sendToFocused(channel: string, ...args: any[]): void; sendToAll(channel: string, payload: any, windowIdsToIgnore?: number[]): void; @@ -111,9 +116,6 @@ export interface IWindowsMainService { getWindows(): ICodeWindow[]; getWindowCount(): number; - waitForWindowCloseOrLoad(windowId: number): Promise; - reload(win: ICodeWindow, cli?: ParsedArgs): void; - closeWorkspace(win: ICodeWindow): void; quit(): void; }