WIP home page & rework some stuff

This commit is contained in:
Lncvrt committed 2026-07-29 06:26:52 -07:00
1 parent 28b88f4033
commit 5ce8aa76ab
6 files changed
+154 -99

No files matched your search

+35 -30
View File
@@ -384,6 +384,39 @@ export default function RootLayout ({
)
}
const uninstallVersion = async (
version: string,
updateList: boolean = true
) => {
if (updateList)
await versions?.set(
'list',
Object.fromEntries(
Object.entries(versionsList).filter(([k]) => k !== version)
)
)
if (
await exists(
(customDataLocation ? customDataLocation + '/' : null) +
'game/' +
version,
{
baseDir: customDataLocation ? undefined : BaseDirectory.AppLocalData
}
)
)
await remove(
(customDataLocation ? customDataLocation + '/' : null) +
'game/' +
version,
{
baseDir: customDataLocation ? undefined : BaseDirectory.AppLocalData,
recursive: true
}
)
}
const launchGame = async (versionInfo: GameVersion) => {
if (needsRevisionUpdate(versionInfo.lastRevision, versionInfo.id)) {
const answer = await ask(
@@ -409,36 +442,7 @@ export default function RootLayout ({
setFadeOut(false)
//uninstall
await versions?.set(
'list',
Object.fromEntries(
Object.entries(versionsList).filter(([k]) => k !== versionInfo.id)
)
)
if (
await exists(
customDataLocation
? customDataLocation + '/'
: null + 'game/' + versionInfo.id,
{
baseDir: customDataLocation
? undefined
: BaseDirectory.AppLocalData
}
)
)
await remove(
customDataLocation
? customDataLocation + '/'
: null + 'game/' + versionInfo.id,
{
baseDir: customDataLocation
? undefined
: BaseDirectory.AppLocalData,
recursive: true
}
)
await uninstallVersion(versionInfo.id)
//reinstall
setSelectedVersionList([versionInfo.id])
@@ -912,6 +916,7 @@ export default function RootLayout ({
managingGame,
setManagingGame,
needsRevisionUpdate,
uninstallVersion,
launchGame
}}
>
+95
View File
@@ -0,0 +1,95 @@
'use client'
import { useGlobal } from '@/providers/GlobalProvider'
import 'swiper/css'
import { Swiper, SwiperSlide } from 'swiper/react'
import { formatDistanceToNow } from 'date-fns'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faEllipsis, faPlay } from '@fortawesome/free-solid-svg-icons'
export default function HomePage () {
const {
launchesList,
serverVersionList,
accountName,
launchGame,
setManagingVersion,
setPopupMode,
setShowPopup,
setFadeOut
} = useGlobal()
const filteredLaunchesList = Object.fromEntries(
Object.entries(launchesList)
.flatMap(([gameId, launches]) => {
const entries = Object.entries(launches)
if (entries.length === 0) return []
const [version, timestamp] = entries.reduce((latest, current) =>
current[1] > latest[1] ? current : latest
)
return [[`${gameId}-${version}`, timestamp] as const]
})
.sort((a, b) => b[1] - a[1])
)
return (
<div className='mx-4 mt-4'>
<div className='flex flex-col gap-1 mb-4'>
<p className='text-3xl'>Home</p>
<p className='text-gray-300'>Welcome back, {accountName ?? 'User'}!</p>
</div>
<div>
<p className='text-2xl'>Jump back in</p>
{Object.entries(filteredLaunchesList).length == 0 ? (
<p className='text-gray-300'>You have no recently launched games</p>
) : (
<Swiper spaceBetween={16} slidesPerView={2}>
{Object.entries(filteredLaunchesList).map(([key, timestamp]) => {
const versionInfo = serverVersionList?.versions.find(
v => v.id == key.split('-').slice(1).join('-')
)
if (!versionInfo) return
return (
<SwiperSlide
key={key}
className='flex flex-col gap-2 bg-(--col1) border border-(--col3) rounded-lg px-3 py-2'
>
<p className='truncate text-2xl'>
{versionInfo?.displayName}
</p>
<p className='truncate text-gray-300'>
Last played:{' '}
{formatDistanceToNow(new Date(timestamp), {
addSuffix: true
})}
</p>
<div className='flex flex-row gap-2 my-1'>
<FontAwesomeIcon
icon={faPlay}
className='button btntheme1'
onClick={async () => await launchGame(versionInfo)}
/>
<FontAwesomeIcon
icon={faEllipsis}
className='button btntheme1'
onClick={() => {
setManagingVersion(versionInfo.id)
setPopupMode(2)
setShowPopup(true)
setFadeOut(false)
}}
/>
</div>
</SwiperSlide>
)
})}
</Swiper>
)}
</div>
</div>
)
}
+11 -65
View File
@@ -9,7 +9,6 @@ import { useGlobal } from '@/providers/GlobalProvider'
import { invoke } from '@tauri-apps/api/core'
import { useEffect, useState } from 'react'
import prettyBytes from 'pretty-bytes'
import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs'
import { openFolder } from '@/lib/util'
export default function ManageVersionPopup () {
@@ -23,8 +22,9 @@ export default function ManageVersionPopup () {
setPopupMode,
setSelectedVersionList,
downloadVersions,
uninstallVersion,
versions,
customDataLocation
launchesList
} = useGlobal()
const [versionSize, setVersionSize] = useState<number>(0)
@@ -114,39 +114,16 @@ export default function ManageVersionPopup () {
className='entry-info-item btntheme2'
onClick={async () => {
closePopup()
uninstallVersion(managingVersion)
if (!versionInfo) return
await versions?.set(
'list',
Object.fromEntries(
Object.entries(versionsList).filter(
([k]) => k !== managingVersion
)
)
)
const gameLaunches = { ...launchesList[versionInfo.game] }
delete gameLaunches[versionInfo.id]
if (
await exists(
(customDataLocation ? customDataLocation + '/' : null) +
'game/' +
managingVersion,
{
baseDir: customDataLocation
? undefined
: BaseDirectory.AppLocalData
}
)
)
await remove(
(customDataLocation ? customDataLocation + '/' : null) +
'game/' +
managingVersion,
{
baseDir: customDataLocation
? undefined
: BaseDirectory.AppLocalData,
recursive: true
}
)
await versions?.set('launches', {
...launchesList,
[versionInfo.game]: gameLaunches
})
}}
title='Click to uninstall this game. This will NOT remove any progress or any save files.'
>
@@ -160,38 +137,7 @@ export default function ManageVersionPopup () {
setPopupMode(1)
//uninstall
await versions?.set(
'list',
Object.fromEntries(
Object.entries(versionsList).filter(
([k]) => k !== managingVersion
)
)
)
if (
await exists(
(customDataLocation ? customDataLocation + '/' : null) +
'game/' +
managingVersion,
{
baseDir: customDataLocation
? undefined
: BaseDirectory.AppLocalData
}
)
)
await remove(
(customDataLocation ? customDataLocation + '/' : null) +
'game/' +
managingVersion,
{
baseDir: customDataLocation
? undefined
: BaseDirectory.AppLocalData,
recursive: true
}
)
uninstallVersion(managingVersion)
//reinstall
setSelectedVersionList([managingVersion])
+1
View File
@@ -73,6 +73,7 @@ type GlobalCtxType = {
lastRevision: number | undefined,
version: string
) => boolean
uninstallVersion: (version: string, updateList?: boolean) => Promise<void>
launchGame: (versionInfo: GameVersion) => Promise<void>
}