Skip to content

Commit

Permalink
Fix more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Mar 25, 2023
1 parent 063429a commit 02a22ad
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
19 changes: 13 additions & 6 deletions app/src/components/Mod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,23 @@ export const Mod: FunctionalComponent<ModParams> = ({ 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
};
Expand Down
2 changes: 1 addition & 1 deletion app/src/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
7 changes: 4 additions & 3 deletions app/src/routes/Instance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
13 changes: 13 additions & 0 deletions app/src/routes/mods/Browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export const Browse = () => {
setPages(0);

(async () => {
setInstance(-1);
setInstanceText("Unknown");

const data = await invoke_proxy("get_mods", {
gameId,
count: perPage,
Expand All @@ -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(
Expand Down
19 changes: 11 additions & 8 deletions common/src/instances/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instance> {
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]
Expand Down

0 comments on commit 02a22ad

Please sign in to comment.