main.js 2.5 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

// Perf measurements
global.vscodeStart = Date.now();

var app = require('electron').app;
J
Joao Moreno 已提交
10
var fs = require('fs');
J
Joao Moreno 已提交
11 12
var path = require('path');

J
Joao Moreno 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26
// Duplicated in ../index.html for the renderes.
function getNLSConfiguration() {
	var locale = undefined;
	var localeOpts = '--locale';
	for (var i = 0; i < process.argv.length; i++) {
		var arg = process.argv[i];
		if (arg.slice(0, localeOpts.length) == localeOpts) {
			var segments = arg.split('=');
			locale = segments[1];
			break;
		}
	}

	if (locale === 'pseudo') {
27
		return { locale: locale, availableLanguages: {}, pseudo: true }
J
Joao Moreno 已提交
28
	}
29 30
	locale = locale || app.getLocale();
	var initialLocale = locale;
J
Joao Moreno 已提交
31
	if (process.env.VSCODE_DEV) {
32
		return { locale: locale, availableLanguages: {} };
J
Joao Moreno 已提交
33 34 35 36
	}
	// We have a built version so we have extracted nls file. Try to find
	// the right file to use.
	while (locale) {
37
		var candidate = path.join(__dirname, 'vs', 'workbench', 'electron-main', 'main.nls.') + locale + '.js';
J
Joao Moreno 已提交
38
		if (fs.existsSync(candidate)) {
39
			return { locale: initialLocale, availableLanguages: { '*': locale } };
J
Joao Moreno 已提交
40 41 42 43 44 45 46 47 48 49
		} else {
			var index = locale.lastIndexOf('-');
			if (index > 0) {
				locale = locale.substring(0, index);
			} else {
				locale = null;
			}
		}
	}

50
	return { locale: initialLocale, availableLanguages: {} };
J
Joao Moreno 已提交
51 52
}

J
Joao Moreno 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
// Change cwd if given via env variable
try {
	if (process.env.VSCODE_CWD) {
		process.chdir(process.env.VSCODE_CWD);
	}
} catch (err) {
	// noop
}

// Set path according to being built or not
if (process.env.VSCODE_DEV) {
	var appData = app.getPath('appData');
	app.setPath('userData', path.join(appData, 'Code-Development'));
}

// Mac: when someone drops a file to the not-yet running VSCode, the open-file event fires even before
// the app-ready event. We listen very early for open-file and remember this upon startup as path to open.
global.macOpenFiles = [];
app.on('open-file', function(event, path) {
	global.macOpenFiles.push(path);
});

J
Joao Moreno 已提交
75 76 77
var nlsConfig = getNLSConfiguration();
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);

J
Joao Moreno 已提交
78 79
// Load our code once ready
app.once('ready', function() {
80
	require('./bootstrap-amd').bootstrap('vs/workbench/electron-main/main');
J
Joao Moreno 已提交
81
});