diff --git a/src/lib/dxvk.rs b/src/lib/dxvk.rs index 8a68e7e..77384ec 100644 --- a/src/lib/dxvk.rs +++ b/src/lib/dxvk.rs @@ -65,7 +65,7 @@ impl Version { std::path::Path::new(&format!("{}/{}", folder.to_string(), self.name)).exists() } - pub fn apply(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result<()> { + pub fn apply(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result { let apply_path = format!("{}/{}/setup_dxvk.sh", dxvks_folder.to_string(), self.name); let config = config::get()?; @@ -102,9 +102,12 @@ impl Version { .env("WINEPREFIX", prefix_path.to_string()) .output()?; - match output.status.success() { - true => Ok(()), - false => Err(Error::new(ErrorKind::Other, String::from_utf8_lossy(&output.stderr))) + if output.status.success() { + Ok(String::from_utf8(output.stdout).unwrap()) + } + + else { + Err(Error::new(ErrorKind::Other, String::from_utf8_lossy(&output.stderr))) } }, None => Err(Error::new(ErrorKind::Other, "Wine is not selected")) diff --git a/src/main.rs b/src/main.rs index 4be7c50..8b4e497 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ async fn main() { // Flush config from the memory to the file before closing the app application.connect_shutdown(|_| { - lib::config::flush().expect("Failed to save config data"); + lib::config::flush().expect("Failed to save config file"); }); // Run app diff --git a/src/ui/components/dxvk_row.rs b/src/ui/components/dxvk_row.rs index 41c0376..9f5d42e 100644 --- a/src/ui/components/dxvk_row.rs +++ b/src/ui/components/dxvk_row.rs @@ -73,7 +73,7 @@ impl DxvkRow { } } - pub fn apply(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result<()> { + pub fn apply(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result { self.button.set_sensitive(false); self.apply_button.set_sensitive(false); diff --git a/src/ui/main.rs b/src/ui/main.rs index fe9ce9b..921b143 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -190,6 +190,8 @@ impl App { Actions::PreferencesGoBack => { this.widgets.leaflet.navigate(adw::NavigationDirection::Back); + + config::flush().expect("Failed to save config file"); } Actions::PerformButtonEvent => { diff --git a/src/ui/preferences/general_page.rs b/src/ui/preferences/general_page.rs index 04a0d88..7da5161 100644 --- a/src/ui/preferences/general_page.rs +++ b/src/ui/preferences/general_page.rs @@ -258,10 +258,13 @@ impl App { std::thread::spawn(clone!(@strong component, @strong this => move || { let config = config::get().expect("Failed to load config"); - if let Err(err) = component.apply(config.game.dxvk.builds, config.game.wine.prefix) { - this.update(Actions::ToastError(Rc::new(( - String::from("Failed to apply DXVK"), err - )))).unwrap(); + match component.apply(&config.game.dxvk.builds, &config.game.wine.prefix) { + Ok(output) => println!("{}", output), + Err(err) => { + this.update(Actions::ToastError(Rc::new(( + String::from("Failed to apply DXVK"), err + )))).unwrap(); + } } })); })); @@ -304,10 +307,13 @@ impl App { else { if let Ok(awaiter) = component.download(&config.game.dxvk.builds) { awaiter.then(clone!(@strong this => move |_| { - if let Err(err) = component.apply(&config.game.dxvk.builds, &config.game.wine.prefix) { - this.update(Actions::ToastError(Rc::new(( - String::from("Failed to apply DXVK"), err - )))).unwrap(); + match component.apply(&config.game.dxvk.builds, &config.game.wine.prefix) { + Ok(output) => println!("{}", output), + Err(err) => { + this.update(Actions::ToastError(Rc::new(( + String::from("Failed to apply DXVK"), err + )))).unwrap(); + } } component.update_state(&config.game.dxvk.builds); @@ -375,11 +381,16 @@ impl App { this.values.set(values); + // This will prevent SelectDxvkVersion action to be invoked + let guard = this.widgets.dxvk_selected.freeze_notify(); + // We need to return app values before we call these methods // because they'll invoke SelectWineVersion action so access // downloaded_wine_versions value this.widgets.dxvk_selected.set_model(Some(&model)); this.widgets.dxvk_selected.set_selected(selected); + + drop(guard); } Actions::SelectDxvkVersion(i) => { @@ -387,15 +398,21 @@ impl App { if let Some(dxvk_versions) = &*values.downloaded_dxvk_versions { let version = dxvk_versions[*i].clone(); - - config.game.dxvk.selected = Some(version.name.clone()); - // FIXME: this calls every time we update dxvks comborow - /*if let Err(err) = version.apply(&config.game.dxvk.builds, &config.game.wine.prefix) { - this.update(Actions::ToastError(Rc::new(( - String::from("Failed to apply DXVK"), err - )))); - }*/ + if config.game.dxvk.selected != Some(version.name.clone()) { + config.game.dxvk.selected = Some(version.name.clone()); + + std::thread::spawn(clone!(@strong config, @strong this => move || { + match version.apply(&config.game.dxvk.builds, &config.game.wine.prefix) { + Ok(output) => println!("{}", output), + Err(err) => { + this.update(Actions::ToastError(Rc::new(( + String::from("Failed to apply DXVK"), err + )))).unwrap(); + } + } + })); + } } this.values.set(values); @@ -427,11 +444,16 @@ impl App { this.values.set(values); + // This will prevent SelectWineVersion action to be invoked + let guard = this.widgets.wine_selected.freeze_notify(); + // We need to return app values before we call these methods // because they'll invoke SelectWineVersion action so access // downloaded_wine_versions value this.widgets.wine_selected.set_model(Some(&model)); this.widgets.wine_selected.set_selected(selected); + + drop(guard); } Actions::SelectWineVersion(i) => {