Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Jan 18, 2023
1 parent 63cc17d commit 227f746
Show file tree
Hide file tree
Showing 42 changed files with 936 additions and 519 deletions.
29 changes: 15 additions & 14 deletions components/dashboard/src/service/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export function getGitpodService(): GitpodService {
let ideFrontendService: IDEFrontendService | undefined;
export function getIDEFrontendService(workspaceID: string, sessionId: string, service: GitpodService) {
if (!ideFrontendService) {
ideFrontendService = new IDEFrontendService(workspaceID, sessionId, service, window.parent);
const parentOrigin = new URLSearchParams(window.location.search).get("parentOrigin") || undefined;
ideFrontendService = new IDEFrontendService(workspaceID, sessionId, service, window.parent, parentOrigin);
}
return ideFrontendService;
}

export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
private instanceID: string | undefined;
private ideUrl: URL | undefined;
private user: User | undefined;

private latestStatus?: IDEFrontendDashboardService.Status;
Expand All @@ -75,14 +75,15 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
readonly onSetState = this.onDidChangeEmitter.event;

constructor(
private workspaceID: string,
private sessionId: string,
private service: GitpodService,
private clientWindow: Window,
private readonly workspaceID: string,
private readonly sessionId: string,
private readonly service: GitpodService,
private readonly clientWindow: Window,
private parentOrigin: string | undefined,
) {
this.processServerInfo();
window.addEventListener("message", (event: MessageEvent) => {
if (event.origin !== this.ideUrl?.origin) {
if (event.origin !== this.parentOrigin) {
return;
}

Expand Down Expand Up @@ -119,9 +120,9 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {

const listener = await this.service.listenToInstance(this.workspaceID);
listener.onDidChange(() => {
this.ideUrl = listener.info.latestInstance?.ideUrl
? new URL(listener.info.latestInstance?.ideUrl)
: undefined;
if (!this.parentOrigin && listener.info.latestInstance?.ideUrl) {
this.parentOrigin = new URL(listener.info.latestInstance?.ideUrl).origin;
}
const status = this.getWorkspaceStatus(listener.info);
this.latestStatus = status;
this.sendStatusUpdate(this.latestStatus);
Expand Down Expand Up @@ -174,25 +175,25 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
}

sendStatusUpdate(status: IDEFrontendDashboardService.Status): void {
if (!this.ideUrl) {
if (!this.parentOrigin) {
return;
}
this.clientWindow.postMessage(
{
type: "ide-status-update",
status,
} as IDEFrontendDashboardService.StatusUpdateEventData,
this.ideUrl.origin,
this.parentOrigin,
);
}

relocate(url: string): void {
if (!this.ideUrl) {
if (!this.parentOrigin) {
return;
}
this.clientWindow.postMessage(
{ type: "ide-relocate", url } as IDEFrontendDashboardService.RelocateEventData,
this.ideUrl.origin,
this.parentOrigin,
);
}
}
Loading

0 comments on commit 227f746

Please sign in to comment.