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

6
//@ts-check
J
Joao Moreno 已提交
7 8
'use strict';

9 10 11
const perf = require('../../../base/common/performance');
perf.mark('renderer/started');

12
const bootstrapWindow = require('../../../../bootstrap-window');
J
Joao Moreno 已提交
13

14
// Setup shell environment
15
process['lazyEnv'] = getLazyEnv();
B
Benjamin Pasero 已提交
16

17 18 19 20 21 22 23 24
// Load workbench main
bootstrapWindow.load([
	'vs/workbench/workbench.main',
	'vs/nls!vs/workbench/workbench.main',
	'vs/css!vs/workbench/workbench.main'
],
	function (workbench, configuration) {
		perf.mark('didLoadWorkbenchMain');
J
Joao Moreno 已提交
25

26
		return process['lazyEnv'].then(function () {
27
			perf.mark('main/startup');
J
Joao Moreno 已提交
28

29
			// @ts-ignore
30
			return require('vs/workbench/electron-browser/main').startup(configuration);
D
Dirk Baeumer 已提交
31
		});
32 33 34 35 36 37
	}, {
		removeDeveloperKeybindingsAfterLoad: true,
		canModifyDOM: function (windowConfig) {
			showPartsSplash(windowConfig);
		},
		beforeLoaderConfig: function (windowConfig, loaderConfig) {
38
			const onNodeCachedData = window['MonacoEnvironment'].onNodeCachedData = [];
39 40 41 42 43 44 45 46 47
			loaderConfig.onNodeCachedData = function () {
				onNodeCachedData.push(arguments);
			};

			loaderConfig.recordStats = !!windowConfig.performance;
		},
		beforeRequire: function () {
			perf.mark('willLoadWorkbenchMain');
		}
D
Dirk Baeumer 已提交
48
	});
B
Benjamin Pasero 已提交
49

50 51 52
/**
 * @param {object} configuration
 */
