mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Call AllowSetForegroundWindow before sending IPC to the running instance on Windows (Fixes #929)
This commit is contained in:
@@ -268,6 +268,7 @@ function packageTask(platform, arch, opts) {
|
||||
.pipe(util.cleanNodeModule('oniguruma', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node']))
|
||||
.pipe(util.cleanNodeModule('windows-mutex', ['binding.gyp', 'build/**', 'src/**'], ['**/*.node']))
|
||||
.pipe(util.cleanNodeModule('native-keymap', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node']))
|
||||
.pipe(util.cleanNodeModule('windows-foreground-love', ['binding.gyp', 'build/**', 'src/**'], ['**/*.node']))
|
||||
.pipe(util.cleanNodeModule('gc-signals', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node', 'src/index.js']))
|
||||
.pipe(util.cleanNodeModule('pty.js', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['build/Release/**']));
|
||||
|
||||
|
||||
Generated
+5
@@ -414,6 +414,11 @@
|
||||
"from": "vscode-textmate@2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-2.2.0.tgz"
|
||||
},
|
||||
"windows-foreground-love": {
|
||||
"version": "0.1.0",
|
||||
"from": "windows-foreground-love@0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/windows-foreground-love/-/windows-foreground-love-0.1.0.tgz"
|
||||
},
|
||||
"windows-mutex": {
|
||||
"version": "0.2.0",
|
||||
"from": "windows-mutex@>=0.2.0 <0.3.0",
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
}
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"windows-foreground-love": "0.1.0",
|
||||
"windows-mutex": "^0.2.0",
|
||||
"fsevents": "0.3.8"
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'windows-foreground-love' {
|
||||
|
||||
export function allowSetForegroundWindow(pid?: number): boolean;
|
||||
|
||||
}
|
||||
@@ -21,10 +21,12 @@ export interface IStartArguments {
|
||||
|
||||
export interface ILaunchService {
|
||||
start(args: ParsedArgs, userEnv: IProcessEnvironment): TPromise<void>;
|
||||
getMainProcessId(): TPromise<number>;
|
||||
}
|
||||
|
||||
export interface ILaunchChannel extends IChannel {
|
||||
call(command: 'start', arg: IStartArguments): TPromise<void>;
|
||||
call(command: 'get-main-process-id', arg: null): TPromise<any>;
|
||||
call(command: string, arg: any): TPromise<any>;
|
||||
}
|
||||
|
||||
@@ -33,10 +35,13 @@ export class LaunchChannel implements ILaunchChannel {
|
||||
constructor(private service: ILaunchService) { }
|
||||
|
||||
call(command: string, arg: any): TPromise<any> {
|
||||
const { args, userEnv } = arg as IStartArguments;
|
||||
|
||||
switch (command) {
|
||||
case 'start': return this.service.start(args, userEnv);
|
||||
case 'start':
|
||||
const { args, userEnv } = arg as IStartArguments;
|
||||
return this.service.start(args, userEnv);
|
||||
|
||||
case 'get-main-process-id':
|
||||
return this.service.getMainProcessId();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +53,10 @@ export class LaunchChannelClient implements ILaunchService {
|
||||
start(args: ParsedArgs, userEnv: IProcessEnvironment): TPromise<void> {
|
||||
return this.channel.call('start', { args, userEnv });
|
||||
}
|
||||
|
||||
getMainProcessId(): TPromise<number> {
|
||||
return this.channel.call('get-main-process-id', null);
|
||||
}
|
||||
}
|
||||
|
||||
export class LaunchService implements ILaunchService {
|
||||
@@ -105,4 +114,9 @@ export class LaunchService implements ILaunchService {
|
||||
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
getMainProcessId(): TPromise<number> {
|
||||
this.logService.log('Received request for process ID from other instance.');
|
||||
return TPromise.as(process.pid);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import { AskpassChannel } from 'vs/workbench/parts/git/common/gitIpc';
|
||||
import { GitAskpassService } from 'vs/workbench/parts/git/electron-main/askpassService';
|
||||
import { spawnSharedProcess } from 'vs/code/node/sharedProcess';
|
||||
import { Mutex } from 'windows-mutex';
|
||||
import { allowSetForegroundWindow } from 'windows-foreground-love';
|
||||
import { LaunchService, ILaunchChannel, LaunchChannel, LaunchChannelClient } from './launch';
|
||||
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
@@ -299,7 +300,17 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
|
||||
const channel = client.getChannel<ILaunchChannel>('launch');
|
||||
const service = new LaunchChannelClient(channel);
|
||||
|
||||
return service.start(environmentService.args, process.env)
|
||||
let promise = TPromise.as(null);
|
||||
if (platform.isWindows) {
|
||||
promise = service.getMainProcessId()
|
||||
.then(processId => {
|
||||
logService.log('Sending some foreground love to the running instance:', processId);
|
||||
allowSetForegroundWindow(processId);
|
||||
});
|
||||
}
|
||||
|
||||
return promise
|
||||
.then(() => service.start(environmentService.args, process.env))
|
||||
.then(() => client.dispose())
|
||||
.then(() => TPromise.wrapError('Sent env to running instance. Terminating...'));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user