From c07828f2444fdb3ab6e65535e124fd47dc7f532e Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Wed, 7 Jan 2026 18:10:14 -0700 Subject: [PATCH] Improve the logic for uninstalling a version, it was incredibly bad and stupid --- src-tauri/capabilities/default.json | 12 +++- src/app/layout.tsx | 107 +++++++++++++--------------- 2 files changed, 57 insertions(+), 62 deletions(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 617c7c4..6a215a8 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -21,11 +21,17 @@ "core:window:allow-toggle-maximize", "decorum:allow-show-snap-overlay", "fs:default", - "fs:allow-applocaldata-read", - "fs:allow-applocaldata-write", "dialog:default", "notification: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/**" } + ] + } ] } \ No newline at end of file diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8a41688..25db2df 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -45,6 +45,7 @@ import { requestPermission } from '@tauri-apps/plugin-notification' import VersionChangelog from './componets/VersionChangelog' +import { BaseDirectory, remove } from '@tauri-apps/plugin-fs' const roboto = Roboto({ subsets: ['latin'] @@ -97,7 +98,6 @@ export default function RootLayout ({ useEffect(() => { let unlistenProgress: (() => void) | null = null - let unlistenUninstalled: (() => void) | null = null listen('download-progress', event => { const [versionName, progStr, totalSizeStr, speedStr, etaSecsStr] = @@ -143,30 +143,8 @@ export default function RootLayout ({ }) }).then(f => (unlistenProgress = f)) - listen('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 () => { unlistenProgress?.() - unlistenUninstalled?.() } }, []) @@ -367,6 +345,21 @@ export default function RootLayout ({ 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 ( <> @@ -438,20 +431,7 @@ export default function RootLayout ({
{ - if (showPopup && e.key === 'Escape') { - 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) - } - } + if (showPopup && e.key === 'Escape') closePopup() }} > @@ -472,24 +452,7 @@ export default function RootLayout ({