diff --git a/components/gitpod-protocol/src/typings/globals.ts b/components/gitpod-protocol/src/typings/globals.ts new file mode 100644 index 00000000000000..e4e1e1767fffde --- /dev/null +++ b/components/gitpod-protocol/src/typings/globals.ts @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2020 TypeFox GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License-AGPL.txt in the project root for license information. + */ + +interface Window { + gitpod: { + service: import('../gitpod-service').GitpodService + } +} \ No newline at end of file diff --git a/components/supervisor/frontend/src/globals.d.ts b/components/supervisor/frontend/src/globals.d.ts index 352c82029f1fa0..0a5451ec2690f8 100644 --- a/components/supervisor/frontend/src/globals.d.ts +++ b/components/supervisor/frontend/src/globals.d.ts @@ -4,6 +4,8 @@ * See License-AGPL.txt in the project root for license information. */ +/// + /** * API specified by https://wicg.github.io/keyboard-map/ */ @@ -13,4 +15,4 @@ interface Navigator { interface Keyboard { getLayoutMap?(): Promise>; addEventListener?(type: 'layoutchange', listener: EventListenerOrEventListenerObject): void; -} +} \ No newline at end of file diff --git a/components/supervisor/frontend/src/index.ts b/components/supervisor/frontend/src/index.ts index 032bf40d78b4c7..b305aefb91c89f 100644 --- a/components/supervisor/frontend/src/index.ts +++ b/components/supervisor/frontend/src/index.ts @@ -11,14 +11,18 @@ import { createGitpodService } from "@gitpod/gitpod-protocol"; import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url"; const workspaceUrl = new GitpodHostUrl(window.location.href); +window.gitpod = { + service: createGitpodService(workspaceUrl.withoutWorkspacePrefix().toString()) +}; const { workspaceId } = workspaceUrl; -if (workspaceId) { - const gitpodService = createGitpodService(workspaceUrl.withoutWorkspacePrefix().toString()); - gitpodService.server.getWorkspace(workspaceId).then(info => { +const workspaceInfo = workspaceId ? window.gitpod.service.server.getWorkspace(workspaceId) : undefined; +if (!workspaceId) { + document.title += ': Unknown workspace'; + console.error(`Failed to extract a workspace id from '${window.location.href}'.`) +} else if (workspaceInfo) { + workspaceInfo.then(info => { document.title = info.workspace.description; }); -} else { - document.title += ': Unknown workspace'; } const checkReady: (kind: 'content' | 'ide') => Promise = kind => @@ -59,6 +63,9 @@ Promise.all([onDOMContentLoaded, checkReady('ide'), checkReady('content')]).then ideFrame.onload = () => loadingFrame.remove(); document.body.appendChild(ideFrame); ideFrame.contentWindow?.addEventListener('DOMContentLoaded', () => { + if (ideFrame.contentWindow) { + ideFrame.contentWindow.gitpod = window.gitpod; + } if (navigator.keyboard?.getLayoutMap && ideFrame.contentWindow?.navigator.keyboard?.getLayoutMap) { ideFrame.contentWindow.navigator.keyboard.getLayoutMap = navigator.keyboard.getLayoutMap.bind(navigator.keyboard); } diff --git a/components/theia/packages/gitpod-extension/src/browser/utils.ts b/components/theia/packages/gitpod-extension/src/browser/utils.ts index dbe11bede02f07..8e97ab3a4c9a41 100644 --- a/components/theia/packages/gitpod-extension/src/browser/utils.ts +++ b/components/theia/packages/gitpod-extension/src/browser/utils.ts @@ -4,17 +4,13 @@ * See License-AGPL.txt in the project root for license information. */ -import { createGitpodService } from "@gitpod/gitpod-protocol"; +/// + import { GitpodService } from "@gitpod/gitpod-protocol"; -import { GitpodHostUrl, workspaceIDRegex } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url"; +import { workspaceIDRegex } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url"; export function getGitpodService(): GitpodService { - if (!(window as any)['_gitpodService']) { - const serverUrl = new GitpodHostUrl(window.location.href).withoutWorkspacePrefix().toString(); - const service = createGitpodService(serverUrl); - (window as any)['_gitpodService'] = service; - } - return (window as any)['_gitpodService']; + return window.gitpod.service; } export function getWorkspaceID() {