-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21879 from Microsoft/joao/shared-process
Move shared process to a browser window
- Loading branch information
Showing
18 changed files
with
327 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- Copyright (C) Microsoft Corporation. All rights reserved. --> | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
|
||
<body aria-label=""> | ||
Shared Process | ||
</body> | ||
|
||
<!-- Startup via index.js --> | ||
<script src="sharedProcess.js"></script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// Warning: Do not use the `let` declarator in this file, it breaks our minification | ||
|
||
'use strict'; | ||
|
||
/*global window,document,define*/ | ||
|
||
const path = require('path'); | ||
const electron = require('electron'); | ||
const remote = electron.remote; | ||
const ipc = electron.ipcRenderer; | ||
|
||
function assign(destination, source) { | ||
return Object.keys(source) | ||
.reduce(function (r, key) { r[key] = source[key]; return r; }, destination); | ||
} | ||
|
||
function parseURLQueryArgs() { | ||
const search = window.location.search || ''; | ||
|
||
return search.split(/[?&]/) | ||
.filter(function (param) { return !!param; }) | ||
.map(function (param) { return param.split('='); }) | ||
.filter(function (param) { return param.length === 2; }) | ||
.reduce(function (r, param) { r[param[0]] = decodeURIComponent(param[1]); return r; }, {}); | ||
} | ||
|
||
function createScript(src, onload) { | ||
const script = document.createElement('script'); | ||
script.src = src; | ||
script.addEventListener('load', onload); | ||
|
||
const 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; | ||
} | ||
|
||
return encodeURI('file://' + pathName); | ||
} | ||
|
||
function main() { | ||
const args = parseURLQueryArgs(); | ||
const configuration = JSON.parse(args['config'] || '{}') || {}; | ||
|
||
// 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: {} }; | ||
const config = process.env['VSCODE_NLS_CONFIG']; | ||
if (config) { | ||
process.env['VSCODE_NLS_CONFIG'] = config; | ||
try { | ||
nlsConfig = JSON.parse(config); | ||
} catch (e) { /*noop*/ } | ||
} | ||
|
||
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); | ||
|
||
// Load the loader and start loading the workbench | ||
const 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 | ||
|
||
window.MonacoEnvironment = {}; | ||
|
||
const nodeCachedDataErrors = window.MonacoEnvironment.nodeCachedDataErrors = []; | ||
require.config({ | ||
baseUrl: rootUrl, | ||
'vs/nls': nlsConfig, | ||
nodeCachedDataDir: configuration.nodeCachedDataDir, | ||
onNodeCachedDataError: function (err) { nodeCachedDataErrors.push(err) }, | ||
nodeModules: [/*BUILD->INSERT_NODE_MODULES*/] | ||
}); | ||
|
||
if (nlsConfig.pseudo) { | ||
require(['vs/nls'], function (nlsPlugin) { | ||
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo); | ||
}); | ||
} | ||
|
||
require(['vs/code/electron-browser/sharedProcessMain'], function () { }); | ||
}); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.