Reworked components downloading during initial setup

now lots of stuff happens in separate threads and launcher shouldn't freeze
also fixed sometimes weird progress bar behavior
This commit is contained in:
Observer KRypt0n_ 2022-08-25 08:32:01 +02:00
parent 4843b6f537
commit 24673fd836
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2

View file

@ -242,7 +242,8 @@ impl App {
this.widgets.download_components.progress_bar.show(); this.widgets.download_components.progress_bar.show();
let (sender, receiver) = glib::MainContext::channel::<InstallerUpdate>(glib::PRIORITY_DEFAULT); let (sender_wine, receiver_wine) = glib::MainContext::channel::<InstallerUpdate>(glib::PRIORITY_DEFAULT);
let (sender_dxvk, receiver_dxvk) = glib::MainContext::channel::<InstallerUpdate>(glib::PRIORITY_DEFAULT);
let progress_bar = this.widgets.download_components.progress_bar.clone(); let progress_bar = this.widgets.download_components.progress_bar.clone();
@ -252,7 +253,7 @@ impl App {
let wine_version_copy = wine_version.clone(); let wine_version_copy = wine_version.clone();
let this_copy = this.clone(); let this_copy = this.clone();
// Download wine // Prepare wine downloader
std::thread::spawn(move || { std::thread::spawn(move || {
let config = config::get().unwrap(); let config = config::get().unwrap();
@ -262,8 +263,10 @@ impl App {
installer.temp_folder = temp_folder; installer.temp_folder = temp_folder;
} }
// Download wine
#[allow(unused_must_use)]
installer.install(&config.game.wine.builds, move |state| { installer.install(&config.game.wine.builds, move |state| {
sender.send(state).unwrap(); sender_wine.send(state);
}); });
}, },
Err(err) => { Err(err) => {
@ -274,15 +277,18 @@ impl App {
} }
}); });
let this = this.clone(); // Display wine downloading progress
let progress_bar_copy = progress_bar.clone();
let dxvk_version_copy = dxvk_version.clone();
// Download wine (had to do so this way) let this_copy = this.clone();
receiver.attach(None, move |state| {
match progress_bar.update_from_state(state) { receiver_wine.attach(None, move |state| {
match progress_bar_copy.update_from_state(state) {
ProgressUpdateResult::Updated => (), ProgressUpdateResult::Updated => (),
ProgressUpdateResult::Error(msg, err) => { ProgressUpdateResult::Error(msg, err) => {
this.update(Actions::Toast(Rc::new((msg, err.to_string())))).unwrap(); this_copy.toast(msg, err);
}, },
ProgressUpdateResult::Finished => { ProgressUpdateResult::Finished => {
@ -295,6 +301,12 @@ impl App {
config::update_raw(config.clone()).unwrap(); config::update_raw(config.clone()).unwrap();
// Create wine prefix // Create wine prefix
let this = this_copy.clone();
let wine_version = wine_version.clone();
let dxvk_version = dxvk_version_copy.clone();
let sender_dxvk = sender_dxvk.clone();
std::thread::spawn(move || {
match prefix.update(&config.game.wine.builds, wine_version.clone()) { match prefix.update(&config.game.wine.builds, wine_version.clone()) {
Ok(output) => { Ok(output) => {
println!("Wine prefix created:\n\n{}", String::from_utf8_lossy(&output.stdout)); println!("Wine prefix created:\n\n{}", String::from_utf8_lossy(&output.stdout));
@ -306,21 +318,53 @@ impl App {
installer.temp_folder = temp_folder; installer.temp_folder = temp_folder;
} }
let dxvk_version = dxvk_version.clone(); // Download DXVK
let progress_bar = progress_bar.clone(); #[allow(unused_must_use)]
installer.install(&config.game.dxvk.builds, move |state| {
sender_dxvk.send(state);
});
},
Err(err) => {
this.update(Actions::Toast(Rc::new((
String::from("Failed to init DXVK downloader"), err.to_string()
)))).unwrap();
}
}
},
Err(err) => {
this.update(Actions::Toast(Rc::new((
String::from("Failed to create wine prefix"), err.to_string()
)))).unwrap();
}
}
});
return glib::Continue(false);
}
}
glib::Continue(true)
});
// Display DXVK downloading progress
let this = this.clone(); let this = this.clone();
// Download DXVK receiver_dxvk.attach(None, move |state| {
installer.install(&config.game.dxvk.builds, move |state| {
match progress_bar.update_from_state(state) { match progress_bar.update_from_state(state) {
ProgressUpdateResult::Updated => (), ProgressUpdateResult::Updated => (),
ProgressUpdateResult::Error(_, _) => todo!(),
ProgressUpdateResult::Error(msg, err) => {
this.toast(msg, err);
},
ProgressUpdateResult::Finished => { ProgressUpdateResult::Finished => {
let mut config = config::get().unwrap(); let mut config = config::get().unwrap();
// Apply DXVK // Apply DXVK
let this = this.clone();
let dxvk_version = dxvk_version.clone();
std::thread::spawn(move || {
match dxvk_version.apply(&config.game.dxvk.builds, &config.game.wine.prefix) { match dxvk_version.apply(&config.game.dxvk.builds, &config.game.wine.prefix) {
Ok(output) => { Ok(output) => {
println!("Applied DXVK:\n\n{}", String::from_utf8_lossy(&output.stdout)); println!("Applied DXVK:\n\n{}", String::from_utf8_lossy(&output.stdout));
@ -344,23 +388,9 @@ impl App {
)))).unwrap(); )))).unwrap();
} }
} }
}
}
}); });
},
Err(err) => { return glib::Continue(false);
this.update(Actions::Toast(Rc::new((
String::from("Failed to init DXVK downloader"), err.to_string()
)))).unwrap();
}
}
},
Err(err) => {
this.update(Actions::Toast(Rc::new((
String::from("Failed to create wine prefix"), err.to_string()
)))).unwrap();
}
}
} }
} }