'use client' import { useEffect, useState } from 'react' import '../Installs.css' import { invoke } from '@tauri-apps/api/core' import { useGlobal } from '../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' export default function Installs () { const { showPopup, setShowPopup, setPopupMode, setFadeOut, setSelectedVersionList, downloadedVersionsConfig, normalConfig, setManagingVersion, getVersionInfo, getGameInfo, setSelectedGame, serverVersionList } = useGlobal() const params = useSearchParams() const id = Number(params.get('id') || 0) const game = serverVersionList?.games.find(g => g.id === id) const [category, setCategory] = useState(-1) const [lastId, setLastId] = useState(id) useEffect(() => { if (!showPopup) return setSelectedVersionList([]) }, [normalConfig, setSelectedVersionList, showPopup]) if (!id || !game) return

Invalid game

if (lastId !== id) { setLastId(id) setCategory(-1) } return (

Installs

{category == -1 && Object.entries(game.categoryNames) .sort(([a], [b]) => Number(b) - Number(a)) .filter(([key]) => { const count = Object.keys( downloadedVersionsConfig?.list ?? {} ).filter(v => { const info = getVersionInfo(v) if (!info) return false if ( platform() === 'linux' && info.wine && !normalConfig?.settings.useWineOnUnixWhenNeeded ) return false return info.game === id && info.category === Number(key) }).length return count >= 1 }) .map(([key, value]) => { return (
{ if (normalConfig?.settings.useLegacyInteractButtons) return setCategory(Number(key)) }} >

{value}

e.stopPropagation()} >

{(() => { const count = Object.keys( downloadedVersionsConfig?.list ?? [] ).filter(v => { const info = getVersionInfo(v) if (!info) return false if ( platform() === 'linux' && info.wine && !normalConfig?.settings .useWineOnUnixWhenNeeded ) return false return ( info.game === id && info.category == Number(key) ) }).length ?? 0 return `${count} install${count === 1 ? '' : 's'}` })()}

) })} {Object.keys(downloadedVersionsConfig?.list ?? []).filter(v => { const info = getVersionInfo(v) if (!info) return false return info.game === id }).length != 0 ? ( Object.keys(downloadedVersionsConfig?.list ?? []) .sort((a, b) => { const infoA = getVersionInfo(a) const infoB = getVersionInfo(b) if (!infoA || !infoB) return -1 return infoB.place - infoA.place }) .filter(v => { const info = getVersionInfo(v) if (!info) return false if ( platform() === 'linux' && info.wine && !normalConfig?.settings.useWineOnUnixWhenNeeded ) return false return ( info.game === id && (category == -1 ? info.category == -1 : info.category == category) ) }) .map(entry => (
{ if (normalConfig?.settings.useLegacyInteractButtons) return const verInfo = getVersionInfo(entry) if (verInfo == undefined) return const gameInfo = getGameInfo(verInfo.game) if (gameInfo == undefined) return invoke('launch_game', { name: verInfo.id, executable: verInfo.executable, displayName: verInfo.displayName, useWine: !!( platform() === 'linux' && verInfo.wine && normalConfig?.settings.useWineOnUnixWhenNeeded ), wineCommand: normalConfig?.settings.wineOnUnixCommand }) }} onContextMenu={e => { e.preventDefault() if (normalConfig?.settings.useLegacyInteractButtons) return setManagingVersion(entry) setPopupMode(2) setShowPopup(true) setFadeOut(false) }} >

{getVersionInfo(entry)?.displayName}

e.stopPropagation()} >

Installed{' '} {new Intl.DateTimeFormat(undefined).format( downloadedVersionsConfig?.list[entry] )}

)) ) : (

No versions installed

)}
) }