mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-25 09:06:21 +01:00
shared process init data
This commit is contained in:
@@ -22,7 +22,7 @@ import { Server, serve, connect } from 'vs/base/parts/ipc/node/ipc.net';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { AskpassChannel } from 'vs/workbench/parts/git/common/gitIpc';
|
||||
import { GitAskpassService } from 'vs/workbench/parts/git/electron-main/askpassService';
|
||||
import { spawnSharedProcess } from 'vs/code/electron-main/sharedProcess';
|
||||
import { spawnSharedProcess } from 'vs/code/node/sharedProcess';
|
||||
import { Mutex } from 'windows-mutex';
|
||||
import { LaunchService, ILaunchChannel, LaunchChannel, LaunchChannelClient } from './launch';
|
||||
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -66,6 +66,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const logService = accessor.get(ILogService);
|
||||
const envService = accessor.get(IEnvService);
|
||||
const environmentService = accessor.get(IEnvironmentService);
|
||||
const windowsService = accessor.get(IWindowsService);
|
||||
const lifecycleService = accessor.get(ILifecycleService);
|
||||
const updateService = accessor.get(IUpdateService);
|
||||
@@ -121,10 +122,13 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
|
||||
electronIpcServer.registerChannel('url', urlChannel);
|
||||
|
||||
// Spawn shared process
|
||||
const sharedProcess = spawnSharedProcess({
|
||||
const initData = { args: environmentService.args };
|
||||
const options = {
|
||||
allowOutput: !envService.isBuilt || envService.cliArgs.verbose,
|
||||
debugPort: envService.isBuilt ? null : 5871
|
||||
});
|
||||
};
|
||||
|
||||
const sharedProcess = spawnSharedProcess(initData, options);
|
||||
|
||||
// Make sure we associate the program with the app user model id
|
||||
// This will help Windows to associate the running program with
|
||||
|
||||
@@ -7,6 +7,11 @@ import * as cp from 'child_process';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { ParsedArgs } from 'vs/platform/environment/node/argv';
|
||||
|
||||
export interface ISharedProcessInitData {
|
||||
args: ParsedArgs;
|
||||
}
|
||||
|
||||
export interface ISharedProcessOptions {
|
||||
allowOutput?: boolean;
|
||||
@@ -15,7 +20,7 @@ export interface ISharedProcessOptions {
|
||||
|
||||
const boostrapPath = URI.parse(require.toUrl('bootstrap')).fsPath;
|
||||
|
||||
function _spawnSharedProcess(options: ISharedProcessOptions): cp.ChildProcess {
|
||||
function _spawnSharedProcess(initData: ISharedProcessInitData, options: ISharedProcessOptions): cp.ChildProcess {
|
||||
const execArgv = [];
|
||||
const env = assign({}, process.env, {
|
||||
AMD_ENTRYPOINT: 'vs/code/node/sharedProcessMain'
|
||||
@@ -32,12 +37,12 @@ function _spawnSharedProcess(options: ISharedProcessOptions): cp.ChildProcess {
|
||||
const result = cp.fork(boostrapPath, ['--type=SharedProcess'], { env, execArgv });
|
||||
|
||||
// handshake
|
||||
result.once('message', () => result.send('hey'));
|
||||
result.once('message', () => result.send(initData));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function spawnSharedProcess(options: ISharedProcessOptions = {}): IDisposable {
|
||||
export function spawnSharedProcess(initData: ISharedProcessInitData, options: ISharedProcessOptions = {}): IDisposable {
|
||||
let spawnCount = 0;
|
||||
let child: cp.ChildProcess;
|
||||
|
||||
@@ -46,7 +51,7 @@ export function spawnSharedProcess(options: ISharedProcessOptions = {}): IDispos
|
||||
return;
|
||||
}
|
||||
|
||||
child = _spawnSharedProcess(options);
|
||||
child = _spawnSharedProcess(initData, options);
|
||||
child.on('exit', spawn);
|
||||
};
|
||||
|
||||
@@ -14,7 +14,6 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { parseArgs } from 'vs/platform/environment/node/argv';
|
||||
import { IEventService } from 'vs/platform/event/common/event';
|
||||
import { EventService } from 'vs/platform/event/common/eventService';
|
||||
import { ExtensionManagementChannel } from 'vs/platform/extensionManagement/common/extensionManagementIpc';
|
||||
@@ -30,6 +29,7 @@ import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProper
|
||||
import { TelemetryAppenderChannel } from 'vs/platform/telemetry/common/telemetryIpc';
|
||||
import { TelemetryService, ITelemetryServiceConfig } from 'vs/platform/telemetry/common/telemetryService';
|
||||
import { AppInsightsAppender } from 'vs/platform/telemetry/node/appInsightsAppender';
|
||||
import { ISharedProcessInitData } from './sharedProcess';
|
||||
|
||||
function quit(err?: Error) {
|
||||
if (err) {
|
||||
@@ -54,11 +54,11 @@ function setupPlanB(parentPid: number): void {
|
||||
|
||||
const eventPrefix = 'monacoworkbench';
|
||||
|
||||
function main(server: Server): void {
|
||||
function main(server: Server, initData: ISharedProcessInitData): void {
|
||||
const services = new ServiceCollection();
|
||||
|
||||
services.set(IEventService, new SyncDescriptor(EventService));
|
||||
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv), process.execPath));
|
||||
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, initData.args, process.execPath));
|
||||
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService));
|
||||
services.set(IRequestService, new SyncDescriptor(RequestService));
|
||||
|
||||
@@ -147,8 +147,8 @@ function setupIPC(hook: string): TPromise<Server> {
|
||||
return setup(true);
|
||||
}
|
||||
|
||||
function handshake(): TPromise<void> {
|
||||
return new TPromise<void>((c, e) => {
|
||||
function handshake(): TPromise<ISharedProcessInitData> {
|
||||
return new TPromise<ISharedProcessInitData>((c, e) => {
|
||||
process.once('message', c);
|
||||
process.once('error', e);
|
||||
process.send('hello');
|
||||
@@ -156,6 +156,6 @@ function handshake(): TPromise<void> {
|
||||
}
|
||||
|
||||
TPromise.join<any>([setupIPC(process.env['VSCODE_SHARED_IPC_HOOK']), handshake()])
|
||||
.then(r => main(r[0]))
|
||||
.then(r => main(r[0], r[1]))
|
||||
.then(() => setupPlanB(process.env['VSCODE_PID']))
|
||||
.done(null, quit);
|
||||
Reference in New Issue
Block a user