Show toast with actions when a file download completes

In the desktop app a toast is now displayed when a file finishes
downloading, with the option to open the file or reveal it in the file
manager of the operating system.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kat47mueTm3CUZSbDVfBas
This commit is contained in:
Claude committed 2026-09-13 01:52:21 +00:00
1 parent ab40dda966
commit bb77656a34
3 files changed
+113

No files matched your search

+3
View File
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { toast } from "sonner";
import KeyboardShortcuts from "~/scenes/KeyboardShortcuts";
import { showDownloadToast } from "~/components/DownloadToast";
import { useDesktopTitlebar } from "~/hooks/useDesktopTitlebar";
import useStores from "~/hooks/useStores";
import Desktop from "~/utils/Desktop";
@@ -41,6 +42,8 @@ export default function DesktopEventHandler() {
});
});
Desktop.bridge?.onDownloadComplete(showDownloadToast);
Desktop.bridge?.focus(() => {
window.document.body.classList.remove("backgrounded");
});
+89
View File
@@ -0,0 +1,89 @@
import { t } from "i18next";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
import styled from "styled-components";
import { s } from "@shared/styles";
import Flex from "~/components/Flex";
import Desktop from "~/utils/Desktop";
type DownloadedFile = {
/** The user facing name of the downloaded file. */
fileName: string;
/** The absolute path the file was saved to. */
filePath: string;
};
/**
* Displays a toast notifying that a file finished downloading, with actions to
* open the file or reveal it in the file manager. Desktop app only.
*
* @param file the name and path of the downloaded file.
*/
export function showDownloadToast(file: DownloadedFile) {
const toastId = `download-${file.filePath}`;
toast.success(t("Download complete"), {
id: toastId,
description: file.fileName,
action: <DownloadToastActions file={file} toastId={toastId} />,
});
}
function DownloadToastActions({
file,
toastId,
}: {
file: DownloadedFile;
toastId: string;
}) {
const { t } = useTranslation();
const handleOpen = useCallback(() => {
toast.dismiss(toastId);
void Desktop.bridge?.openDownload(file.filePath);
}, [file.filePath, toastId]);
const handleShowInFolder = useCallback(() => {
toast.dismiss(toastId);
void Desktop.bridge?.showDownloadInFolder(file.filePath);
}, [file.filePath, toastId]);
// The name given to the file manager differs by operating system.
const showInFolderLabel = Desktop.isMacApp()
? t("Show in Finder")
: Desktop.isWindowsApp()
? t("Show in Explorer")
: t("Show in folder");
return (
<Flex gap={4} shrink={false}>
<Action type="button" onClick={handleOpen}>
{t("Open")}
</Action>
<Action type="button" onClick={handleShowInFolder}>
{showInFolderLabel}
</Action>
</Flex>
);
}
const Action = styled.button`
height: 24px;
padding: 0 8px;
flex-shrink: 0;
border: 1px solid ${s("divider")};
border-radius: 4px;
background: transparent;
color: ${s("toastText")};
font-family: inherit;
font-size: 12px;
font-weight: 500;
line-height: 1;
white-space: nowrap;
cursor: var(--pointer);
&:hover {
background: ${s("sidebarActiveBackground")};
}
`;
+21
View File
@@ -142,6 +142,27 @@ declare global {
*/
onReplaceInPage: (callback: () => void) => void;
/**
* Registers a callback to be called when a file download completes. The
* callback receives the name and saved path of the file, which can be
* passed back to `openDownload` or `showDownloadInFolder`.
*/
onDownloadComplete: (
callback: (file: { fileName: string; filePath: string }) => void
) => void;
/**
* Opens a downloaded file with the default application for its type.
* Resolves with whether the file was opened.
*/
openDownload: (filePath: string) => Promise<boolean>;
/**
* Reveals a downloaded file in the file manager of the operating system.
* Resolves with whether the file was revealed.
*/
showDownloadInFolder: (filePath: string) => Promise<boolean>;
/**
* Get whether the app is configured to launch at login.
*/