Skip to content
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
14 changes: 14 additions & 0 deletions site/src/modules/resources/AppLink/AppLink.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
MockWorkspaceApp,
MockWorkspaceProxies,
} from "testHelpers/entities";
import { withGlobalSnackbar } from "testHelpers/storybook";
import { AppLink } from "./AppLink";

const meta: Meta<typeof AppLink> = {
Expand Down Expand Up @@ -72,6 +73,19 @@ export const ExternalApp: Story = {
},
};

export const ExternalAppNotInstalled: Story = {
decorators: [withGlobalSnackbar],
args: {
workspace: MockWorkspace,
app: {
...MockWorkspaceApp,
external: true,
url: "foobar-foobaz://open-me",
},
agent: MockWorkspaceAgent,
},
};

export const SharingLevelOwner: Story = {
args: {
workspace: MockWorkspace,
Expand Down
16 changes: 16 additions & 0 deletions site/src/modules/resources/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import Link from "@mui/material/Link";
import Tooltip from "@mui/material/Tooltip";
import { API } from "api/api";
import type * as TypesGen from "api/typesGenerated";
import { displayError } from "components/GlobalSnackbar/utils";
import { useProxy } from "contexts/ProxyContext";
import { useEffect } from "react";
import { type FC, type MouseEvent, useState } from "react";
import { createAppLinkHref } from "utils/apps";
import { generateRandomString } from "utils/random";
Expand Down Expand Up @@ -152,6 +154,20 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
url = href.replaceAll(magicTokenString, key.key);
setFetchingSessionToken(false);
}

// When browser recognizes the protocol and is able to navigate to the app,
// it will blur away, and will stop the timer. Otherwise,
// an error message will be displayed.
const openAppExternallyFailedTimeout = 500;
const openAppExternallyFailed = setTimeout(() => {
displayError(
`${app.display_name !== "" ? app.display_name : app.slug} must be installed first.`,
);
}, openAppExternallyFailedTimeout);
window.addEventListener("blur", () => {
clearTimeout(openAppExternallyFailed);
});

window.location.href = url;
return;
}
Expand Down
Loading