-
Notifications
You must be signed in to change notification settings - Fork 1.4k
polish IDEFrontendDashboardService #15895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -15,33 +15,37 @@ export class FrontendDashboardServiceClient implements IDEFrontendDashboardServi | |
| private readonly onDidChangeEmitter = new Emitter<IDEFrontendDashboardService.Status>(); | ||
| readonly onStatusUpdate = this.onDidChangeEmitter.event; | ||
|
|
||
| private readonly onOpenBrowserIDEEmitter = new Emitter<void>(); | ||
| readonly onOpenBrowserIDE = this.onOpenBrowserIDEEmitter.event; | ||
|
|
||
| private resolveInit!: () => void; | ||
| private initPromise = new Promise<void>((resolve) => (this.resolveInit = resolve)); | ||
|
|
||
| private version?: number; | ||
|
|
||
| constructor(private serverWindow: Window) { | ||
| window.addEventListener("message", (event: MessageEvent) => { | ||
| if (event.origin !== serverUrl.url.origin) { | ||
| return; | ||
| } | ||
| if (IDEFrontendDashboardService.isStatusUpdateEventData(event.data)) { | ||
| this.version = event.data.version; | ||
| this.latestStatus = event.data.status; | ||
| this.resolveInit(); | ||
| this.onDidChangeEmitter.fire(this.latestStatus); | ||
| } | ||
| if (IDEFrontendDashboardService.isRelocateEventData(event.data)) { | ||
| this.relocate(event.data.url); | ||
| window.location.href = event.data.url; | ||
| } | ||
| if (IDEFrontendDashboardService.isOpenBrowserIDE(event.data)) { | ||
| this.onOpenBrowserIDEEmitter.fire(undefined); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| initialize(): Promise<void> { | ||
| return this.initPromise; | ||
| } | ||
|
|
||
| relocate(url: string): void { | ||
| window.location.href = url; | ||
| } | ||
|
|
||
| trackEvent(msg: RemoteTrackMessage): void { | ||
| this.serverWindow.postMessage( | ||
| { type: "ide-track-event", msg } as IDEFrontendDashboardService.TrackEventData, | ||
|
|
@@ -62,4 +66,32 @@ export class FrontendDashboardServiceClient implements IDEFrontendDashboardServi | |
| serverUrl.url.origin, | ||
| ); | ||
| } | ||
|
|
||
| openDesktopIDE(url: string): void { | ||
| if (this.version && this.version >= 1) { | ||
| // always perfrom redirect to dekstop IDE on gitpod origin | ||
| // to avoid confirmation popup on each workspace origin | ||
| this.serverWindow.postMessage( | ||
| { type: "ide-open-desktop", url } as IDEFrontendDashboardService.OpenDesktopIDE, | ||
| serverUrl.url.origin, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // TODO(ak) remove after new dashboard is deployed | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question about the todo |
||
| let redirect = false; | ||
| try { | ||
| const desktopLink = new URL(url); | ||
| redirect = desktopLink.protocol !== "http:" && desktopLink.protocol !== "https:"; | ||
| } catch (e) { | ||
| console.error("invalid desktop link:", e); | ||
| } | ||
| // redirect only if points to desktop application | ||
| // don't navigate browser to another page | ||
| if (redirect) { | ||
| window.location.href = url; | ||
| } else { | ||
| window.open(url, "_blank", "noopener"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO intended to be left in place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after both deployments, we will do another PR to clean up