mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
* 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 * Guard download bridge calls for older desktop apps Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kat47mueTm3CUZSbDVfBas * Change protocol in dev for easier testing * Use standard buttons stacked below the file name in download toast --------- Co-authored-by: Claude <noreply@anthropic.com>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { useRef, useEffect } from "react";
|
|
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";
|
|
|
|
export default function DesktopEventHandler() {
|
|
useDesktopTitlebar();
|
|
const { t } = useTranslation();
|
|
const history = useHistory();
|
|
const { dialogs } = useStores();
|
|
const hasDisabledUpdateMessage = useRef(false);
|
|
|
|
useEffect(() => {
|
|
Desktop.bridge?.redirect((path: string, replace: boolean) => {
|
|
if (replace) {
|
|
history.replace(path);
|
|
} else {
|
|
history.push(path);
|
|
}
|
|
});
|
|
|
|
Desktop.bridge?.updateDownloaded(() => {
|
|
if (hasDisabledUpdateMessage.current) {
|
|
return;
|
|
}
|
|
|
|
hasDisabledUpdateMessage.current = true;
|
|
toast.message("An update is ready to install.", {
|
|
duration: Infinity,
|
|
dismissible: true,
|
|
action: {
|
|
label: t("Install now"),
|
|
onClick: () => {
|
|
void Desktop.bridge?.restartAndInstall();
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
Desktop.bridge?.onDownloadComplete?.(showDownloadToast);
|
|
|
|
Desktop.bridge?.focus(() => {
|
|
window.document.body.classList.remove("backgrounded");
|
|
});
|
|
|
|
Desktop.bridge?.blur(() => {
|
|
window.document.body.classList.add("backgrounded");
|
|
});
|
|
|
|
Desktop.bridge?.openKeyboardShortcuts(() => {
|
|
dialogs.openGuide({
|
|
title: t("Keyboard shortcuts"),
|
|
content: <KeyboardShortcuts />,
|
|
});
|
|
});
|
|
}, [t, history, dialogs]);
|
|
|
|
return null;
|
|
}
|