improve consistency in env sent to renderer procs

fixes #10194
This commit is contained in:
Joao Moreno 2016-08-08 16:12:32 +02:00
parent ff061902a7
commit 18beedd450
6 changed files with 199 additions and 200 deletions

View file

@ -17,6 +17,7 @@ if not exist out node .\node_modules\gulp\bin\gulp.js compile
:: Configuration
set NODE_ENV=development
set VSCODE_DEV=1
set VSCODE_CLI=1
set ELECTRON_DEFAULT_ERROR_MODE=1
set ELECTRON_ENABLE_LOGGING=1
set ELECTRON_ENABLE_STACK_DUMPING=1

View file

@ -22,6 +22,7 @@ function code() {
# Configuration
export NODE_ENV=development
export VSCODE_DEV=1
export VSCODE_CLI=1
export ELECTRON_ENABLE_LOGGING=1
export ELECTRON_ENABLE_STACK_DUMPING=1

View file

@ -44,10 +44,10 @@ if (typeof process === 'object') {
_isMacintosh = (process.platform === 'darwin');
_isLinux = (process.platform === 'linux');
_isRootUser = !_isWindows && (process.getuid() === 0);
let vscode_nls_config = process.env['VSCODE_NLS_CONFIG'];
if (vscode_nls_config) {
let rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
if (rawNlsConfig) {
try {
let nlsConfig:NLSConfig = JSON.parse(vscode_nls_config);
let nlsConfig:NLSConfig = JSON.parse(rawNlsConfig);
let resolved = nlsConfig.availableLanguages['*'];
_locale = nlsConfig.locale;
// VSCode's default language is 'en'

View file

@ -269,7 +269,7 @@ interface IEnv {
[key: string]: string;
}
function getUnixUserEnvironment(): TPromise<IEnv> {
function getUnixShellEnvironment(): TPromise<IEnv> {
const promise = new TPromise((c, e) => {
const runAsNode = process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
const noAttach = process.env['ELECTRON_NO_ATTACH_CONSOLE'];
@ -328,20 +328,20 @@ function getUnixUserEnvironment(): TPromise<IEnv> {
}
/**
* 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.
* We eed to get the environment from a user's shell.
* This should only be done when Code itself is not launched
* from within a shell.
*/
function getUserShellEnvironment(): TPromise<IEnv> {
if (platform.isWindows) {
return TPromise.as({});
}
function getShellEnvironment(): TPromise<IEnv> {
if (process.env['VSCODE_CLI'] === '1') {
return TPromise.as({});
}
return getUnixUserEnvironment();
if (platform.isWindows) {
return TPromise.as({});
}
return getUnixShellEnvironment();
}
/**
@ -349,32 +349,29 @@ function getUserShellEnvironment(): TPromise<IEnv> {
* Such environment needs to be propagated to the renderer/shared
* processes.
*/
function getUserEnvironment(): TPromise<IEnv> {
return getUserShellEnvironment().then(userShellEnv => {
function getEnvironment(): TPromise<IEnv> {
return getShellEnvironment().then(shellEnv => {
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
VSCODE_SHARED_IPC_HOOK: envService.sharedIPCHandle,
VSCODE_NLS_CONFIG: process.env['VSCODE_NLS_CONFIG']
};
return assign({}, userShellEnv, instanceEnv);
return assign({}, shellEnv, 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 => {
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'];
getEnvironment().then(env => {
assign(process.env, env);
return instantiationService.invokeFunction(a => a.get(IEnvironmentService).createPaths())
.then(() => instantiationService.invokeFunction(setupIPC))
.then(ipcServer => instantiationService.invokeFunction(main, ipcServer, userEnv));
.then(ipcServer => instantiationService.invokeFunction(main, ipcServer, env));
})
.done(null, err => instantiationService.invokeFunction(quit, err));

View file

@ -14,215 +14,221 @@
<!-- Helpers -->
<script type="text/javascript">
var fs = require('fs');
var path = require('path');
var electron = require('electron');
var remote = electron.remote;
var ipc = electron.ipcRenderer;
var windowId = remote.getCurrentWindow().id;
var path = require('path');
var electron = require('electron');
var remote = electron.remote;
var ipc = electron.ipcRenderer;
var windowId = remote.getCurrentWindow().id;
function onError(error, enableDeveloperTools) {
if (enableDeveloperTools) {
ipc.send('vscode:openDevTools', windowId);
}
console.error('[uncaught exception]: ' + error);
if (error.stack) {
console.error(error.stack);
}
function onError(error, enableDeveloperTools) {
if (enableDeveloperTools) {
ipc.send('vscode:openDevTools', windowId);
}
function parseURLQueryArgs() {
var result = {};
var search = window.location.search;
if (search) {
var params = search.split(/[?&]/);
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (param) {
var keyValue = param.split('=');
if (keyValue.length === 2) {
result[keyValue[0]] = decodeURIComponent(keyValue[1]);
}
console.error('[uncaught exception]: ' + error);
if (error.stack) {
console.error(error.stack);
}
}
function parseURLQueryArgs() {
var result = {};
var search = window.location.search;
if (search) {
var params = search.split(/[?&]/);
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (param) {
var keyValue = param.split('=');
if (keyValue.length === 2) {
result[keyValue[0]] = decodeURIComponent(keyValue[1]);
}
}
}
return result;
}
function createScript(src, onload) {
var script = document.createElement('script');
script.src = src;
script.addEventListener('load', onload);
return result;
}
var head = document.getElementsByTagName('head')[0];
head.insertBefore(script, head.lastChild);
function createScript(src, onload) {
var script = document.createElement('script');
script.src = src;
script.addEventListener('load', onload);
var head = document.getElementsByTagName('head')[0];
head.insertBefore(script, head.lastChild);
}
function uriFromPath(_path) {
var pathName = path.resolve(_path).replace(/\\/g, '/');
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
pathName = '/' + pathName;
}
function uriFromPath(_path) {
var pathName = path.resolve(_path).replace(/\\/g, '/');
return encodeURI('file://' + pathName);
}
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
pathName = '/' + pathName;
}
function registerListeners(enableDeveloperTools) {
return encodeURI('file://' + pathName);
// Devtools & reload support
if (enableDeveloperTools) {
var extractKey = function(e) {
return [
e.ctrlKey ? 'ctrl-' : '',
e.metaKey ? 'meta-' : '',
e.altKey ? 'alt-' : '',
e.shiftKey ? 'shift-' : '',
e.keyCode
].join('');
};
var TOGGLE_DEV_TOOLS_KB = (process.platform === 'darwin' ? 'meta-alt-73' : 'ctrl-shift-73'); // mac: Cmd-Alt-I, rest: Ctrl-Shift-I
var RELOAD_KB = (process.platform === 'darwin' ? 'meta-82' : 'ctrl-82'); // mac: Cmd-R, rest: Ctrl-R
window.addEventListener('keydown', function(e) {
var key = extractKey(e);
if (key === TOGGLE_DEV_TOOLS_KB) {
ipc.send('vscode:toggleDevTools', windowId);
} else if (key === RELOAD_KB) {
ipc.send('vscode:reloadWindow', windowId);
}
});
}
function registerListeners(enableDeveloperTools) {
process.on('uncaughtException', function(error) { onError(error, enableDeveloperTools) });
}
// Devtools & reload support
if (enableDeveloperTools) {
var extractKey = function(e) {
return [
e.ctrlKey ? 'ctrl-' : '',
e.metaKey ? 'meta-' : '',
e.altKey ? 'alt-' : '',
e.shiftKey ? 'shift-' : '',
e.keyCode
].join('');
};
var TOGGLE_DEV_TOOLS_KB = (process.platform === 'darwin' ? 'meta-alt-73' : 'ctrl-shift-73'); // mac: Cmd-Alt-I, rest: Ctrl-Shift-I
var RELOAD_KB = (process.platform === 'darwin' ? 'meta-82' : 'ctrl-82'); // mac: Cmd-R, rest: Ctrl-R
window.addEventListener('keydown', function(e) {
var key = extractKey(e);
if (key === TOGGLE_DEV_TOOLS_KB) {
ipc.send('vscode:toggleDevTools', windowId);
} else if (key === RELOAD_KB) {
ipc.send('vscode:reloadWindow', windowId);
}
});
}
process.on('uncaughtException', function(error) { onError(error, enableDeveloperTools) });
}
function assign(destination, source) {
source => Object.keys(source).forEach(key => destination[key] = source[key]);
return destination;
}
</script>
<!-- Startup Code -->
<script type="text/javascript">
var webFrame = require('electron').webFrame;
var args = parseURLQueryArgs();
var configuration = JSON.parse(args['config']) || {};
var enableDeveloperTools = !configuration.isBuilt || !!configuration.extensionDevelopmentPath;
var mainStarted = false;
var args = parseURLQueryArgs();
var configuration = JSON.parse(args['config']);
var enableDeveloperTools = !configuration.isBuilt || !!configuration.extensionDevelopmentPath;
// Correctly inherit the parent's environment
assign(process.env, configuration.userEnv);
// Get the nls configuration into the process.env as early as possible.
var nlsConfig = { availableLanguages: {} };
if (configuration.userEnv && configuration.userEnv['VSCODE_NLS_CONFIG']) {
var config = configuration.userEnv['VSCODE_NLS_CONFIG'];
process.env['VSCODE_NLS_CONFIG'] = config;
try {
if (config) {
nlsConfig = JSON.parse(config);
}
} catch (e) {
}
}
var locale = nlsConfig.availableLanguages['*'] || 'en';
if (locale === 'zh-tw') {
locale = 'zh-Hant';
} else if (locale === 'zh-cn') {
locale = 'zh-Hans';
}
window.document.documentElement.setAttribute('lang', locale);
// Get the nls configuration into the process.env as early as possible.
var nlsConfig = { availableLanguages: {} };
var config = process.env['VSCODE_NLS_CONFIG'];
if (config) {
process.env['VSCODE_NLS_CONFIG'] = config;
try {
nlsConfig = JSON.parse(config);
} catch (e) {}
}
registerListeners(enableDeveloperTools);
var locale = nlsConfig.availableLanguages['*'] || 'en';
// We get the global settings through a remote call from the browser
// because its value can change dynamically.
var globalSettings;
var globalSettingsValue = remote.getGlobal('globalSettingsValue');
if (globalSettingsValue) {
globalSettings = JSON.parse(globalSettingsValue);
} else {
globalSettings = {
settings: {},
keybindings: []
};
}
if (locale === 'zh-tw') {
locale = 'zh-Hant';
} else if (locale === 'zh-cn') {
locale = 'zh-Hans';
}
// disable pinch zoom & apply zoom level early to avoid glitches
var windowConfiguration = globalSettings.settings && globalSettings.settings.window;
webFrame.setZoomLevelLimits(1, 1);
if (windowConfiguration && typeof windowConfiguration.zoomLevel === 'number' && windowConfiguration.zoomLevel !== 0) {
webFrame.setZoomLevel(windowConfiguration.zoomLevel);
}
window.document.documentElement.setAttribute('lang', locale);
// Load the loader and start loading the workbench
var rootUrl = uriFromPath(configuration.appRoot) + '/out';
// In the bundled version the nls plugin is packaged with the loader so the NLS Plugins
// loads as soon as the loader loads. To be able to have pseudo translation
createScript(rootUrl + '/vs/loader.js', function() {
define('fs', ['original-fs'], function(originalFS) { return originalFS; }); // replace the patched electron fs with the original node fs for all AMD code
require.config({
baseUrl: rootUrl,
'vs/nls': nlsConfig,
recordStats: configuration.enablePerformance,
ignoreDuplicateModules: [
'vs/workbench/parts/search/common/searchQuery'
]
});
if (nlsConfig.pseudo) {
require(['vs/nls'], function(nlsPlugin) {
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);
});
}
registerListeners(enableDeveloperTools);
window.MonacoEnvironment = {};
var timers = window.MonacoEnvironment.timers = {
start: new Date()
};
// We get the global settings through a remote call from the browser
// because its value can change dynamically.
var globalSettings;
var globalSettingsValue = remote.getGlobal('globalSettingsValue');
if (globalSettingsValue) {
globalSettings = JSON.parse(globalSettingsValue);
} else {
globalSettings = {
settings: {},
keybindings: []
};
}
if (configuration.enablePerformance) {
var programStart = remote.getGlobal('programStart');
var vscodeStart = remote.getGlobal('vscodeStart');
// disable pinch zoom & apply zoom level early to avoid glitches
var windowConfiguration = globalSettings.settings && globalSettings.settings.window;
webFrame.setZoomLevelLimits(1, 1);
if (windowConfiguration && typeof windowConfiguration.zoomLevel === 'number' && windowConfiguration.zoomLevel !== 0) {
webFrame.setZoomLevel(windowConfiguration.zoomLevel);
}
if (programStart) {
timers.beforeProgram = new Date(programStart);
timers.afterProgram = new Date(vscodeStart);
}
timers.vscodeStart = new Date(vscodeStart);
timers.start = new Date(programStart || vscodeStart);
}
timers.beforeLoad = new Date();
require([
'vs/workbench/workbench.main',
'vs/nls!vs/workbench/workbench.main',
'vs/css!vs/workbench/workbench.main'
], function() {
timers.afterLoad = new Date();
var main = require('vs/workbench/electron-browser/main');
main.startup(configuration, globalSettings).then(function() {
mainStarted = true;
}, function(error) { onError(error, enableDeveloperTools) });
});
// Load the loader and start loading the workbench
var rootUrl = uriFromPath(configuration.appRoot) + '/out';
// In the bundled version the nls plugin is packaged with the loader so the NLS Plugins
// loads as soon as the loader loads. To be able to have pseudo translation
createScript(rootUrl + '/vs/loader.js', function() {
define('fs', ['original-fs'], function(originalFS) { return originalFS; }); // replace the patched electron fs with the original node fs for all AMD code
require.config({
baseUrl: rootUrl,
'vs/nls': nlsConfig,
recordStats: configuration.enablePerformance,
ignoreDuplicateModules: [
'vs/workbench/parts/search/common/searchQuery'
]
});
if (nlsConfig.pseudo) {
require(['vs/nls'], function(nlsPlugin) {
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);
});
}
window.MonacoEnvironment = {};
var timers = window.MonacoEnvironment.timers = {
start: new Date()
};
if (configuration.enablePerformance) {
var programStart = remote.getGlobal('programStart');
var vscodeStart = remote.getGlobal('vscodeStart');
if (programStart) {
timers.beforeProgram = new Date(programStart);
timers.afterProgram = new Date(vscodeStart);
}
timers.vscodeStart = new Date(vscodeStart);
timers.start = new Date(programStart || vscodeStart);
}
timers.beforeLoad = new Date();
require([
'vs/workbench/electron-browser/main',
'vs/workbench/workbench.main',
'vs/nls!vs/workbench/workbench.main',
'vs/css!vs/workbench/workbench.main'
], (main) => {
timers.afterLoad = new Date();
main
.startup(configuration, globalSettings)
.done(null, error => onError(error, enableDeveloperTools));
});
});
</script>
</head>
<body class="monaco-shell vs-dark" aria-label="">
<script>
(function() {
try {
var theme = window.localStorage.getItem('storage://global/workbench.theme');
if (theme) {
var baseTheme = theme.split(' ')[0];
if (baseTheme !== 'vs-dark') {
window.document.body.className = 'monaco-shell ' + baseTheme;
}
try {
var theme = window.localStorage.getItem('storage://global/workbench.theme');
if (theme) {
var baseTheme = theme.split(' ')[0];
if (baseTheme !== 'vs-dark') {
window.document.body.className = 'monaco-shell ' + baseTheme;
}
} catch (error) {
console.error(error);
}
})();
} catch (error) {
console.error(error);
}
})();
</script>
</body>
</html>

View file

@ -12,7 +12,6 @@ import errors = require('vs/base/common/errors');
import platform = require('vs/base/common/platform');
import paths = require('vs/base/common/paths');
import timer = require('vs/base/common/timer');
import {assign} from 'vs/base/common/objects';
import uri from 'vs/base/common/uri';
import strings = require('vs/base/common/strings');
import {IResourceInput} from 'vs/platform/editor/common/editor';
@ -20,10 +19,8 @@ import {EventService} from 'vs/platform/event/common/eventService';
import {WorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IWorkspace, IConfiguration, IEnvironment} from 'vs/platform/workspace/common/workspace';
import {ConfigurationService} from 'vs/workbench/services/configuration/node/configurationService';
import path = require('path');
import fs = require('fs');
import gracefulFs = require('graceful-fs');
gracefulFs.gracefulify(fs);
@ -56,9 +53,6 @@ export interface IMainEnvironment extends IEnvironment {
}
export function startup(environment: IMainEnvironment, globalSettings: IGlobalSettings): winjs.TPromise<void> {
// Inherit the user environment
assign(process.env, environment.userEnv);
// Shell Configuration
let shellConfiguration: IConfiguration = {
env: environment