From 59d0e27ca3b63308e94e092c92c9fd30ec0340dd Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Thu, 16 Mar 2023 14:27:53 +0200 Subject: [PATCH] fix: fixed "wine not installed" button work --- src/ui/main.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/ui/main.rs b/src/ui/main.rs index d8c29ca..a2038e8 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -1097,17 +1097,34 @@ impl SimpleComponent for App { let mut config = config::get().unwrap(); match wine::get_downloaded(&CONFIG.components.path, &config.game.wine.builds) { - Ok(list) => { - // FIXME: .find(|version| version.recommended) - if !list.is_empty() { - config.game.wine.selected = Some(list[0].name.clone()); + Ok(downloaded) => { + // Select downloaded version + if !downloaded.is_empty() { + config.game.wine.selected = Some(downloaded[0].name.clone()); config::update(config.clone()); + + sender.input(AppMsg::UpdateLauncherState { + perform_on_download_needed: false, + show_status_page: true + }); } - if config.game.wine.selected.is_none() { - let wine = wine::Version::latest(&CONFIG.components.path).expect("Failed to get latest wine version"); + // Or download new one if none is available + else { + let latest = wine::Version::latest(&CONFIG.components.path).expect("Failed to get latest wine version"); + // Choose selected wine version or use latest available one + let wine = match &config.game.wine.selected { + Some(version) => match wine::Version::find_in(&config.components.path, version) { + Ok(Some(version)) => version, + _ => latest + } + + None => latest + }; + + // Download wine version match Installer::new(wine.uri) { Ok(mut installer) => { if let Some(temp_folder) = &config.launcher.temp { @@ -1165,13 +1182,6 @@ impl SimpleComponent for App { Err(err) => self.toast(tr("wine-install-failed"), Some(err.to_string())) } } - - else { - sender.input(AppMsg::UpdateLauncherState { - perform_on_download_needed: false, - show_status_page: true - }); - } } Err(err) => self.toast(tr("downloaded-wine-list-failed"), Some(err.to_string()))