catch the error if proton is not initialized correctly

This commit is contained in:
ALEZ-DEV 2025-04-27 16:45:20 +02:00
parent 6e1b7ac461
commit 8804bec06c
2 changed files with 31 additions and 19 deletions

View File

@ -25,22 +25,26 @@ use crate::ui::{
static PROTON: OnceCell<Proton> = OnceCell::const_new(); static PROTON: OnceCell<Proton> = OnceCell::const_new();
pub async fn get_proton() -> Proton { pub async fn get_proton() -> anyhow::Result<Proton> {
PROTON if !PROTON.initialized() {
.get_or_init(|| async { let proton_component = ProtonComponent::new(GameConfig::get_config().await.config_dir);
let proton_component = ProtonComponent::new(GameConfig::get_config().await.config_dir); let proton = proton_component.init_proton();
let proton = proton_component.init_proton();
if let Err(ref e) = proton { if let Err(ref e) = proton {
error!("Failed to initialize proton : {}", e); anyhow::bail!("Failed to initialize proton : {}", e);
} }
proton.unwrap()
}) Ok(PROTON
.await .get_or_init(|| async { proton.unwrap() })
.clone() .await
.clone())
} else {
Ok(PROTON.get().unwrap().clone())
}
} }
pub async fn run_game() -> anyhow::Result<()> { pub async fn run_game() -> anyhow::Result<()> {
let proton = get_proton().await; let proton = get_proton().await?;
let game_dir = GameConfig::get_config().await.game_dir; let game_dir = GameConfig::get_config().await.game_dir;
if game_dir.is_none() { if game_dir.is_none() {
anyhow::bail!("Failed to start game, the game directory was not found"); anyhow::bail!("Failed to start game, the game directory was not found");
@ -277,7 +281,15 @@ impl Worker for HandleComponentInstallation {
let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("DXVK"))); let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("DXVK")));
if let Err(error) = GameManager::install_dxvk(&get_proton().await, game_dir, dxvk_release, Some(progress_bar.clone())).await { let proton = match get_proton().await {
Ok(p) => p,
Err(e) => {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to initialize proton : {:?}", e))).unwrap();
return;
}
};
if let Err(error) = GameManager::install_dxvk(&proton, game_dir, dxvk_release, Some(progress_bar.clone())).await {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install DXVK : {}", error))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install DXVK : {}", error))).unwrap();
return; return;
} }
@ -289,7 +301,7 @@ impl Worker for HandleComponentInstallation {
let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("fonts"))); let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("fonts")));
if let Err(error) = GameManager::install_font(&get_proton().await, Some(progress_bar.clone())).await { if let Err(error) = GameManager::install_font(&proton, Some(progress_bar.clone())).await {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install fonts : {}", error))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install fonts : {}", error))).unwrap();
return; return;
} }
@ -301,7 +313,7 @@ impl Worker for HandleComponentInstallation {
let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("denpendecies"))); let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("denpendecies")));
if let Err(error) = GameManager::install_dependencies(&get_proton().await).await { if let Err(error) = GameManager::install_dependencies(&proton).await {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install dependencies : {}", error))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install dependencies : {}", error))).unwrap();
return; return;
} }

View File

@ -162,12 +162,12 @@ impl GameManager {
debug!("Wine version : {:?}", proton_version); debug!("Wine version : {:?}", proton_version);
let mut child = if let Some(custom_command) = options { let mut child = if let Some(custom_command) = options {
Self::run(proton, binary_path, Some(custom_command)).await? Self::run(proton, binary_path, Some(custom_command)).await??
} else { } else {
if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() { if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() {
Self::run(proton, binary_path, Some(custom_command)).await? Self::run(proton, binary_path, Some(custom_command)).await??
} else { } else {
Self::run(proton, binary_path, None).await? Self::run(proton, binary_path, None).await??
} }
}?; }?;