Skip to content

Commit c255f9e

Browse files
author
Benjamin Pasero
committed
web - first cut API
1 parent 770c8d5 commit c255f9e

8 files changed

Lines changed: 79 additions & 60 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-oss-dev",
33
"version": "1.36.0",
4-
"distro": "8a2c96a9296c1b8112a4d0e74c0b10063c1a8d44",
4+
"distro": "5fc996cf23a90ee6ea8d55df47948fcccfd7b613",
55
"author": {
66
"name": "Microsoft Corporation"
77
},

src/buildfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports.base = [{
1212
}];
1313

1414
exports.workbench = require('./vs/workbench/buildfile').collectModules(['vs/workbench/workbench.main']);
15-
exports.workbenchWeb = require('./vs/workbench/buildfile').collectModules(['vs/workbench/workbench.web.main']);
15+
exports.workbenchWeb = require('./vs/workbench/buildfile').collectModules(['vs/workbench/workbench.web.api']);
1616

1717
exports.code = require('./vs/code/buildfile').collectModules();
1818

src/vs/code/browser/workbench/workbench.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
<body class="vs-dark" aria-label="">
1111
</body>
1212

13-
<!-- Startup via workbench.js -->
13+
<!-- Require our AMD loader -->
14+
<script src="./out/vs/loader.js"></script>
15+
16+
<!-- Window Configuration from Server -->
1417
<script>
15-
self.CONNECTION_AUTH_TOKEN = '{{CONNECTION_AUTH_TOKEN}}';
1618
self.WINDOW_CONFIGURATION = {
19+
connectionAuthToken: '{{CONNECTION_AUTH_TOKEN}}',
1720
folderUri: '{{FOLDER}}',
1821
workspaceUri: '{{WORKSPACE}}',
1922
userDataUri: '{{USER_DATA}}',
20-
authority: '{{AUTHORITY}}',
23+
remoteAuthority: '{{AUTHORITY}}',
2124
webviewEndpoint: '{{WEBVIEW_ENDPOINT}}'
2225
}
2326
</script>

src/vs/code/browser/workbench/workbench.js

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,22 @@
88

