clean up env passing from main to renderers

related to #10194
This commit is contained in:
Sandeep Somavarapu 2016-08-05 17:38:41 +02:00
parent b4e188f97c
commit 35ef7bc18e
4 changed files with 56 additions and 31 deletions

View file

@ -102,11 +102,6 @@ function main(accessor: ServicesAccessor, ipcServer: Server, userEnv: IProcessEn
const askpassChannel = new AskpassChannel(askpassService);
ipcServer.registerChannel('askpass', askpassChannel);
// Used by sub processes to communicate back to the main instance
process.env['VSCODE_PID'] = '' + process.pid;
process.env['VSCODE_IPC_HOOK'] = envService.mainIPCHandle;
process.env['VSCODE_SHARED_IPC_HOOK'] = envService.sharedIPCHandle;
// Spawn shared process
const sharedProcess = spawnSharedProcess({
allowOutput: !envService.isBuilt || envService.cliArgs.verboseLogging,
@ -332,24 +327,54 @@ function getUnixUserEnvironment(): TPromise<IEnv> {
return promise.then(null, () => ({}));
}
/**
* On Unix systems, we might need to get the environment
* from a user's shell. This should only be done when Code
* is not launched from a Terminal.
*/
function getUserShellEnvironment(): TPromise<IEnv> {
if (platform.isWindows) {
return TPromise.as({});
}
if (process.env['VSCODE_CLI'] === '1') {
return TPromise.as({});
}
return getUnixUserEnvironment();
}
/**
* Returns the user environment necessary for all Code processes.
* Such environment needs to be propagated to the renderer/shared
* processes.
*/
function getUserEnvironment(): TPromise<IEnv> {
return platform.isWindows ? TPromise.as({}) : getUnixUserEnvironment();
return getUserShellEnvironment().then(userShellEnv => {
return instantiationService.invokeFunction(a => {
const envService = a.get(IEnvironmentService);
const instanceEnv = {
VSCODE_PID: String(process.pid),
VSCODE_IPC_HOOK: envService.mainIPCHandle,
VSCODE_SHARED_IPC_HOOK: envService.sharedIPCHandle
};
return assign({}, userShellEnv, instanceEnv);
});
});
}
// On some platforms we need to manually read from the global environment variables
// and assign them to the process environment (e.g. when doubleclick app on Mac)
getUserEnvironment()
.then(userEnv => {
if (process.env['VSCODE_CLI'] !== '1') {
assign(process.env, userEnv);
}
getUserEnvironment().then(userEnv => {
assign(process.env, userEnv);
// Make sure the NLS Config travels to the rendered process
// See also https://github.com/Microsoft/vscode/issues/4558
userEnv['VSCODE_NLS_CONFIG'] = process.env['VSCODE_NLS_CONFIG'];
// Make sure the NLS Config travels to the rendered process
// See also https://github.com/Microsoft/vscode/issues/4558
userEnv['VSCODE_NLS_CONFIG'] = process.env['VSCODE_NLS_CONFIG'];
return instantiationService.invokeFunction(a => a.get(IEnvironmentService).createPaths())
.then(() => instantiationService.invokeFunction(setupIPC))
.then(ipcServer => instantiationService.invokeFunction(main, ipcServer, userEnv));
})
.done(null, err => instantiationService.invokeFunction(quit, err));
return instantiationService.invokeFunction(a => a.get(IEnvironmentService).createPaths())
.then(() => instantiationService.invokeFunction(setupIPC))
.then(ipcServer => instantiationService.invokeFunction(main, ipcServer, userEnv));
})
.done(null, err => instantiationService.invokeFunction(quit, err));

View file

@ -11,7 +11,7 @@ import * as platform from 'vs/base/common/platform';
import * as nls from 'vs/nls';
import * as paths from 'vs/base/common/paths';
import * as arrays from 'vs/base/common/arrays';
import * as objects from 'vs/base/common/objects';
import { assign, mixin } from 'vs/base/common/objects';
import pkg from 'vs/platform/package';
import { EventEmitter } from 'events';
import { IStorageService } from 'vs/code/electron-main/storage';
@ -604,7 +604,7 @@ export class WindowsManager implements IWindowsService {
// Otherwise open instance with files
else {
configuration = this.toConfiguration(openConfig.userEnv || this.initialUserEnv, openConfig.cli, null, filesToOpen, filesToCreate, filesToDiff, extensionsToInstall);
configuration = this.toConfiguration(this.getWindowUserEnv(openConfig), openConfig.cli, null, filesToOpen, filesToCreate, filesToDiff, extensionsToInstall);
let browserWindow = this.openInBrowserWindow(configuration, true /* new window */);
usedWindows.push(browserWindow);
@ -650,7 +650,7 @@ export class WindowsManager implements IWindowsService {
return; // ignore folders that are already open
}
configuration = this.toConfiguration(openConfig.userEnv || this.initialUserEnv, openConfig.cli, folderToOpen.workspacePath, filesToOpen, filesToCreate, filesToDiff, extensionsToInstall);
configuration = this.toConfiguration(this.getWindowUserEnv(openConfig), openConfig.cli, folderToOpen.workspacePath, filesToOpen, filesToCreate, filesToDiff, extensionsToInstall);
let browserWindow = this.openInBrowserWindow(configuration, openInNewWindow, openInNewWindow ? void 0 : openConfig.windowToUse);
usedWindows.push(browserWindow);
@ -667,7 +667,7 @@ export class WindowsManager implements IWindowsService {
// Handle empty
if (emptyToOpen.length > 0) {
emptyToOpen.forEach(() => {
let configuration = this.toConfiguration(openConfig.userEnv || this.initialUserEnv, openConfig.cli);
let configuration = this.toConfiguration(this.getWindowUserEnv(openConfig), openConfig.cli);
let browserWindow = this.openInBrowserWindow(configuration, openInNewWindow, openInNewWindow ? void 0 : openConfig.windowToUse);
usedWindows.push(browserWindow);
@ -688,6 +688,10 @@ export class WindowsManager implements IWindowsService {
return arrays.distinct(usedWindows);
}
private getWindowUserEnv(openConfig: IOpenConfiguration): IProcessEnvironment {
return assign({}, this.initialUserEnv, openConfig.userEnv || {});
}
public openPluginDevelopmentHostWindow(openConfig: IOpenConfiguration): void {
// Reload an existing plugin development host window on the same path
@ -722,7 +726,7 @@ export class WindowsManager implements IWindowsService {
}
private toConfiguration(userEnv: IProcessEnvironment, cli: ICommandLineArguments, workspacePath?: string, filesToOpen?: IPath[], filesToCreate?: IPath[], filesToDiff?: IPath[], extensionsToInstall?: string[]): IWindowConfiguration {
let configuration: IWindowConfiguration = objects.mixin({}, cli); // inherit all properties from CLI
let configuration: IWindowConfiguration = mixin({}, cli); // inherit all properties from CLI
configuration.execPath = process.execPath;
configuration.workspacePath = workspacePath;
configuration.filesToOpen = filesToOpen;

View file

@ -111,8 +111,8 @@
var enableDeveloperTools = !configuration.isBuilt || !!configuration.extensionDevelopmentPath;
// Linux is a PAIN https://github.com/electron/electron/issues/3306
process.env['VSCODE_IPC_HOOK'] = configuration.mainIPCHandle;
process.env['VSCODE_SHARED_IPC_HOOK'] = configuration.sharedIPCHandle;
// process.env['VSCODE_IPC_HOOK'] = configuration.mainIPCHandle;
// process.env['VSCODE_SHARED_IPC_HOOK'] = configuration.sharedIPCHandle;
// Get the nls configuration into the process.env as early as possible.
var nlsConfig = { availableLanguages: {} };

View file

@ -56,12 +56,8 @@ export interface IMainEnvironment extends IEnvironment {
}
export function startup(environment: IMainEnvironment, globalSettings: IGlobalSettings): winjs.TPromise<void> {
// Inherit the user environment
// TODO@Joao: this inheritance should **not** happen here!
if (process.env['VSCODE_CLI'] !== '1') {
assign(process.env, environment.userEnv);
}
assign(process.env, environment.userEnv);
// Shell Configuration
let shellConfiguration: IConfiguration = {