Let the user approve revision updates before proceeding

This commit is contained in:
2026-02-09 20:46:15 -07:00
parent a93e4ab521
commit 97231c6b38
4 changed files with 218 additions and 23 deletions

View File

@@ -42,6 +42,7 @@ type GlobalCtxType = {
} | null } | null
viewingInfoFromDownloads: boolean viewingInfoFromDownloads: boolean
version: string | null version: string | null
downloadVersions: (list: string[]) => Promise<void>
} }
const GlobalCtx = createContext<GlobalCtxType | null>(null) const GlobalCtx = createContext<GlobalCtxType | null>(null)

View File

@@ -0,0 +1,105 @@
'use client'
import { invoke } from '@tauri-apps/api/core'
import { useGlobal } from '../GlobalProvider'
import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs'
import { writeVersionsConfig } from '../util/BazookaManager'
import { useState } from 'react'
export default function VersionUpdateWarning () {
const [confirmed, setConfirmed] = useState<-1 | 0>(-1)
const {
managingVersion,
setDownloadedVersionsConfig,
setManagingVersion,
setPopupMode,
setSelectedVersionList,
downloadVersions
} = useGlobal()
if (!managingVersion) return <p>Error</p>
return (
<>
<p className='text-xl text-center'>Warning!</p>
<div className='popup-content text-center p-2 relative'>
<p className='mb-2'>
Before proceeding, please note that any modifications to the
installation directory <b>(NOT THE SAVE DATA)</b> will be completely
wiped/reset.
</p>
<p>
If you do not want your installation directory wiped just yet, please
backup the files to another directory. When you click update, it will
be wiped.
</p>
<p className='my-2'>
Updating will have the same effect as clicking the uninstall button
then installing again.
</p>
<p>Revisions are not a frequent thing and rarely ever happen.</p>
<div className='flex flex-row gap-2 absolute bottom-2 left-1/2 -translate-x-1/2 w-max'>
<button
className='button btntheme2'
onClick={async () =>
invoke('open_folder', {
name: managingVersion
})
}
title="Click to browse the game's files."
>
Open Folder / Installation directory
</button>
<button
className='button btntheme2'
onClick={async () => {
if (confirmed == -1) {
setConfirmed(0)
return
}
//change popup to downloads
setManagingVersion(null)
setPopupMode(1)
//uninstall
setDownloadedVersionsConfig(prev => {
if (!prev) return prev
const updatedList = Object.fromEntries(
Object.entries(prev.list).filter(
([k]) => k !== managingVersion
)
)
const updatedConfig = {
...prev,
list: updatedList
}
writeVersionsConfig(updatedConfig)
return updatedConfig
})
if (
await exists('game/' + managingVersion, {
baseDir: BaseDirectory.AppLocalData
})
)
await remove('game/' + managingVersion, {
baseDir: BaseDirectory.AppLocalData,
recursive: true
})
//reinstall
setSelectedVersionList([managingVersion])
downloadVersions([managingVersion])
}}
title='Click to update the game'
>
<span className='text-red-500 font-bold underline'>
{confirmed == -1 ? 'Update' : 'Are you sure?'}
</span>
</button>
</div>
</div>
</>
)
}

View File