99
(function () {
1010

11-
function loadScript(path, callback) {
12-
let script = document.createElement('script');
13-
script.onload = callback;
14-
script.async = true;
15-
script.type = 'text/javascript';
16-
script.src = path;
17-
document.head.appendChild(script);
18-
}
19-
20-
loadScript('./out/vs/loader.js', function () {
21-
22-
// @ts-ignore
23-
require.config({
24-
baseUrl: `${window.location.origin}/out`,
25-
paths: {
26-
'vscode-textmate': `${window.location.origin}/node_modules/vscode-textmate/release/main`,
27-
'onigasm-umd': `${window.location.origin}/node_modules/onigasm-umd/release/main`,
28-
'xterm': `${window.location.origin}/node_modules/xterm/lib/xterm.js`,
29-
'xterm-addon-search': `${window.location.origin}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
30-
'xterm-addon-web-links': `${window.location.origin}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`,
31-
}
32-
});
11+
// @ts-ignore
12+
require.config({
13+
baseUrl: `${window.location.origin}/out`,
14+
paths: {
15+
'vscode-textmate': `${window.location.origin}/node_modules/vscode-textmate/release/main`,
16+
'onigasm-umd': `${window.location.origin}/node_modules/onigasm-umd/release/main`,
17+
'xterm': `${window.location.origin}/node_modules/xterm/lib/xterm.js`,
18+
'xterm-addon-search': `${window.location.origin}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
19+
'xterm-addon-web-links': `${window.location.origin}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`,
20+
}
21+
});
3322

23+
// @ts-ignore
24+
require(['vs/workbench/workbench.web.api'], function () {
3425
// @ts-ignore
35-
require([
36-
'vs/workbench/workbench.web.main',
37-
'vs/nls!vs/workbench/workbench.web.main',
38-
'vs/css!vs/workbench/workbench.web.main'
39-
],
40-
// @ts-ignore
41-
function () {
42-
// @ts-ignore
43-
require('vs/workbench/browser/web.main').main(self['WINDOW_CONFIGURATION']).then(undefined, console.error);
44-
});
26+
// eslint-disable-next-line no-undef
27+
monaco.workbench.create(document.body, self.WINDOW_CONFIGURATION);
4528
});
4629
})();

src/vs/platform/sign/browser/signService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ISignService } from 'vs/platform/sign/common/sign';
7+
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
78

89
export class SignService implements ISignService {
9-
_serviceBrand: any;
10+
11+
_serviceBrand: ServiceIdentifier<ISignService>;
1012

1113
async sign(value: string): Promise<string> {
12-
return Promise.resolve((<any>self).CONNECTION_AUTH_TOKEN);
14+
return Promise.resolve((<any>self).WINDOW_CONFIGURATION.connectionAuthToken);
1315
}
1416
}

src/vs/workbench/browser/web.main.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { Schemas } from 'vs/base/common/network';
2424
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
2525
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2626
import { onUnexpectedError } from 'vs/base/common/errors';
27-
import { URI, UriComponents } from 'vs/base/common/uri';
27+
import { URI } from 'vs/base/common/uri';
2828
import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
2929
import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService';
3030
import { ConfigurationCache } from 'vs/workbench/services/configuration/browser/configurationCache';
@@ -34,21 +34,27 @@ import { ISignService } from 'vs/platform/sign/common/sign';
3434
import { SignService } from 'vs/platform/sign/browser/signService';
3535
import { hash } from 'vs/base/common/hash';
3636
import { joinPath } from 'vs/base/common/resources';
37+
import { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api';
3738

3839
interface IWindowConfiguration {
3940
remoteAuthority: string;
4041

4142
userDataUri: URI;
43+
44+
webviewEndpoint?: string;
45+
4246
folderUri?: URI;
4347
workspaceUri?: URI;
44-
webviewEndpoint?: string;
4548
}
4649

4750
class CodeRendererMain extends Disposable {
4851

4952
private workbench: Workbench;
5053

51-
constructor(private readonly configuration: IWindowConfiguration) {
54+
constructor(
55+
private readonly domElement: HTMLElement,
56+
private readonly configuration: IWindowConfiguration
57+
) {
5258
super();
5359
}
5460

@@ -60,7 +66,7 @@ class CodeRendererMain extends Disposable {
6066

6167
// Create Workbench
6268
this.workbench = new Workbench(
63-
document.body,
69+
this.domElement,
6470
services.serviceCollection,
6571
services.logService
6672
);
@@ -186,23 +192,16 @@ class CodeRendererMain extends Disposable {
186192
}
187193
}
188194

189-
export interface IWindowConfigurationContents {
190-
authority: string;
191-
userDataUri: UriComponents;
192-
folderUri?: UriComponents;
193-
workspaceUri?: UriComponents;
194-
webviewEndpoint?: string;
195-
}
196-
197-
export function main(windowConfigurationContents: IWindowConfigurationContents): Promise<void> {
198-
const windowConfiguration: IWindowConfiguration = {
199-
userDataUri: URI.revive(windowConfigurationContents.userDataUri),
200-
remoteAuthority: windowConfigurationContents.authority,
201-
folderUri: windowConfigurationContents.folderUri ? URI.revive(windowConfigurationContents.folderUri) : undefined,
202-
workspaceUri: windowConfigurationContents.workspaceUri ? URI.revive(windowConfigurationContents.workspaceUri) : undefined,
203-
webviewEndpoint: windowConfigurationContents.webviewEndpoint
204-
};
195+
export function main(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise<void> {
196+
const renderer = new CodeRendererMain(
197+
domElement,
198+
{
199+
userDataUri: URI.revive(options.userDataUri),
200+
remoteAuthority: options.remoteAuthority,
201+
webviewEndpoint: options.webviewEndpoint,
202+
folderUri: options.folderUri ? URI.revive(options.folderUri) : undefined,
203+
workspaceUri: options.workspaceUri ? URI.revive(options.workspaceUri) : undefined,
204+
});
205205

206-
const renderer = new CodeRendererMain(windowConfiguration);
207206
return renderer.open();
208207
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import 'vs/workbench/workbench.web.main';
7+
import { main } from 'vs/workbench/browser/web.main';
8+
import { UriComponents } from 'vs/base/common/uri';
9+
10+
export interface IWorkbenchConstructionOptions {
11+
remoteAuthority: string;
12+
13+
userDataUri: UriComponents;
14+
15+
webviewEndpoint?: string;
16+
17+
folderUri?: UriComponents;
18+
workspaceUri?: UriComponents;
19+
}
20+
21+
function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise<void> {
22+
return main(domElement, options);
23+
}
24+
25+
const api: any = self;
26+
27+
api.monaco = {
28+
workbench: {
29+
create
30+
}
31+
};

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@
364364
"**/vs/platform/*/{common,browser}/**",
365365
"**/vs/editor/{common,browser}/**",
366366
"**/vs/editor/contrib/**", // editor/contrib is equivalent to /browser/ by convention
367+
"**/vs/workbench/workbench.web.api",
367368
"**/vs/workbench/{common,browser}/**",
368369
"**/vs/workbench/services/*/{common,browser}/**",
369370
"assert"

0 commit comments

Comments
 (0)