import { config } from "@/config"; import { Link, useLocation } from "react-router-dom"; import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from "@/components/ui/sidebar"; import { CircleArrowUp, Download, Settings, SquarePlay, } from "lucide-react"; import { isActive as isActiveSidebarItem } from "@/utils"; import { RoutesObj } from "@/types/route"; import { useDownloadStatesStore, useSettingsPageStatesStore } from "@/services/store"; import { Badge } from "@/components/ui/badge"; import { useEffect, useState } from "react"; import { NeoDlpLogo } from "@/components/icons/neodlp"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"; import { Progress } from "@/components/ui/progress"; import useAppUpdater from "@/helpers/use-app-updater"; import { platform } from "@tauri-apps/plugin-os"; import * as fs from "@tauri-apps/plugin-fs"; export function AppSidebar() { const downloadStates = useDownloadStatesStore(state => state.downloadStates); const ongoingDownloads = downloadStates.filter(state => ['starting', 'downloading', 'queued'].includes(state.download_status) ); const appVersion = useSettingsPageStatesStore(state => state.appVersion); const isFetchingAppVersion = useSettingsPageStatesStore(state => state.isFetchingAppVersion); const appUpdate = useSettingsPageStatesStore(state => state.appUpdate); const isUpdatingApp = useSettingsPageStatesStore(state => state.isUpdatingApp); const appUpdateDownloadProgress = useSettingsPageStatesStore(state => state.appUpdateDownloadProgress); const currentPlatform = platform(); const location = useLocation(); const { open } = useSidebar(); const { downloadAndInstallAppUpdate } = useAppUpdater(); const [showBadge, setShowBadge] = useState(false); const [showUpdateCard, setShowUpdateCard] = useState(false); const [isNativeLinuxApp, setIsNativeLinuxApp] = useState(false); const topItems: Array = [ { title: "Downloader", url: "/", icon: Download, }, { title: "Library", url: "/library", icon: SquarePlay, } ]; const bottomItems: Array = [ { title: "Settings", url: "/settings", icon: Settings, } ]; useEffect(() => { let timeout: NodeJS.Timeout; if (open) { timeout = setTimeout(() => { setShowBadge(true); setShowUpdateCard(true); }, 300); } else { setShowBadge(false); setShowUpdateCard(false); } return () => { clearTimeout(timeout); }; }, [open]); useEffect(() => { (async () => { if (currentPlatform === 'linux') { const neoDlpExists = await fs.exists('/usr/bin/neodlp'); setIsNativeLinuxApp(neoDlpExists); } })(); }, [currentPlatform]); return (
Neo Downloader Plus {isFetchingAppVersion ? 'Loading...' : `v${appVersion}`}
{/* */} {/* Tools */} {topItems.map((item) => ( {!open ? ( {item.title} {item.title === "Library" && ongoingDownloads.length > 0 && showBadge && ( {ongoingDownloads.length} )}

{item.title}

) : ( {item.title} {item.title === "Library" && ongoingDownloads.length > 0 && showBadge && ( {ongoingDownloads.length} )} )}
))}
{appUpdate && !open && (

Update Available

(Expand sidebar to view update)

)} {appUpdate && open && showUpdateCard && ( Update Available (v{appUpdate?.version || '0.0.0'}) A newer version of {config.appName} is available. Please update to the latest version for the best experience. ✨ Read Changelog {isNativeLinuxApp ? ( ) : ( Updating {config.appName} Updating {config.appName} to v{appUpdate?.version || '0.0.0'}, Please be patience! Do not quit the app untill the update finishes. The app will auto re-launch to complete the update, Please allow all system prompts from {config.appName} if asked. Downloading update... {appUpdateDownloadProgress}% )} )} {bottomItems.map((item) => ( {!open ? ( {item.title}

{item.title}

) : ( {item.title} )}
))}
); }