diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 0f7ed26..0772634 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -105,6 +105,26 @@ fn fallback_mod(file_name: &str, enabled: bool) -> Mod { } } +#[tauri::command] +pub async fn remove_mod(version: String, file_name: String) -> Result<(), String> { + // mods folder + let mods_dir: PathBuf = LAUNCHER_DIR.data_dir().join(&version).join("mods"); + + // File to remove + let source = mods_dir.join(&file_name); + + if !source.exists() { + return Err(format!("Mod file not found: {}", file_name)); + } + + // move file + fs::remove_file(&source) + .await + .map_err(|e| e.to_string())?; + + Ok(()) +} + #[tauri::command] pub async fn disable_mod(version: String, file_name: String) -> Result<(), String> { // mods folder diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index cd7f6aa..b388c66 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -12,9 +12,10 @@ fn main() { .invoke_handler(tauri::generate_handler![ // Saturn Launcher Commands saturn_launcher_lib::commands::get_installed_mods, + saturn_launcher_lib::commands::install_mod, saturn_launcher_lib::commands::enable_mod, saturn_launcher_lib::commands::disable_mod, - saturn_launcher_lib::commands::install_mod, + saturn_launcher_lib::commands::remove_mod, saturn_launcher_lib::commands::get_settings, saturn_launcher_lib::commands::update_settings, saturn_launcher_lib::commands::get_version, diff --git a/src/components/ModsSection.tsx b/src/components/ModsSection.tsx index f62aeb6..0113be7 100644 --- a/src/components/ModsSection.tsx +++ b/src/components/ModsSection.tsx @@ -14,6 +14,7 @@ import { enableMod, installMod, disableMod, + removeMod, } from "@/lib/saturn"; import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; @@ -46,6 +47,10 @@ const ModsSection: React.FC = ({ version }) => { if (activeTab === "installed") { const m = await getInstalledMods(version.id); setMods(m); + if (activeTab === "installed") { + // Fix: If discover mods takes too long and the user switches tabs it glitches + setMods(m); + } } else { const m = await discoverMods(searchQuery); if (activeTab === "discover") { @@ -72,6 +77,11 @@ const ModsSection: React.FC = ({ version }) => { setMods(m); }; + const handleRemove = async (modId: string) => { + await removeMod(version.id, modId); + loadMods(); + } + const openInstallDialog = (mod: Mod) => { setSelectedModForInstall(mod); setSelectedVersionsForInstall([version.id]); @@ -200,7 +210,7 @@ const ModsSection: React.FC = ({ version }) => { )} {mod.enabled ? "Enabled" : "Disabled"} - diff --git a/src/lib/saturn.ts b/src/lib/saturn.ts index 0dad4ad..8dc6d07 100644 --- a/src/lib/saturn.ts +++ b/src/lib/saturn.ts @@ -17,6 +17,13 @@ export async function disableMod( await invoke("disable_mod", { version, fileName: modId }); } +export async function removeMod( + version: string, + modId: string, +): Promise { + await invoke("remove_mod", { version, fileName: modId }); +} + export async function discoverMods(query: string): Promise { const url = new URL("https://api.modrinth.com/v2/search");