Skip to content

Commit

Permalink
Redirect web page when instance changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh authored and Simon Emms committed Apr 11, 2022
1 parent b66aef4 commit 9e750f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
49 changes: 6 additions & 43 deletions components/dashboard/src/start/StartWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,

// Redirect to workspaceURL if we are not yet running in an iframe.
// It happens this late if we were waiting for a docker build.
if (!this.props.runsInIFrame && workspaceInstance.ideUrl && !this.props.dontAutostart) {
if (
!this.props.runsInIFrame &&
workspaceInstance.ideUrl &&
(!this.props.dontAutostart || workspaceInstance.status.phase === "running")
) {
this.redirectTo(workspaceInstance.ideUrl);
return;
}
Expand Down Expand Up @@ -431,48 +435,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
}
if (!this.state.desktopIde) {
phase = StartPhase.Running;

if (this.props.dontAutostart) {
// hide the progress bar, as we're already running
phase = undefined;
title = "Running";

// in case we dontAutostart the IDE we have to provide controls to do so
statusMessage = (
<div>
<div className="flex space-x-3 items-center text-left rounded-xl m-auto px-4 h-16 w-72 mt-4 mb-2 bg-gray-100 dark:bg-gray-800">
<div className="rounded-full w-3 h-3 text-sm bg-green-500">&nbsp;</div>
<div>
<p className="text-gray-700 dark:text-gray-200 font-semibold w-56 truncate">
{this.state.workspaceInstance.workspaceId}
</p>
<a target="_parent" href={contextURL}>
<p className="w-56 truncate hover:text-blue-600 dark:hover:text-blue-400">
{contextURL}
</p>
</a>
</div>
</div>
<div className="mt-10 justify-center flex space-x-2">
<a target="_parent" href={gitpodHostUrl.asDashboard().toString()}>
<button className="secondary">Go to Dashboard</button>
</a>
<a
target="_parent"
href={
gitpodHostUrl
.asStart(this.props.workspaceId)
.toString() /** move over 'start' here to fetch fresh credentials in case this is an older tab */
}
>
<button>Open Workspace</button>
</a>
</div>
</div>
);
} else {
statusMessage = <p className="text-base text-gray-400">Opening Workspace …</p>;
}
statusMessage = <p className="text-base text-gray-400">Opening Workspace …</p>;
} else {
phase = StartPhase.IdeReady;
const openLink = this.state.desktopIde.link;
Expand Down
10 changes: 10 additions & 0 deletions components/supervisor/frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ const toStop = new DisposableCollection();
//#region current-frame
let current: HTMLElement = loading.frame;
let desktopRedirected = false;
let currentInstanceId = "";
const nextFrame = () => {
const instance = gitpodServiceClient.info.latestInstance;
if (instance) {
// refresh web page when instanceId changed
if (currentInstanceId !== "") {
if (instance.id !== currentInstanceId && instance.ideUrl !== "") {
currentInstanceId = instance.id;
window.location.href = instance.ideUrl;
}
} else {
currentInstanceId = instance.id;
}
if (instance.status.phase === 'running') {
if (!hideDesktopIde) {
if (isDesktopIde == undefined) {
Expand Down

0 comments on commit 9e750f3

Please sign in to comment.