提交 c56f0686 编写于 作者: B Benjamin Pasero

`-w` doesn't work when there are no windows open (fixes #4150)

上级 373426f1
......@@ -12,6 +12,7 @@ import {assign} from 'vs/base/common/objects';
import platform = require('vs/base/common/platform');
import env = require('vs/workbench/electron-main/env');
import windows = require('vs/workbench/electron-main/windows');
import window = require('vs/workbench/electron-main/window');
import lifecycle = require('vs/workbench/electron-main/lifecycle');
import menu = require('vs/workbench/electron-main/menus');
import settings = require('vs/workbench/electron-main/settings');
......@@ -28,30 +29,31 @@ export class LaunchService {
env.log('Received data from other instance', args);
let killOtherInstance = args.waitForWindowClose;
let usedWindows: window.VSCodeWindow[];
// Otherwise handle in windows manager
if (!!args.extensionDevelopmentPath) {
windows.manager.openPluginDevelopmentHostWindow({ cli: args, userEnv: userEnv });
} else if (args.pathArguments.length === 0 && args.openNewWindow) {
windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: true, forceEmpty: true });
usedWindows = windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: true, forceEmpty: true });
} else if (args.pathArguments.length === 0) {
windows.manager.focusLastActive(args);
usedWindows = [windows.manager.focusLastActive(args)];
} else {
let usedWindows = windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: args.waitForWindowClose || args.openNewWindow, preferNewWindow: !args.openInSameWindow });
// If the other instance is waiting to be killed, we hook up a window listener if one window
// is being used and kill the other instance when that window is being closed
if (args.waitForWindowClose && usedWindows && usedWindows.length === 1) {
let windowToObserve = usedWindows[0];
killOtherInstance = false; // only scenario where the "-w" switch is supported and makes sense
let unbind = windows.onClose(id => {
if (id === windowToObserve.id) {
unbind();
process.kill(otherInstancePid);
}
});
}
usedWindows = windows.manager.open({ cli: args, userEnv: userEnv, forceNewWindow: args.waitForWindowClose || args.openNewWindow, preferNewWindow: !args.openInSameWindow });
}
// If the other instance is waiting to be killed, we hook up a window listener if one window
// is being used and kill the other instance when that window is being closed
if (args.waitForWindowClose && usedWindows && usedWindows.length === 1 && usedWindows[0]) {
let windowToObserve = usedWindows[0];
killOtherInstance = false; // only scenario where the "-w" switch is supported and makes sense
let unbind = windows.onClose(id => {
if (id === windowToObserve.id) {
unbind();
process.kill(otherInstancePid);
}
});
}
if (killOtherInstance) {
......
......@@ -964,17 +964,19 @@ export class WindowsManager {
});
}
public focusLastActive(cli: env.ICommandLineArguments): void {
public focusLastActive(cli: env.ICommandLineArguments): window.VSCodeWindow {
let lastActive = this.getLastActiveWindow();
if (lastActive) {
lastActive.focus();
return lastActive;
}
// No window - open new one
else {
this.windowsState.openedFolders = []; // make sure we do not open too much
this.open({ cli: cli });
}
this.windowsState.openedFolders = []; // make sure we do not open too much
const res = this.open({ cli: cli });
return res && res[0];
}
public getLastActiveWindow(): window.VSCodeWindow {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册