add download context menu action for browser

This commit is contained in:
jeffvli
2026-01-31 00:41:48 -08:00
parent 131e1ec11d
commit 72ab1dc8a0
@@ -5,7 +5,6 @@ import { useTranslation } from 'react-i18next';
import { api } from '/@/renderer/api'; import { api } from '/@/renderer/api';
import { useCurrentServer } from '/@/renderer/store'; import { useCurrentServer } from '/@/renderer/store';
import { ContextMenu } from '/@/shared/components/context-menu/context-menu'; import { ContextMenu } from '/@/shared/components/context-menu/context-menu';
import { toast } from '/@/shared/components/toast/toast';
interface DownloadActionProps { interface DownloadActionProps {
ids: string[]; ids: string[];
@@ -18,10 +17,6 @@ export const DownloadAction = ({ ids }: DownloadActionProps) => {
const server = useCurrentServer(); const server = useCurrentServer();
const onSelect = useCallback(async () => { const onSelect = useCallback(async () => {
if (!utils) {
return;
}
try { try {
for (const id of ids) { for (const id of ids) {
const downloadUrl = api.controller.getDownloadUrl({ const downloadUrl = api.controller.getDownloadUrl({
@@ -29,23 +24,16 @@ export const DownloadAction = ({ ids }: DownloadActionProps) => {
query: { id }, query: { id },
}); });
utils.download(downloadUrl); if (isElectron()) {
utils?.download(downloadUrl);
} else {
window.open(downloadUrl, '_blank');
}
} }
toast.success({
message: t('action.downloadStarted', {
count: ids.length,
postProcess: 'sentenceCase',
}),
});
} catch (error) { } catch (error) {
console.error('Failed to download items:', error); console.error('Failed to download items:', error);
} }
}, [ids, server, t]); }, [ids, server]);
if (!utils) {
return null;
}
return ( return (
<ContextMenu.Item disabled={ids.length > 1} leftIcon="download" onSelect={onSelect}> <ContextMenu.Item disabled={ids.length > 1} leftIcon="download" onSelect={onSelect}>