53
function showPartsSplash(configuration) {
J
Johannes Rieken 已提交
54
	perf.mark('willShowPartsSplash');
55

J
Johannes Rieken 已提交
56 57
	let data;
	try {
58
		// TODO@Ben remove me after a while
59
		perf.mark('willReadLocalStorage');
60
		let raw = window.localStorage.getItem('storage://global/parts-splash-data');
61
		perf.mark('didReadLocalStorage');
J
Johannes Rieken 已提交
62 63 64
		data = JSON.parse(raw);
	} catch (e) {
		// ignore
65
	}
J
Johannes Rieken 已提交
66

67
	// high contrast mode has been turned on from the outside, e.g OS -> ignore stored colors and layouts
68
	if (data && configuration.highContrast && data.baseTheme !== 'hc-black') {
69 70 71 72 73 74
		data = undefined;
	}

	// developing an extension -> ignore stored layouts
	if (data && configuration.extensionDevelopmentPath) {
		data.layoutInfo = undefined;
75 76
	}

J
Johannes Rieken 已提交
77 78 79 80
	// minimal color configuration (works with or without persisted data)
	const baseTheme = data ? data.baseTheme : configuration.highContrast ? 'hc-black' : 'vs-dark';
	const shellBackground = data ? data.colorInfo.editorBackground : configuration.highContrast ? '#000000' : '#1E1E1E';
	const shellForeground = data ? data.colorInfo.foreground : configuration.highContrast ? '#FFFFFF' : '#CCCCCC';
81
	const style = document.createElement('style');
82
	style.className = 'initialShellColors';
83
	document.head.appendChild(style);
J
Johannes Rieken 已提交
84 85
	document.body.className = `monaco-shell ${baseTheme}`;
	style.innerHTML = `.monaco-shell { background-color: ${shellBackground}; color: ${shellForeground}; }`;
86 87


J
Johannes Rieken 已提交
88 89 90
	if (data && data.layoutInfo) {
		// restore parts if possible (we might not always store layout info)
		const { id, layoutInfo, colorInfo } = data;
J
Johannes Rieken 已提交
91
		const splash = document.createElement('div');
J
Johannes Rieken 已提交
92
		splash.id = id;
93 94 95 96

		// ensure there is enough space
		layoutInfo.sideBarWidth = Math.min(layoutInfo.sideBarWidth, window.innerWidth - (layoutInfo.activityBarWidth + layoutInfo.editorPartMinWidth));

J
Johannes Rieken 已提交
97 98
		if (configuration.folderUri || configuration.workspace) {
			// folder or workspace -> status bar color, sidebar
99
			splash.innerHTML = `
B
Benjamin Pasero 已提交
100
			<div style="position: absolute; width: 100%; left: 0; top: 0; height: ${layoutInfo.titleBarHeight}px; background-color: ${colorInfo.titleBarBackground}; -webkit-app-region: drag;"></div>
J
Johannes Rieken 已提交
101 102 103
			<div style="position: absolute; height: calc(100% - ${layoutInfo.titleBarHeight}px); top: ${layoutInfo.titleBarHeight}px; ${layoutInfo.sideBarSide}: 0; width: ${layoutInfo.activityBarWidth}px; background-color: ${colorInfo.activityBarBackground};"></div>
			<div style="position: absolute; height: calc(100% - ${layoutInfo.titleBarHeight}px); top: ${layoutInfo.titleBarHeight}px; ${layoutInfo.sideBarSide}: ${layoutInfo.activityBarWidth}px; width: ${layoutInfo.sideBarWidth}px; background-color: ${colorInfo.sideBarBackground};"></div>
			<div style="position: absolute; width: 100%; bottom: 0; left: 0; height: ${layoutInfo.statusBarHeight}px; background-color: ${colorInfo.statusBarBackground};"></div>
104
			`;
J
Johannes Rieken 已提交
105 106
		} else {
			// empty -> speical status bar color, no sidebar
107
			splash.innerHTML = `
B
Benjamin Pasero 已提交
108
			<div style="position: absolute; width: 100%; left: 0; top: 0; height: ${layoutInfo.titleBarHeight}px; background-color: ${colorInfo.titleBarBackground}; -webkit-app-region: drag;"></div>
J
Johannes Rieken 已提交
109 110
			<div style="position: absolute; height: calc(100% - ${layoutInfo.titleBarHeight}px); top: ${layoutInfo.titleBarHeight}px; ${layoutInfo.sideBarSide}: 0; width: ${layoutInfo.activityBarWidth}px; background-color: ${colorInfo.activityBarBackground};"></div>
			<div style="position: absolute; width: 100%; bottom: 0; left: 0; height: ${layoutInfo.statusBarHeight}px; background-color: ${colorInfo.statusBarNoFolderBackground};"></div>
111
			`;
J
Johannes Rieken 已提交
112 113
		}
		document.body.appendChild(splash);
114
	}
115

J
Johannes Rieken 已提交
116
	perf.mark('didShowPartsSplash');
117 118
}

119 120 121
/**
 * @returns {Promise<void>}
 */
122
function getLazyEnv() {
123
	// @ts-ignore
124
	const ipc = require('electron').ipcRenderer;
A
Alex Dima 已提交
125

126 127 128 129 130
	return new Promise(function (resolve) {
		const handle = setTimeout(function () {
			resolve();
			console.warn('renderer did not receive lazyEnv in time');
		}, 10000);
J
Joao Moreno 已提交
131

132 133 134
		ipc.once('vscode:acceptShellEnv', function (event, shellEnv) {
			clearTimeout(handle);
			bootstrapWindow.assign(process.env, shellEnv);
135
			// @ts-ignore
136
			resolve(process.env);
J
Joao Moreno 已提交
137
		});
138

139
		ipc.send('vscode:fetchShellEnv');
140
	});
J
Johannes Rieken 已提交
141
}