Improve the logic for uninstalling a version, it was incredibly bad and stupid
This commit is contained in:
@@ -21,11 +21,17 @@
|
|||||||
"core:window:allow-toggle-maximize",
|
"core:window:allow-toggle-maximize",
|
||||||
"decorum:allow-show-snap-overlay",
|
"decorum:allow-show-snap-overlay",
|
||||||
"fs:default",
|
"fs:default",
|
||||||
"fs:allow-applocaldata-read",
|
|
||||||
"fs:allow-applocaldata-write",
|
|
||||||
"dialog:default",
|
"dialog:default",
|
||||||
"notification:default",
|
"notification:default",
|
||||||
"clipboard-manager:default",
|
"clipboard-manager:default",
|
||||||
"clipboard-manager:allow-write-text"
|
"clipboard-manager:allow-write-text",
|
||||||
|
"fs:allow-applocaldata-read",
|
||||||
|
"fs:allow-applocaldata-write",
|
||||||
|
{
|
||||||
|
"identifier": "fs:scope",
|
||||||
|
"allow": [
|
||||||
|
{ "path": "$APPLOCALDATA/game/**" }
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,7 @@ import {
|
|||||||
requestPermission
|
requestPermission
|
||||||
} from '@tauri-apps/plugin-notification'
|
} from '@tauri-apps/plugin-notification'
|
||||||
import VersionChangelog from './componets/VersionChangelog'
|
import VersionChangelog from './componets/VersionChangelog'
|
||||||
|
import { BaseDirectory, remove } from '@tauri-apps/plugin-fs'
|
||||||
|
|
||||||
const roboto = Roboto({
|
const roboto = Roboto({
|
||||||
subsets: ['latin']
|
subsets: ['latin']
|
||||||
@@ -97,7 +98,6 @@ export default function RootLayout ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let unlistenProgress: (() => void) | null = null
|
let unlistenProgress: (() => void) | null = null
|
||||||
let unlistenUninstalled: (() => void) | null = null
|
|
||||||
|
|
||||||
listen<string>('download-progress', event => {
|
listen<string>('download-progress', event => {
|
||||||
const [versionName, progStr, totalSizeStr, speedStr, etaSecsStr] =
|
const [versionName, progStr, totalSizeStr, speedStr, etaSecsStr] =
|
||||||
@@ -143,30 +143,8 @@ export default function RootLayout ({
|
|||||||
})
|
})
|
||||||
}).then(f => (unlistenProgress = f))
|
}).then(f => (unlistenProgress = f))
|
||||||
|
|
||||||
listen<string>('version-uninstalled', event => {
|
|
||||||
const versionName = event.payload
|
|
||||||
setDownloadedVersionsConfig(prev => {
|
|
||||||
if (!prev) return prev
|
|
||||||
const updatedList = prev.list.filter(v => v !== versionName)
|
|
||||||
const updatedTimestamps = Object.fromEntries(
|
|
||||||
Object.entries(prev.timestamps).filter(([k]) => k !== versionName)
|
|
||||||
)
|
|
||||||
const updatedConfig = {
|
|
||||||
...prev,
|
|
||||||
list: updatedList,
|
|
||||||
timestamps: updatedTimestamps
|
|
||||||
}
|
|
||||||
writeVersionsConfig(updatedConfig)
|
|
||||||
setManagingVersion(null)
|
|
||||||
setFadeOut(true)
|
|
||||||
setTimeout(() => setShowPopup(false), 200)
|
|
||||||
return updatedConfig
|
|
||||||
})
|
|
||||||
}).then(f => (unlistenUninstalled = f))
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unlistenProgress?.()
|
unlistenProgress?.()
|
||||||
unlistenUninstalled?.()
|
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@@ -367,6 +345,21 @@ export default function RootLayout ({
|
|||||||
return `${d}d ${h}h`
|
return `${d}d ${h}h`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closePopup () {
|
||||||
|
if (popupMode == 0 && selectedGame && pathname === '/') {
|
||||||
|
setSelectedGame(null)
|
||||||
|
setSelectedVersionList([])
|
||||||
|
} else if (viewingInfoFromDownloads) {
|
||||||
|
setViewingInfoFromDownloads(false)
|
||||||
|
setPopupMode(0)
|
||||||
|
} else if (popupMode == 4) {
|
||||||
|
setPopupMode(3)
|
||||||
|
} else {
|
||||||
|
setFadeOut(true)
|
||||||
|
setTimeout(() => setShowPopup(false), 200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<html lang='en' className={roboto.className}>
|
<html lang='en' className={roboto.className}>
|
||||||
@@ -438,20 +431,7 @@ export default function RootLayout ({
|
|||||||
<div
|
<div
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
onKeyDown={e => {
|
onKeyDown={e => {
|
||||||
if (showPopup && e.key === 'Escape') {
|
if (showPopup && e.key === 'Escape') closePopup()
|
||||||
if (popupMode == 0 && selectedGame && pathname === '/') {
|
|
||||||
setSelectedGame(null)
|
|
||||||
setSelectedVersionList([])
|
|
||||||
} else if (viewingInfoFromDownloads) {
|
|
||||||
setViewingInfoFromDownloads(false)
|
|
||||||
setPopupMode(0)
|
|
||||||
} else if (popupMode == 4) {
|
|
||||||
setPopupMode(3)
|
|
||||||
} else {
|
|
||||||
setFadeOut(true)
|
|
||||||
setTimeout(() => setShowPopup(false), 200)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
@@ -472,24 +452,7 @@ export default function RootLayout ({
|
|||||||
<div className='popup-box'>
|
<div className='popup-box'>
|
||||||
<button
|
<button
|
||||||
className='close-button'
|
className='close-button'
|
||||||
onClick={() => {
|
onClick={() => closePopup()}
|
||||||
if (
|
|
||||||
popupMode == 0 &&
|
|
||||||
selectedGame &&
|
|
||||||
pathname === '/'
|
|
||||||
) {
|
|
||||||
setSelectedGame(null)
|
|
||||||
setSelectedVersionList([])
|
|
||||||
} else if (viewingInfoFromDownloads) {
|
|
||||||
setViewingInfoFromDownloads(false)
|
|
||||||
setPopupMode(0)
|
|
||||||
} else if (popupMode == 4) {
|
|
||||||
setPopupMode(3)
|
|
||||||
} else {
|
|
||||||
setFadeOut(true)
|
|
||||||
setTimeout(() => setShowPopup(false), 200)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon
|
<FontAwesomeIcon
|
||||||
icon={
|
icon={
|
||||||
@@ -762,11 +725,37 @@ export default function RootLayout ({
|
|||||||
<button
|
<button
|
||||||
className='button btntheme2'
|
className='button btntheme2'
|
||||||
disabled={downloadProgress.length != 0}
|
disabled={downloadProgress.length != 0}
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
invoke('uninstall_version', {
|
closePopup()
|
||||||
name: managingVersion
|
|
||||||
|
setDownloadedVersionsConfig(prev => {
|
||||||
|
if (!prev) return prev
|
||||||
|
const updatedList = prev.list.filter(
|
||||||
|
v => v !== managingVersion
|
||||||
|
)
|
||||||
|
const updatedTimestamps =
|
||||||
|
Object.fromEntries(
|
||||||
|
Object.entries(prev.timestamps).filter(
|
||||||
|
([k]) => k !== managingVersion
|
||||||
|
)
|
||||||
|
)
|
||||||
|
const updatedConfig = {
|
||||||
|
...prev,
|
||||||
|
list: updatedList,
|
||||||
|
timestamps: updatedTimestamps
|
||||||
|
}
|
||||||
|
writeVersionsConfig(updatedConfig)
|
||||||
|
setManagingVersion(null)
|
||||||
|
setFadeOut(true)
|
||||||
|
setTimeout(() => setShowPopup(false), 200)
|
||||||
|
return updatedConfig
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
remove('game/' + managingVersion, {
|
||||||
|
baseDir: BaseDirectory.AppLocalData,
|
||||||
|
recursive: true
|
||||||
|
})
|
||||||
|
}}
|
||||||
title='Click to uninstall this game. This will NOT remove any progress or any save files.'
|
title='Click to uninstall this game. This will NOT remove any progress or any save files.'
|
||||||
>
|
>
|
||||||
Uninstall
|
Uninstall
|
||||||
|
|||||||
Reference in New Issue
Block a user