@@ -45,6 +45,21 @@ export default function Installs () {
setCategory(-1) setCategory(-1)
} }
const needsRevisionUpdate = (
lastRevision: number | undefined,
version: string
) => {
if (!lastRevision) return false
return (
lastRevision > 0 &&
(downloadedVersionsConfig == undefined
? 0
: downloadedVersionsConfig?.list[version]) /
1000 <=
lastRevision
)
}
return ( return (
<div className='mx-4 mt-4'> <div className='mx-4 mt-4'>
<div className='flex justify-between items-center mb-4'> <div className='flex justify-between items-center mb-4'>
@@ -203,17 +218,32 @@ export default function Installs () {
<div <div
key={entry} key={entry}
className={`downloads-entry ${ className={`downloads-entry ${
normalConfig?.settings.useLegacyInteractButtons normalConfig?.settings.useLegacyInteractButtons ||
needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
? '' ? ''
: 'cursor-pointer' : 'cursor-pointer'
}`} }`}
title={ title={
normalConfig?.settings.useLegacyInteractButtons normalConfig?.settings.useLegacyInteractButtons ||
needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
? '' ? ''
: 'Click to launch game. Right-click to manage this version install' : 'Click to launch game. Right-click to manage this version install'
} }
onClick={async () => { onClick={async () => {
if (normalConfig?.settings.useLegacyInteractButtons) return if (
normalConfig?.settings.useLegacyInteractButtons ||
needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
)
return
const verInfo = getVersionInfo(entry) const verInfo = getVersionInfo(entry)
if (verInfo == undefined) return if (verInfo == undefined) return
const gameInfo = getGameInfo(verInfo.game) const gameInfo = getGameInfo(verInfo.game)
@@ -232,7 +262,14 @@ export default function Installs () {
}} }}
onContextMenu={e => { onContextMenu={e => {
e.preventDefault() e.preventDefault()
if (normalConfig?.settings.useLegacyInteractButtons) return if (
normalConfig?.settings.useLegacyInteractButtons ||
needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
)
return
setManagingVersion(entry) setManagingVersion(entry)
setPopupMode(2) setPopupMode(2)
@@ -242,7 +279,7 @@ export default function Installs () {
> >
<div className='h-18 w-screen relative'> <div className='h-18 w-screen relative'>
<p className='text-2xl'> <p className='text-2xl'>
{getVersionInfo(entry)?.displayName} {getVersionInfo(entry)?.displayName}{' '}
</p> </p>
<div className='flex gap-2 absolute left-0 bottom-0'> <div className='flex gap-2 absolute left-0 bottom-0'>
@@ -272,6 +309,19 @@ export default function Installs () {
<FontAwesomeIcon icon={faWarning} color='#ffc800' /> <FontAwesomeIcon icon={faWarning} color='#ffc800' />
<p>Uses wine</p> <p>Uses wine</p>
</div> </div>
<div
className='entry-info-item'
onClick={e => e.stopPropagation()}
hidden={
!needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
}
>
<FontAwesomeIcon icon={faWarning} color='#ffc800' />
<p>Needs revision update!</p>
</div>
</div> </div>
<div className='flex gap-2 absolute right-0 bottom-0'> <div className='flex gap-2 absolute right-0 bottom-0'>
@@ -284,6 +334,10 @@ export default function Installs () {
setShowPopup(true) setShowPopup(true)
setFadeOut(false) setFadeOut(false)
}} }}
hidden={needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)}
title='Click to view version info' title='Click to view version info'
> >
View Info View Info
@@ -291,7 +345,11 @@ export default function Installs () {
<button <button
className='button' className='button'
hidden={ hidden={
!normalConfig?.settings.useLegacyInteractButtons !normalConfig?.settings.useLegacyInteractButtons ||
needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
} }
onClick={e => { onClick={e => {
e.stopPropagation() e.stopPropagation()
@@ -326,12 +384,35 @@ export default function Installs () {
}) })
}} }}
hidden={ hidden={
!normalConfig?.settings.useLegacyInteractButtons !normalConfig?.settings.useLegacyInteractButtons ||
needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
} }
title='Click to launch game' title='Click to launch game'
> >
Launch Launch
</button> </button>
<button
className='button'
onClick={e => {
e.stopPropagation()
setManagingVersion(entry)
setPopupMode(5)
setShowPopup(true)
setFadeOut(false)
}}
hidden={
!needsRevisionUpdate(
getVersionInfo(entry)?.lastRevision,
entry
)
}
title='Click to update the game'
>
Update
</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -46,6 +46,7 @@ import {
} from '@tauri-apps/plugin-notification' } from '@tauri-apps/plugin-notification'
import VersionChangelog from './componets/VersionChangelog' import VersionChangelog from './componets/VersionChangelog'
import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs' import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs'
import VersionUpdateWarning from './componets/VersionUpdateWarning'
const roboto = Roboto({ const roboto = Roboto({
subsets: ['latin'] subsets: ['latin']
@@ -394,28 +395,26 @@ export default function RootLayout ({
if (!serverVersionList || !downloadedVersionsConfig) return if (!serverVersionList || !downloadedVersionsConfig) return
revisionCheck.current = true revisionCheck.current = true
;(async () => { ;(async () => {
const newConfig = {
...downloadedVersionsConfig,
list: { ...downloadedVersionsConfig.list }
}
const versionsToSelect: string[] = []
for (const [key, value] of Object.entries( for (const [key, value] of Object.entries(
downloadedVersionsConfig.list downloadedVersionsConfig.list
)) { )) {
const verInfo = serverVersionList.versions.find(item => item.id === key) const verInfo = serverVersionList.versions.find(item => item.id === key)
if (!verInfo || value / 1000 <= verInfo.lastRevision) { if (
delete newConfig.list[key] !verInfo ||
versionsToSelect.push(key) (verInfo.lastRevision > 0 && value / 1000 <= verInfo.lastRevision)
) {
if (
await exists('game/' + key + '/' + verInfo?.executable, {
baseDir: BaseDirectory.AppLocalData
})
)
await remove('game/' + key + '/' + verInfo?.executable, {
baseDir: BaseDirectory.AppLocalData,
recursive: true
})
} }
} }
setDownloadedVersionsConfig(newConfig)
writeVersionsConfig(newConfig)
setSelectedVersionList(prev => [...prev, ...versionsToSelect])
await downloadVersions(versionsToSelect)
})() })()
}, [serverVersionList, downloadedVersionsConfig, downloadVersions]) }, [serverVersionList, downloadedVersionsConfig, downloadVersions])
@@ -480,7 +479,8 @@ export default function RootLayout ({
setSelectedGame, setSelectedGame,
getVersionsAmountData, getVersionsAmountData,
viewingInfoFromDownloads, viewingInfoFromDownloads,
version version,
downloadVersions
}} }}
> >
<div <div
@@ -893,6 +893,14 @@ export default function RootLayout ({
No version selected No version selected
</p> </p>
) )
) : popupMode === 5 ? (
managingVersion && downloadedVersionsConfig ? (
<VersionUpdateWarning />
) : (
<p className='text-xl text-center'>
No version selected
</p>
)
) : null} ) : null}
{popupMode == 0 && {popupMode == 0 &&
selectedGame && selectedGame &&