Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
Replace native cancel-download confirm with shadcn AlertDialog
Anmol Kapil6c2a55e51ef9
diff --git a/src/renderer/src/components/ui/alert-dialog.tsx b/src/renderer/src/components/ui/alert-dialog.tsxnew file mode 100644index 0000000..360ed4d--- /dev/null+++ b/src/renderer/src/components/ui/alert-dialog.tsx@@ -0,0 +1,137 @@+import * as React from 'react'+import { AlertDialog as AlertDialogPrimitive } from '@base-ui/react/alert-dialog'+import { cn } from 'cn'+import { buttonVariants } from './button'++function AlertDialog({ ...props }: AlertDialogPrimitive.Root.Props): React.JSX.Element {+ return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />+}++function AlertDialogTrigger({ ...props }: AlertDialogPrimitive.Trigger.Props): React.JSX.Element {+ return <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />+}++function AlertDialogBackdrop({+ className,+ ...props+}: AlertDialogPrimitive.Backdrop.Props): React.JSX.Element {+ return (+ <AlertDialogPrimitive.Backdrop+ data-slot="alert-dialog-backdrop"+ className={cn(+ 'fixed inset-0 z-50 bg-black/40 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 dark:bg-black/60',+ className+ )}+ {...props}+ />+ )+}++function AlertDialogContent({+ className,+ ...props+}: AlertDialogPrimitive.Popup.Props): React.JSX.Element {+ return (+ <AlertDialogPrimitive.Portal>+ <AlertDialogBackdrop />+ <AlertDialogPrimitive.Popup+ data-slot="alert-dialog-content"+ className={cn(+ 'fixed top-1/2 left-1/2 z-50 w-full max-w-sm -translate-x-1/2 -translate-y-1/2 rounded-lg bg-popover p-4 text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[ending-style]:scale-95 data-[ending-style]:opacity-0 data-[starting-style]:scale-95 data-[starting-style]:opacity-0',+ className+ )}+ {...props}+ />+ </AlertDialogPrimitive.Portal>+ )+}++function AlertDialogHeader({+ className,+ ...props+}: React.ComponentProps<'div'>): React.JSX.Element {+ return (+ <div+ data-slot="alert-dialog-header"+ className={cn('flex flex-col gap-1.5', className)}+ {...props}+ />+ )+}++function AlertDialogFooter({+ className,+ ...props+}: React.ComponentProps<'div'>): React.JSX.Element {+ return (+ <div+ data-slot="alert-dialog-footer"+ className={cn('mt-3 flex justify-end gap-2', className)}+ {...props}+ />+ )+}++function AlertDialogTitle({+ className,+ ...props+}: AlertDialogPrimitive.Title.Props): React.JSX.Element {+ return (+ <AlertDialogPrimitive.Title+ data-slot="alert-dialog-title"+ className={cn('text-sm font-semibold', className)}+ {...props}+ />+ )+}++function AlertDialogDescription({+ className,+ ...props+}: AlertDialogPrimitive.Description.Props): React.JSX.Element {+ return (+ <AlertDialogPrimitive.Description+ data-slot="alert-dialog-description"+ className={cn('text-sm text-muted-foreground', className)}+ {...props}+ />+ )+}++function AlertDialogAction({+ className,+ ...props+}: AlertDialogPrimitive.Close.Props): React.JSX.Element {+ return (+ <AlertDialogPrimitive.Close+ data-slot="alert-dialog-action"+ className={cn(buttonVariants({ size: 'sm' }), className)}+ {...props}+ />+ )+}++function AlertDialogCancel({+ className,+ ...props+}: AlertDialogPrimitive.Close.Props): React.JSX.Element {+ return (+ <AlertDialogPrimitive.Close+ data-slot="alert-dialog-cancel"+ className={cn(buttonVariants({ variant: 'secondary', size: 'sm' }), className)}+ {...props}+ />+ )+}++export {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+ AlertDialogTrigger+}diff --git a/src/renderer/src/screens/DownloadingScreen.tsx b/src/renderer/src/screens/DownloadingScreen.tsxindex 452c60b..6912b8b 100644--- a/src/renderer/src/screens/DownloadingScreen.tsx+++ b/src/renderer/src/screens/DownloadingScreen.tsx@@ -7,7 +7,18 @@ import { CyclableChip } from '../components/CyclableChip'import { NetworkRow } from '../components/NetworkRow'import { ThroughputChart } from '../components/ThroughputChart'import { TruncatedText } from '../components/TruncatedText'-import { Button } from '../components/ui/button'+import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+ AlertDialogTrigger+} from '../components/ui/alert-dialog'+import { Button, buttonVariants } from '../components/ui/button'import { Tooltip, TooltipContent, TooltipTrigger } from '../components/ui/tooltip'import { useNetworkPolling } from '../hooks/useNetworkPolling'import { useNetworkVisuals } from '../hooks/useNetworkVisuals'@@ -158,10 +169,8 @@ export function DownloadingScreen({ download }: { download: DownloadState }): Revoid window.plexo.pauseDownload(download.id)}}- const handleCancel = (): void => {- if (window.confirm('Cancel this download? Progress will be lost.')) {- void window.plexo.cancelDownload(download.id)- }+ const handleConfirmCancel = (): void => {+ void window.plexo.cancelDownload(download.id)}const effectiveSpeed = isPaused ? 0 : download.speedBytesPerSec@@ -430,16 +439,32 @@ export function DownloadingScreen({ download }: { download: DownloadState }): Re{pauseResumeLabel}</Button></WhileAssembling>- <WhileAssembling active={isAssembling} text="Can’t cancel while assembling the file">- <Button- type="button"- variant="destructive"- onClick={handleCancel}- disabled={isAssembling}- >- Cancel- </Button>- </WhileAssembling>+ <AlertDialog>+ <WhileAssembling active={isAssembling} text="Can’t cancel while assembling the file">+ <AlertDialogTrigger+ render={+ <Button type="button" variant="destructive" disabled={isAssembling}>+ Cancel+ </Button>+ }+ />+ </WhileAssembling>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Cancel this download?</AlertDialogTitle>+ <AlertDialogDescription>Progress will be lost.</AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel>Keep downloading</AlertDialogCancel>+ <AlertDialogAction+ className={buttonVariants({ variant: 'destructive', size: 'sm' })}+ onClick={handleConfirmCancel}+ >+ Cancel download+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog></div></div>)