'use client' import { useGlobal } from '@/providers/GlobalProvider' import { verifySignature } from '@/lib/util' import { Mod } from '@/types/Mod' import { faArrowUpRightFromSquare, faClock, faCodeBranch, faDownload, faGlobe, faPeopleGroup, faRefresh, faTrash } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { message } from '@tauri-apps/plugin-dialog' import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs' import { fetch } from '@tauri-apps/plugin-http' import { arch, platform } from '@tauri-apps/plugin-os' import { useEffect, useState } from 'react' export default function ModDownloadsPopup () { const { modsList, serverVersionList, managingVersion, showModInfo, setShowModInfo, downloadVersions, downloadProgress, versions } = useGlobal() const [mods, setMods] = useState(0) const [tab, setTab] = useState(0) useEffect(() => { if (!managingVersion) return ;(async () => { const response = await fetch( `https://games.lncvrt.xyz/api/launcher/mods?platform=${platform()}&arch=${arch()}&version=${managingVersion}` ) const signature = response.headers.get('x-signature') ?? '' const data = await response.json() if (await verifySignature(JSON.stringify(data), signature)) { setMods(data as Mod[]) } else { setMods(1) } })() }, [managingVersion]) if (!managingVersion || !serverVersionList) return <> const versionInfo = serverVersionList.versions.find( v => v.id == managingVersion ) return ( <>

{!showModInfo ? versionInfo?.displayName + ' Mod Manager' : showModInfo.name + ' by ' + showModInfo.creators[0] + (showModInfo.creators.length > 1 ? ' + ' + (showModInfo.creators.length - 1) + ' more' : '')}

{typeof mods != 'number' && !showModInfo ? (
) : null}
{typeof mods == 'number' || (!showModInfo && mods.filter(v => tab == 0 ? Object.keys(modsList).includes( String(versionInfo?.game + '-' + v.id) ) : !Object.keys(modsList).includes( String(versionInfo?.game + '-' + v.id) ) ).length == 0) ? (

{typeof mods == 'number' ? mods == 0 ? 'Loading' : 'Failed to load mods' : tab == 0 ? 'No mods installed' : 'No mods available to download'}

) : !showModInfo ? (
{mods .filter(v => tab == 0 ? Object.keys(modsList).includes( String(versionInfo?.game + '-' + v.id) ) : !Object.keys(modsList).includes( String(versionInfo?.game + '-' + v.id) ) ) .map(v => { const localVersion = tab == 0 ? Object.keys( modsList[versionInfo?.game + '-' + v.id] ?? {} )[0] : null return (

{v.name}{' '} v{tab == 0 ? localVersion : v.latestVersion}

Made by {v.creators[0]} {v.creators.length > 1 ? ' + ' + (v.creators.length - 1) + ' more' : null}

) })}
) : (

{' '} Downloads {showModInfo.downloads.toLocaleString()}

Released{' '} {new Intl.DateTimeFormat(undefined).format( showModInfo.released * 1000 )}

Updated{' '} {new Intl.DateTimeFormat(undefined).format( showModInfo.updated * 1000 )}

Version{' '} {showModInfo.latestVersion}

{showModInfo.description ? atob(showModInfo.description) : '(No description added)'}
{Object.keys(modsList).includes( String(versionInfo?.game + '-' + showModInfo.id) ) ? ( ) : ( )}
)}
) }