Remove mod #11
This commit is contained in:
@@ -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]
|
#[tauri::command]
|
||||||
pub async fn disable_mod(version: String, file_name: String) -> Result<(), String> {
|
pub async fn disable_mod(version: String, file_name: String) -> Result<(), String> {
|
||||||
// mods folder
|
// mods folder
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ fn main() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
// Saturn Launcher Commands
|
// Saturn Launcher Commands
|
||||||
saturn_launcher_lib::commands::get_installed_mods,
|
saturn_launcher_lib::commands::get_installed_mods,
|
||||||
|
saturn_launcher_lib::commands::install_mod,
|
||||||
saturn_launcher_lib::commands::enable_mod,
|
saturn_launcher_lib::commands::enable_mod,
|
||||||
saturn_launcher_lib::commands::disable_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::get_settings,
|
||||||
saturn_launcher_lib::commands::update_settings,
|
saturn_launcher_lib::commands::update_settings,
|
||||||
saturn_launcher_lib::commands::get_version,
|
saturn_launcher_lib::commands::get_version,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
enableMod,
|
enableMod,
|
||||||
installMod,
|
installMod,
|
||||||
disableMod,
|
disableMod,
|
||||||
|
removeMod,
|
||||||
} from "@/lib/saturn";
|
} from "@/lib/saturn";
|
||||||
import { clsx, type ClassValue } from "clsx";
|
import { clsx, type ClassValue } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
@@ -46,6 +47,10 @@ const ModsSection: React.FC<ModsSectionProps> = ({ version }) => {
|
|||||||
if (activeTab === "installed") {
|
if (activeTab === "installed") {
|
||||||
const m = await getInstalledMods(version.id);
|
const m = await getInstalledMods(version.id);
|
||||||
setMods(m);
|
setMods(m);
|
||||||
|
if (activeTab === "installed") {
|
||||||
|
// Fix: If discover mods takes too long and the user switches tabs it glitches
|
||||||
|
setMods(m);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const m = await discoverMods(searchQuery);
|
const m = await discoverMods(searchQuery);
|
||||||
if (activeTab === "discover") {
|
if (activeTab === "discover") {
|
||||||
@@ -72,6 +77,11 @@ const ModsSection: React.FC<ModsSectionProps> = ({ version }) => {
|
|||||||
setMods(m);
|
setMods(m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRemove = async (modId: string) => {
|
||||||
|
await removeMod(version.id, modId);
|
||||||
|
loadMods();
|
||||||
|
}
|
||||||
|
|
||||||
const openInstallDialog = (mod: Mod) => {
|
const openInstallDialog = (mod: Mod) => {
|
||||||
setSelectedModForInstall(mod);
|
setSelectedModForInstall(mod);
|
||||||
setSelectedVersionsForInstall([version.id]);
|
setSelectedVersionsForInstall([version.id]);
|
||||||
@@ -200,7 +210,7 @@ const ModsSection: React.FC<ModsSectionProps> = ({ version }) => {
|
|||||||
)}
|
)}
|
||||||
{mod.enabled ? "Enabled" : "Disabled"}
|
{mod.enabled ? "Enabled" : "Disabled"}
|
||||||
</button>
|
</button>
|
||||||
<button className="p-2 text-saturn-text-secondary hover:text-red-400 transition-colors">
|
<button className="p-2 text-saturn-text-secondary hover:text-red-400 transition-colors" onClick={() => handleRemove(mod.id)}>
|
||||||
<Trash2 size={16} />
|
<Trash2 size={16} />
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ export async function disableMod(
|
|||||||
await invoke("disable_mod", { version, fileName: modId });
|
await invoke("disable_mod", { version, fileName: modId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function removeMod(
|
||||||
|
version: string,
|
||||||
|
modId: string,
|
||||||
|
): Promise<void> {
|
||||||
|
await invoke("remove_mod", { version, fileName: modId });
|
||||||
|
}
|
||||||
|
|
||||||
export async function discoverMods(query: string): Promise<Mod[]> {
|
export async function discoverMods(query: string): Promise<Mod[]> {
|
||||||
const url = new URL("https://api.modrinth.com/v2/search");
|
const url = new URL("https://api.modrinth.com/v2/search");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user