diff --git a/src-tauri/src/app/gui.rs b/src-tauri/src/app/gui.rs index aecfddc..0e47150 100644 --- a/src-tauri/src/app/gui.rs +++ b/src-tauri/src/app/gui.rs @@ -147,7 +147,7 @@ async fn get_custom_mods(branch: &str, mc_version: &str) -> Result Re fs::create_dir_all(&mod_cache_path).await.unwrap(); } - if let Some(path) = path.file_name() { - let file_name = path.to_str().unwrap(); - let dest_path = mod_cache_path.join(file_name); + if let Some(file_name) = path.file_name() { + let dest_path = mod_cache_path.join(file_name.to_str().unwrap()); fs::copy(path, dest_path).await .map_err(|e| format!("unable to copy custom mod: {:?}", e))?; diff --git a/src/lib/main/LaunchArea.svelte b/src/lib/main/LaunchArea.svelte index d4cb3e0..0bbcbc6 100644 --- a/src/lib/main/LaunchArea.svelte +++ b/src/lib/main/LaunchArea.svelte @@ -33,8 +33,8 @@
- dispatch("showVersionSelect")} /> - dispatch("showVersionSelect")} /> + dispatch("showVersionSelect")} /> + dispatch("showVersionSelect")} />
{#if running} diff --git a/src/lib/main/MainScreen.svelte b/src/lib/main/MainScreen.svelte index afc2cbe..6e595b7 100644 --- a/src/lib/main/MainScreen.svelte +++ b/src/lib/main/MainScreen.svelte @@ -25,6 +25,7 @@ import LauncherVersion from "../settings/LauncherVersion.svelte"; import IconButtonSetting from "../settings/IconButtonSetting.svelte"; import CustomModSetting from "../settings/CustomModSetting.svelte"; + import { open as dialogOpen } from "@tauri-apps/api/dialog"; export let options; @@ -87,8 +88,15 @@ return builds.find((build) => build.buildId === options.preferredBuild); } - let lbVersion = {}; - let mcVersion = {}; + let lbVersion = ""; + let mcVersion = ""; + let branch = ""; + + let additionalModsTitle = ""; + + $: { + additionalModsTitle = `Additional mods for ${branch} ${mcVersion}`; + } let mods = []; let customMods = []; @@ -116,14 +124,9 @@ let b = getBuild(); console.debug("Updating build data", b); - lbVersion = { - date: b.date, - title: b.lbVersion - }; - mcVersion = { - date: "", // todo: No date for MC version - title: b.mcVersion - }; + branch = b.branch; + lbVersion = b.lbVersion; + mcVersion = b.mcVersion; // Update changelog invoke("fetch_changelog", { buildId: b.buildId }) @@ -159,11 +162,10 @@ invoke("get_custom_mods", { branch, mcVersion }) .then(result => { - console.log("Fetched custom mods", result); customMods = result; if (branchOptions) { - mods.forEach(mod => { + customMods.forEach(mod => { mod.enabled = branchOptions.customModStates[mod.name] ?? mod.enabled; }); } @@ -207,6 +209,8 @@ let build = getBuild(); console.debug("Running build", build); + + console.log([...mods, ...customMods]) await invoke("run_client", { buildId: build.buildId, accountData: options.currentAccount, options: options, mods: [...mods, ...customMods] }); } @@ -234,7 +238,12 @@ return map; }, {}); - console.debug("Updated mod states", branchOptions.modStates); + branchOptions.customModStates = customMods.reduce(function(map, mod) { + map[mod.name] = mod.enabled; + return map; + }, {}); + + console.log("Updated mod states", branchOptions); options.branchOptions[options.preferredBranch] = branchOptions; options.store(); } @@ -259,6 +268,30 @@ alert("Failed to get data folder: " + e); console.error(e) }); + + async function handleCustomModDelete(e) { + const { branch, mcVersion, subsystem } = getBuild(); + + await invoke("delete_custom_mod", { branch, mcVersion, modName: `${e.detail.name}.jar` }); + + requestMods(branch, mcVersion, subsystem); + } + + async function handleInstallMod(e) { + const { branch, mcVersion, subsystem } = getBuild(); + + const selected = await dialogOpen({ + directory: false, + multiple: false, + filters: [{ name: "", extensions: ["jar"] }], + title: "Select a custom mod to install" + }); + + if (selected) { + await invoke("install_custom_mod", { branch, mcVersion, path: selected }); + requestMods(branch, mcVersion, subsystem); + } + } {#if clientLogShown} @@ -288,13 +321,13 @@ {/each} - +
- +
{#each customMods as m} - + {/each}
diff --git a/src/lib/settings/CustomModSetting.svelte b/src/lib/settings/CustomModSetting.svelte index 667cf5a..d280e4f 100644 --- a/src/lib/settings/CustomModSetting.svelte +++ b/src/lib/settings/CustomModSetting.svelte @@ -1,13 +1,16 @@
- -
diff --git a/src/lib/settings/IconButtonSetting.svelte b/src/lib/settings/IconButtonSetting.svelte index cc4783b..63362d4 100644 --- a/src/lib/settings/IconButtonSetting.svelte +++ b/src/lib/settings/IconButtonSetting.svelte @@ -7,7 +7,7 @@ const dispatch = createEventDispatcher(); -