Skip to content

Commit 18beedd

Browse files
committed
improve consistency in env sent to renderer procs
fixes microsoft#10194
1 parent ff06190 commit 18beedd

6 files changed

Lines changed: 194 additions & 195 deletions

File tree

scripts/code.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if not exist out node .\node_modules\gulp\bin\gulp.js compile
1717
:: Configuration
1818
set NODE_ENV=development
1919
set VSCODE_DEV=1
20+
set VSCODE_CLI=1
2021
set ELECTRON_DEFAULT_ERROR_MODE=1
2122
set ELECTRON_ENABLE_LOGGING=1
2223
set ELECTRON_ENABLE_STACK_DUMPING=1

scripts/code.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function code() {
2222
# Configuration
2323
export NODE_ENV=development
2424
export VSCODE_DEV=1
25+
export VSCODE_CLI=1
2526
export ELECTRON_ENABLE_LOGGING=1
2627
export ELECTRON_ENABLE_STACK_DUMPING=1
2728

src/vs/base/common/platform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ if (typeof process === 'object') {
4444
_isMacintosh = (process.platform === 'darwin');
4545
_isLinux = (process.platform === 'linux');
4646
_isRootUser = !_isWindows && (process.getuid() === 0);
47-
let vscode_nls_config = process.env['VSCODE_NLS_CONFIG'];
48-
if (vscode_nls_config) {
47+
let rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
48+
if (rawNlsConfig) {
4949
try {
50-
let nlsConfig:NLSConfig = JSON.parse(vscode_nls_config);
50+
let nlsConfig:NLSConfig = JSON.parse(rawNlsConfig);
5151
let resolved = nlsConfig.availableLanguages['*'];
5252
_locale = nlsConfig.locale;
5353
// VSCode's default language is 'en'

src/vs/code/electron-main/main.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ interface IEnv {
269269
[key: string]: string;
270270
}
271271

272-
function getUnixUserEnvironment(): TPromise<IEnv> {
272+
function getUnixShellEnvironment(): TPromise<IEnv> {
273273
const promise = new TPromise((c, e) => {
274274
const runAsNode = process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
275275
const noAttach = process.env['ELECTRON_NO_ATTACH_CONSOLE'];
@@ -328,53 +328,50 @@ function getUnixUserEnvironment(): TPromise<IEnv> {
328328
}
329329

330330
/**
331-
* On Unix systems, we might need to get the environment
332-
* from a user's shell. This should only be done when Code
333-
* is not launched from a Terminal.
331+
* We eed to get the environment from a user's shell.
332+
* This should only be done when Code itself is not launched
333+
* from within a shell.
334334
*/
335-
function getUserShellEnvironment(): TPromise<IEnv> {
336-
if (platform.isWindows) {
335+
function getShellEnvironment(): TPromise<IEnv> {
336+
if (process.env['VSCODE_CLI'] === '1') {
337337
return TPromise.as({});
338338
}
339339

340-
if (process.env['VSCODE_CLI'] === '1') {
340+
if (platform.isWindows) {
341341
return TPromise.as({});
342342
}
343343

344-
return getUnixUserEnvironment();
344+
return getUnixShellEnvironment();
345345
}
346346

347347
/**
348348
* Returns the user environment necessary for all Code processes.
349349
* Such environment needs to be propagated to the renderer/shared
350350
* processes.
351351
*/
352-
function getUserEnvironment(): TPromise<IEnv> {
353-
return getUserShellEnvironment().then(userShellEnv => {
352+
function getEnvironment(): TPromise<IEnv> {
353+
return getShellEnvironment().then(shellEnv => {
354354
return instantiationService.invokeFunction(a => {
355355
const envService = a.get(IEnvironmentService);
356356
const instanceEnv = {
357357
VSCODE_PID: String(process.pid),
358358
VSCODE_IPC_HOOK: envService.mainIPCHandle,
359-
VSCODE_SHARED_IPC_HOOK: envService.sharedIPCHandle
359+
VSCODE_SHARED_IPC_HOOK: envService.sharedIPCHandle,
360+
VSCODE_NLS_CONFIG: process.env['VSCODE_NLS_CONFIG']
360361
};
361362

362-
return assign({}, userShellEnv, instanceEnv);
363+
return assign({}, shellEnv, instanceEnv);
363364
});
364365
});
365366
}
366367

367368
// On some platforms we need to manually read from the global environment variables
368369
// and assign them to the process environment (e.g. when doubleclick app on Mac)
369-
getUserEnvironment().then(userEnv => {
370-
assign(process.env, userEnv);
371-
372-
// Make sure the NLS Config travels to the rendered process
373-
// See also https://github.com/Microsoft/vscode/issues/4558
374-
userEnv['VSCODE_NLS_CONFIG'] = process.env['VSCODE_NLS_CONFIG'];
370+
getEnvironment().then(env => {
371+
assign(process.env, env);
375372

376373
return instantiationService.invokeFunction(a => a.get(IEnvironmentService).createPaths())
377374
.then(() => instantiationService.invokeFunction(setupIPC))
378-
.then(ipcServer => instantiationService.invokeFunction(main, ipcServer, userEnv));
375+
.then(ipcServer => instantiationService.invokeFunction(main, ipcServer, env));
379376
})
380377
.done(null, err => instantiationService.invokeFunction(quit, err));

0 commit comments

Comments
 (0)