From 520d176368b65da66168a0cda776271667687a83 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Wed, 23 Jul 2025 00:47:16 -0700 Subject: [PATCH] Add managing versions menu & fix a typo --- package.json | 2 +- src-tauri/src/lib.rs | 47 ++++++++++++++++++++++++++++- src/main.tsx | 62 ++++++++++++++++++++++++++++++++++++++ src/routes/Installs.tsx | 18 +++++++++-- src/types/InstallsProps.ts | 2 ++ yarn.lock | 12 ++++---- 6 files changed, 132 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 8ae6d04..c657f27 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@tauri-apps/plugin-notification": "2.3.0", "@tauri-apps/plugin-opener": "2.4.0", "@tauri-apps/plugin-os": "2.3.0", - "axios": "1.10.0", + "axios": "1.11.0", "date-fns": "4.1.0", "react": "19.1.0", "react-dom": "19.1.0" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 42decd5..9da17f0 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -259,6 +259,49 @@ fn get_keys_config(key: i8) -> String { } } +#[tauri::command] +async fn uninstall_version(app: AppHandle, name: String) { + let game_path = app + .path() + .app_local_data_dir() + .unwrap() + .join("game") + .join(&name); + if game_path.exists() { + if let Err(_) = tokio::fs::remove_dir_all(&game_path).await { + app.emit("version-failed", &name).unwrap(); + } else { + app.emit("version-uninstalled", &name).unwrap(); + } + } else { + app.emit("version-uninstalled", &name).unwrap(); + } +} + +#[tauri::command] +async fn open_folder(app: AppHandle, name: String) { + let game_path = app + .path() + .app_local_data_dir() + .unwrap() + .join("game") + .join(&name); + if game_path.exists() { + app.opener() + .open_path(game_path.to_string_lossy(), None::<&str>) + .unwrap(); + } else { + app.dialog() + .message(format!( + "Game folder \"{}\" not found.", + game_path.display() + )) + .kind(MessageDialogKind::Error) + .title("Folder not found") + .show(|_| {}); + } +} + pub fn run() { #[allow(unused_variables)] tauri::Builder::default() @@ -278,7 +321,9 @@ pub fn run() { download, launch_game, download_leaderboard, - get_keys_config + get_keys_config, + uninstall_version, + open_folder ]) .setup(|app| { #[cfg(target_os = "windows")] diff --git a/src/main.tsx b/src/main.tsx index 06b3b35..572daf7 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -50,8 +50,15 @@ function App () { const [downloadedVersionsConfig, setDownloadedVersionsConfig] = useState(null) const [normalConfig, setNormalConfig] = useState(null) + const [managingVersion, setManagingVersion] = + useState(null) function runNext () { + if (activeDownloads.current === 0 && queue.current.length === 0) { + setFadeOut(true) + setTimeout(() => setShowPopup(false), 200) + return + } if (activeDownloads.current >= 3 || queue.current.length === 0) return activeDownloads.current++ const next = queue.current.shift() @@ -133,10 +140,32 @@ function App () { ) }) + const unlistenUninstalled = listen( + 'version-uninstalled', + async event => { + const versionName = event.payload + setDownloadedVersionsConfig(prev => { + if (!prev) return prev + const updatedList = prev.list.filter( + v => v.version.version !== versionName + ) + const updatedConfig = { ...prev, list: updatedList } + writeVersionsConfig(updatedConfig) + if (popupMode === 2) { + setManagingVersion(null) + setFadeOut(true) + setTimeout(() => setShowPopup(false), 200) + } + return updatedConfig + }) + } + ) + return () => { unlistenProgress.then(f => f()) unlistenDone.then(f => f()) unlistenFailed.then(f => f()) + unlistenUninstalled.then(f => f()) } }, [downloadedVersionsConfig]) @@ -246,6 +275,7 @@ function App () { setVersionList={setVersionList} downloadedVersionsConfig={downloadedVersionsConfig} normalConfig={normalConfig} + setManagingVersion={setManagingVersion} /> ) } else if (hash === '#settings') { @@ -411,6 +441,38 @@ function App () { )} + ) : popupMode === 2 ? ( + managingVersion ? ( + <> +

+ Manage version {managingVersion.version.displayName} +

+
+ + +
+ + ) : ( +

No version selected

+ ) ) : null} {popupMode == 0 && versionList != null && (
diff --git a/src/routes/Installs.tsx b/src/routes/Installs.tsx index 4002d94..13c66a5 100644 --- a/src/routes/Installs.tsx +++ b/src/routes/Installs.tsx @@ -16,7 +16,8 @@ export default function Installs ({ setSelectedVersionList, setVersionList, downloadedVersionsConfig, - normalConfig + normalConfig, + setManagingVersion }: InstallsProps) { useEffect(() => { if (!showPopup) return @@ -49,7 +50,7 @@ export default function Installs ({ return (
-

Install

+

Installs

+