diff --git a/app/src/components/Mod.tsx b/app/src/components/Mod.tsx index e3ebb47..dd65e06 100644 --- a/app/src/components/Mod.tsx +++ b/app/src/components/Mod.tsx @@ -32,16 +32,23 @@ export const Mod: FunctionalComponent = ({ mod }) => { setInstalling(true); - await invoke_proxy("install_mod", { - modId: mod.id, + const instance = await invoke_proxy("get_active_instance", { gameId: mod.game_id, - instanceId: await invoke_proxy("get_active_instance", { - gameId: mod.game_id, - }), }); + if (instance) { + const instanceId = instance.id; + + await invoke_proxy("install_mod", { + modId: mod.id, + gameId: mod.game_id, + instanceId, + }); + + setInstalled(!installed); + } + setInstalling(false); - setInstalled(!installed); // TODO: add writing to mods.json when mod is installed }; diff --git a/app/src/invoke.ts b/app/src/invoke.ts index 31e2349..0fdd9ed 100644 --- a/app/src/invoke.ts +++ b/app/src/invoke.ts @@ -71,7 +71,7 @@ export interface InvokeFunction { read_mod_json: [undefined, ModsIntegrity]; update_description: [InstanceUpdateArgs, undefined]; - get_active_instance: [GameArgs, number]; + get_active_instance: [GameArgs, InstanceInfo | undefined]; set_active_instance: [InstanceArgs, undefined]; delete_instance: [InstanceArgs, undefined]; diff --git a/app/src/routes/Instance.tsx b/app/src/routes/Instance.tsx index 1eb16f3..ba2ccd9 100644 --- a/app/src/routes/Instance.tsx +++ b/app/src/routes/Instance.tsx @@ -66,9 +66,10 @@ export const Instance = () => { }; const launch = async () => { - await invoke_proxy("launch", { - instanceId: instanceInfo?.id || -1, - }); + if (instanceInfo) + await invoke_proxy("launch", { + instanceId: instanceInfo.id, + }); }; return ( diff --git a/app/src/routes/mods/Browse.tsx b/app/src/routes/mods/Browse.tsx index 07dc030..0cee34b 100644 --- a/app/src/routes/mods/Browse.tsx +++ b/app/src/routes/mods/Browse.tsx @@ -70,6 +70,9 @@ export const Browse = () => { setPages(0); (async () => { + setInstance(-1); + setInstanceText("Unknown"); + const data = await invoke_proxy("get_mods", { gameId, count: perPage, @@ -81,6 +84,16 @@ export const Browse = () => { if (page > data.pages) setPage(data.pages - 1); + const defaultInstance = await invoke_proxy( + "get_active_instance", + { gameId } + ); + + if (defaultInstance) { + setInstance(defaultInstance.id); + setInstanceText(defaultInstance.name); + } + if (initialLoad) { setInstances( (await invoke_proxy("get_instances", undefined)).map( diff --git a/common/src/instances/instance.rs b/common/src/instances/instance.rs index d5ae883..d9383a8 100644 --- a/common/src/instances/instance.rs +++ b/common/src/instances/instance.rs @@ -83,20 +83,23 @@ impl Instance { KSPGame::KSP1 => instance .install_path .join("KSP_x64_Data/Plugins/x86_64/steam_api64.dll"), + KSPGame::KSP2 => instance .install_path - .join("KSP2_x64_Data/Plugins/x86_64/steam_api64.dll`"), + .join("KSP2_x64_Data/Plugins/x86_64/steam_api64.dll"), }; - let size = api_dll.metadata().unwrap().len(); + if api_dll.exists() { + let size = api_dll.metadata().unwrap().len(); - let needed_size = match instance.game { - KSPGame::KSP1 => KSP1_STEAM_API_SIZE, - KSPGame::KSP2 => KSP2_STEAM_API_SIZE, - }; + let needed_size = match instance.game { + KSPGame::KSP1 => KSP1_STEAM_API_SIZE, + KSPGame::KSP2 => KSP2_STEAM_API_SIZE, + }; - if size == needed_size { - final_instances.push(instance); + if size == needed_size { + final_instances.push(instance); + } } } } diff --git a/gui/src/main.rs b/gui/src/main.rs index 159818f..220d4fd 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -176,14 +176,10 @@ fn read_mod_json() -> Mods { } #[tauri::command] -fn get_active_instance(game_id: i32) -> i32 { +fn get_active_instance(game_id: i32) -> Option { let instance = Instance::get_active_instance(KSPGame::from_id(game_id).unwrap()); - if let Some(instance) = instance { - return instance.id; - } - - return -1; + return instance; } #[tauri::command]