Skip to content

Commit 0a08418

Browse files
committed
[dashboard] allow to open desktop links on app domain
1 parent 6a52dbf commit 0a08418

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

components/dashboard/src/start/StartWorkspace.tsx

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
124124
this.setState({ desktopIde: { link: event.data.state.desktopIdeLink, label, clientID } });
125125
}
126126
}
127+
if (
128+
event.data.type === "$openDekstopLink" &&
129+
"link" in event.data &&
130+
typeof event.data["link"] === "string"
131+
) {
132+
this.openDekstopLink(event.data["link"] as string);
133+
}
127134
};
128135
window.addEventListener("message", setStateEventListener, false);
129136
this.toDispose.push({
@@ -390,6 +397,23 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
390397
}
391398
}
392399

400+
private openDekstopLink(link: string) {
401+
let redirect = false;
402+
try {
403+
const desktopLink = new URL(link);
404+
redirect = desktopLink.protocol !== "http:" && desktopLink.protocol !== "https:";
405+
} catch (e) {
406+
console.error("invalid desktop link:", e);
407+
}
408+
// redirect only if points to desktop application
409+
// don't navigate browser to another page
410+
if (redirect) {
411+
window.location.href = link;
412+
} else {
413+
window.open(link, "_blank", "noopener");
414+
}
415+
}
416+
393417
render() {
394418
const { error } = this.state;
395419
const isPrebuild = this.state.workspace?.type === "prebuild";
@@ -522,23 +546,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
522546
<Arrow direction={"down"} />
523547
</button>
524548
</ContextMenu>
525-
<button
526-
onClick={() => {
527-
let redirect = false;
528-
try {
529-
const desktopLink = new URL(openLink);
530-
redirect =
531-
desktopLink.protocol !== "http:" && desktopLink.protocol !== "https:";
532-
} catch {}
533-
if (redirect) {
534-
window.location.href = openLink;
535-
} else {
536-
window.open(openLink, "_blank", "noopener");
537-
}
538-
}}
539-
>
540-
{openLinkLabel}
541-
</button>
549+
<button onClick={() => this.openDekstopLink(openLink)}>{openLinkLabel}</button>
542550
</div>
543551
{!useLatest && (
544552
<Alert type="info" className="mt-4 w-96">

0 commit comments

Comments
 (0)