Last active window is not always restored when reopening (fixes #20770)

This commit is contained in:
Benjamin Pasero
2017-02-27 14:38:39 +01:00
parent 7f12fccc9c
commit 1f5fae9c5e
3 changed files with 94 additions and 51 deletions

View File

@@ -7,7 +7,7 @@
import { ipcMain as ipc, app } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ReadyState, IVSCodeWindow } from 'vs/code/electron-main/window';
import { ReadyState, VSCodeWindow } from 'vs/code/electron-main/window';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/code/electron-main/log';
import { IStorageService } from 'vs/code/electron-main/storage';
@@ -38,9 +38,16 @@ export interface ILifecycleService {
*/
onBeforeQuit: Event<void>;
/**
* We provide our own event when we close a window because the general window.on('close')
* is called even when the window prevents the closing. We want an event that truly fires
* before the window gets closed for real.
*/
onBeforeWindowClose: Event<VSCodeWindow>;
ready(): void;
registerWindow(vscodeWindow: IVSCodeWindow): void;
unload(vscodeWindow: IVSCodeWindow, reason: UnloadReason): TPromise<boolean /* veto */>;
registerWindow(vscodeWindow: VSCodeWindow): void;
unload(vscodeWindow: VSCodeWindow, reason: UnloadReason): TPromise<boolean /* veto */>;
quit(fromUpdate?: boolean): TPromise<boolean /* veto */>;
isQuitRequested(): boolean;
}
@@ -61,6 +68,9 @@ export class LifecycleService implements ILifecycleService {
private _onBeforeQuit = new Emitter<void>();
onBeforeQuit: Event<void> = this._onBeforeQuit.event;
private _onBeforeWindowClose = new Emitter<VSCodeWindow>();
onBeforeWindowClose: Event<VSCodeWindow> = this._onBeforeWindowClose.event;
constructor(
@IEnvironmentService private environmentService: IEnvironmentService,
@ILogService private logService: ILogService,
@@ -116,7 +126,7 @@ export class LifecycleService implements ILifecycleService {
});
}
public registerWindow(vscodeWindow: IVSCodeWindow): void {
public registerWindow(vscodeWindow: VSCodeWindow): void {
// Window Before Closing: Main -> Renderer
vscodeWindow.win.on('close', (e) => {
@@ -137,6 +147,7 @@ export class LifecycleService implements ILifecycleService {
this.unload(vscodeWindow, UnloadReason.CLOSE).done(veto => {
if (!veto) {
this.windowToCloseRequest[windowId] = true;
this._onBeforeWindowClose.fire(vscodeWindow);
vscodeWindow.win.close();
} else {
this.quitRequested = false;
@@ -146,7 +157,7 @@ export class LifecycleService implements ILifecycleService {
});
}
public unload(vscodeWindow: IVSCodeWindow, reason: UnloadReason): TPromise<boolean /* veto */> {
public unload(vscodeWindow: VSCodeWindow, reason: UnloadReason): TPromise<boolean /* veto */> {
// Always allow to unload a window that is not yet ready
if (vscodeWindow.readyState !== ReadyState.READY) {