diff --git a/components/supervisor/frontend/src/ide/heart-beat.ts b/components/supervisor/frontend/src/ide/heart-beat.ts index 5d4ba9febc4f84..54c2be8e59903e 100644 --- a/components/supervisor/frontend/src/ide/heart-beat.ts +++ b/components/supervisor/frontend/src/ide/heart-beat.ts @@ -19,7 +19,7 @@ export const track = (w: Window) => { } let pageCloseCompatibile: boolean = false - +// TODO(ak) remove isSaaSServerGreaterThan("main.4124").then((r) => { pageCloseCompatibile = r }) diff --git a/components/supervisor/frontend/src/index.ts b/components/supervisor/frontend/src/index.ts index c7794fd3a70812..dded7e9b78e748 100644 --- a/components/supervisor/frontend/src/index.ts +++ b/components/supervisor/frontend/src/index.ts @@ -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; } diff --git a/components/supervisor/frontend/src/shared/loading-frame.ts b/components/supervisor/frontend/src/shared/loading-frame.ts index 4de953253e9f71..f4aca469cb7612 100644 --- a/components/supervisor/frontend/src/shared/loading-frame.ts +++ b/components/supervisor/frontend/src/shared/loading-frame.ts @@ -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) { @@ -36,6 +43,7 @@ export function load({ gitpodService }: { frame: HTMLIFrameElement sessionId: Promise setState: (state: object) => void + openDesktopLink: (link: string) => void }> { return new Promise(resolve => { const frame = document.createElement('iframe'); @@ -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 }); }; }); }