Improved DXVK applying experience

This commit is contained in:
Observer KRypt0n_ 2022-07-24 22:04:35 +02:00
parent 737aa7e8bc
commit b1b6f2d68e
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
5 changed files with 49 additions and 22 deletions

View file

@ -65,7 +65,7 @@ impl Version {
std::path::Path::new(&format!("{}/{}", folder.to_string(), self.name)).exists()
}
pub fn apply<T: ToString>(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result<()> {
pub fn apply<T: ToString>(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result<String> {
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"))

View file

@ -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

View file

@ -73,7 +73,7 @@ impl DxvkRow {
}
}
pub fn apply<T: ToString>(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result<()> {
pub fn apply<T: ToString>(&self, dxvks_folder: T, prefix_path: T) -> std::io::Result<String> {
self.button.set_sensitive(false);
self.apply_button.set_sensitive(false);

View file

@ -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 => {

View file

@ -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) => {