Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call AllowSetForegroundWindow before sending IPC #13255

Merged
merged 2 commits into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**']));

Expand Down
5 changes: 5 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
}
},
"optionalDependencies": {
"windows-foreground-love": "0.1.0",
"windows-mutex": "^0.2.0",
"fsevents": "0.3.8"
}
Expand Down
10 changes: 10 additions & 0 deletions src/typings/windows-foreground-love.d.ts
Original file line number Diff line number Diff line change
@@ -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;

}
20 changes: 17 additions & 3 deletions src/vs/code/electron-main/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

Expand All @@ -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();
}
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
17 changes: 16 additions & 1 deletion src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,22 @@ 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);
try {
const { allowSetForegroundWindow } = <any>require.__$__nodeRequire('windows-foreground-love');
allowSetForegroundWindow(processId);
} catch (e) {
// noop
}
});
}

return promise
.then(() => service.start(environmentService.args, process.env))
.then(() => client.dispose())
.then(() => TPromise.wrapError('Sent env to running instance. Terminating...'));
},
Expand Down