'use client' import '../Installs.css' import { useEffect } from 'react' import { useGlobal } from '@/providers/GlobalProvider' import { useSearchParams } from 'next/navigation' import { platform } from '@tauri-apps/plugin-os' import { faWarning } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { ask } from '@tauri-apps/plugin-dialog' import { BaseDirectory, exists } from '@tauri-apps/plugin-fs' import { WebviewWindow } from '@tauri-apps/api/webviewWindow' export default function Installs () { const { versionsList, serverVersionList, showPopup, setShowPopup, setPopupMode, setFadeOut, setSelectedVersionList, setManagingVersion, setSelectedGame, category, setCategory, downloadVersions, downloadProgress, linuxUseWine, customDataLocation, needsRevisionUpdate, launchGame, developerMode, theme, accountSession, accountId, accountName, version } = useGlobal() const params = useSearchParams() const id = Number(params.get('id') || 0) const game = serverVersionList?.games.find(g => g.id === id) useEffect(() => { if (!showPopup) return setSelectedVersionList([]) }, [setSelectedVersionList, showPopup]) if (!id || !game) return null const filteredVersions = Object.keys(versionsList).filter(v => { const info = serverVersionList?.versions.find(vf => vf.id == v) if (!info) return false if (platform() == 'linux' && info.wine && !linuxUseWine) return false return ( info.game === id && (category == -1 ? info.category == -1 : info.category == category) ) }) return (

{game.name} Installs

{game.id == 1 && ( <> )} {game.id == 9 && category == -1 && ( )} {game.id == 11 && category == -1 && ( )} {category != -1 && ( )}
{category == -1 && Object.entries(game.categoryNames) .filter(([key]) => { const count = Object.keys(versionsList).filter(v => { const info = serverVersionList?.versions.find( vf => vf.id == v ) if (!info) return false if (platform() == 'linux' && info.wine && !linuxUseWine) return false return info.game === id && info.category === Number(key) }).length return count >= 1 }) .sort(([a], [b]) => Number(b) - Number(a)) .map(([key, value]) => { return (
setCategory(Number(key))} >
{developerMode && (

{key}

)}

{value}

e.stopPropagation()} >

{(() => { const count = Object.keys(versionsList).filter(v => { const info = serverVersionList?.versions.find( vf => vf.id == v ) if (!info) return false if ( platform() == 'linux' && info.wine && !linuxUseWine ) return false return ( info.game === id && info.category == Number(key) ) }).length ?? 0 return `${count} install${count === 1 ? '' : 's'}` })()}

) })} {filteredVersions.length === 0 && (category !== -1 || Object.keys(versionsList).filter(v => { const info = serverVersionList?.versions.find(vf => vf.id == v) if (!info) return false if (platform() == 'linux' && info.wine && !linuxUseWine) return false return info.game === id }).length === 0) && (

No versions installed

)} {filteredVersions .sort((a, b) => { const infoA = serverVersionList?.versions.find(vf => vf.id == a) const infoB = serverVersionList?.versions.find(vf => vf.id == b) if (!infoA || !infoB) return 0 return infoB.place - infoA.place }) .map(v => { const versionInfo = serverVersionList?.versions.find( vf => vf.id == v ) if (!versionInfo) return return (
await launchGame(versionInfo)} onContextMenu={e => { e.preventDefault() setManagingVersion(v) setPopupMode(2) setShowPopup(true) setFadeOut(false) }} >
{developerMode && (

{versionInfo.id}

)}

{versionInfo.displayName}

Installed{' '} {new Intl.DateTimeFormat(undefined).format( versionsList[v] )}

{platform() == 'linux' && versionInfo.wine && !needsRevisionUpdate(versionInfo.lastRevision, v) && (

Uses wine

)} {needsRevisionUpdate(versionInfo.lastRevision, v) && (

Needs revision update!

)}
{versionInfo.modSupportDownload && ( )}
) })}
) }