Skip to content

redirect to desktop IDE on app domain #12082

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 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/supervisor/frontend/src/ide/heart-beat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const track = (w: Window) => {
}

let pageCloseCompatibile: boolean = false

// TODO(ak) remove
isSaaSServerGreaterThan("main.4124").then((r) => {
pageCloseCompatibile = r
})
Expand Down
11 changes: 1 addition & 10 deletions components/supervisor/frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,7 @@ const toStop = new DisposableCollection();
});
if (!desktopRedirected) {
desktopRedirected = true;
try {
const desktopLink = new URL(ideStatus.desktop.link)
// redirect only if points to desktop application
// don't navigate browser to another page
if (desktopLink.protocol != 'http:' && desktopLink.protocol != 'https:') {
window.location.href = ideStatus.desktop.link;
}
} catch (e) {
console.error('invalid desktop link:', e)
}
loading.openDesktopLink(ideStatus.desktop.link)
}
return loading.frame;
}
Expand Down
30 changes: 29 additions & 1 deletion components/supervisor/frontend/src/shared/loading-frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import { WindowMessageReader, WindowMessageWriter } from "@gitpod/gitpod-protoco
import { JsonRpcProxyFactory } from '@gitpod/gitpod-protocol/lib/messaging/proxy-factory';
import { createMessageConnection } from 'vscode-jsonrpc/lib/main';
import { ConsoleLogger } from 'vscode-ws-jsonrpc';
import { isSaaSServerGreaterThan } from '../ide/gitpod-server-compatibility';
import { startUrl } from './urls';

let openDesktopLinkSupported = false;
// TODO(ak) remove after 15.09.2022
isSaaSServerGreaterThan("main.4275").then(r =>
openDesktopLinkSupported = r
)

const serverOrigin = startUrl.url.origin;
const relocateListener = (event: MessageEvent) => {
if (event.origin === serverOrigin && event.data.type == 'relocate' && event.data.url) {
Expand All @@ -36,6 +43,7 @@ export function load({ gitpodService }: {
frame: HTMLIFrameElement
sessionId: Promise<string>
setState: (state: object) => void
openDesktopLink: (link: string) => void
}> {
return new Promise(resolve => {
const frame = document.createElement('iframe');
Expand All @@ -56,7 +64,27 @@ export function load({ gitpodService }: {
const setState = (state: object) => {
frameWindow.postMessage({ type: 'setState', state }, serverOrigin);
}
resolve({ frame, sessionId, setState });
const openDesktopLink = (link: string) => {
if (openDesktopLinkSupported) {
frameWindow.postMessage({ type: '$openDesktopLink', link }, serverOrigin);
} else {
let redirect = false;
try {
const desktopLink = new URL(link);
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 = link;
} else {
window.open(link, "_blank", "noopener");
}
}
}
resolve({ frame, sessionId, setState, openDesktopLink });
};
});
}