fix: game state was not updated

This commit is contained in:
ALEZ-DEV 2025-03-17 20:37:05 +01:00
parent 80836f32ec
commit c70feada75
3 changed files with 26 additions and 14 deletions

View File

@ -39,14 +39,16 @@ pub async fn get_proton() -> Proton {
.clone()
}
pub async fn run_game() {
pub async fn run_game() -> anyhow::Result<()> {
let proton = get_proton().await;
let game_dir = GameConfig::get_game_dir().await;
let game_dir = GameConfig::get_config().await.game_dir;
if game_dir.is_none() {
error!("Failed to start game, the game directory was not found")
anyhow::bail!("Failed to start game, the game directory was not found");
}
GameManager::start_game(&proton, game_dir.unwrap(), None, false).await;
GameManager::start_game(&proton, game_dir.unwrap(), None, false).await?;
Ok(())
}
#[derive(Debug)]
@ -77,7 +79,12 @@ impl Worker for HandleGameProcess {
.unwrap()
.block_on(async {
sender.output(ui::pages::game::GamePageMsg::SetIsGameRunning(true));
run_game().await;
if let Err(error) = run_game().await {
sender.output(pages::game::GamePageMsg::ShowError(format!(
"Unable to start game : {}",
error
)));
};
sender.output(ui::pages::game::GamePageMsg::SetIsGameRunning(false));
});
}
@ -131,6 +138,7 @@ impl Worker for HandleGameInstallation {
};
sender.output(pages::game::GamePageMsg::SetIsDownloading(false));
sender.output(pages::game::GamePageMsg::UpdateGameState);
});
}
HandleGameInstallationMsg::StartPatch => {
@ -155,6 +163,7 @@ impl Worker for HandleGameInstallation {
};
sender.output(pages::game::GamePageMsg::SetIsPatching(false));
sender.output(pages::game::GamePageMsg::UpdateGameState);
});
}
HandleGameInstallationMsg::StartUpdate(progress_bar) => {
@ -187,6 +196,7 @@ impl Worker for HandleGameInstallation {
};
sender.output(pages::game::GamePageMsg::SetIsDownloading(true));
sender.output(pages::game::GamePageMsg::UpdateGameState);
});
}
}

View File

@ -80,6 +80,7 @@ impl SimpleAsyncComponent for GamePage {
set_hexpand: false,
set_width_request: 200,
#[watch]
set_visible: model.game_state == GameState::GameNotInstalled,
#[watch]
@ -96,6 +97,7 @@ impl SimpleAsyncComponent for GamePage {
set_hexpand: false,
set_width_request: 200,
#[watch]
set_visible: model.game_state == GameState::GameNotPatched,
#[watch]
@ -112,6 +114,7 @@ impl SimpleAsyncComponent for GamePage {
set_hexpand: false,
set_width_request: 200,
#[watch]
set_visible: model.game_state == GameState::GameInstalled,
#[watch]
@ -189,6 +192,7 @@ impl SimpleAsyncComponent for GamePage {
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
set_halign: gtk::Align::Center,
gtk::Label {
set_label: "Patching game",

View File

@ -153,8 +153,8 @@ impl GameManager {
game_dir: PathBuf,
options: Option<String>,
show_logs: bool,
) {
let proton_version = proton.wine().version().unwrap();
) -> anyhow::Result<()> {
let proton_version = proton.wine().version()?;
let binary_path = game_dir
.join(get_game_name())
.join(get_game_name_with_executable());
@ -162,16 +162,12 @@ impl GameManager {
debug!("Wine version : {:?}", proton_version);
let mut child = if let Some(custom_command) = options {
Self::run(proton, binary_path, Some(custom_command))
.await
.unwrap()
Self::run(proton, binary_path, Some(custom_command)).await?
} else {
if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() {
Self::run(proton, binary_path, Some(custom_command))
.await
.unwrap()
Self::run(proton, binary_path, Some(custom_command)).await?
} else {
Self::run(proton, binary_path, None).await.unwrap()
Self::run(proton, binary_path, None).await?
}
};
@ -274,6 +270,8 @@ impl GameManager {
.write_all(to_write)
.await
.expect("Failed to write the output to the log file");
Ok(())
}
async fn run(