mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2025-04-04 15:55:27 +03:00
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:
parent
4843b6f537
commit
24673fd836
1 changed files with 99 additions and 69 deletions
|
@ -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,72 +301,96 @@ impl App {
|
||||||
config::update_raw(config.clone()).unwrap();
|
config::update_raw(config.clone()).unwrap();
|
||||||
|
|
||||||
// Create wine prefix
|
// Create wine prefix
|
||||||
match prefix.update(&config.game.wine.builds, wine_version.clone()) {
|
let this = this_copy.clone();
|
||||||
Ok(output) => {
|
let wine_version = wine_version.clone();
|
||||||
println!("Wine prefix created:\n\n{}", String::from_utf8_lossy(&output.stdout));
|
let dxvk_version = dxvk_version_copy.clone();
|
||||||
|
let sender_dxvk = sender_dxvk.clone();
|
||||||
|
|
||||||
// Prepare DXVK downloader
|
std::thread::spawn(move || {
|
||||||
match Installer::new(&dxvk_version.uri) {
|
match prefix.update(&config.game.wine.builds, wine_version.clone()) {
|
||||||
Ok(mut installer) => {
|
Ok(output) => {
|
||||||
if let Some(temp_folder) = config.launcher.temp {
|
println!("Wine prefix created:\n\n{}", String::from_utf8_lossy(&output.stdout));
|
||||||
installer.temp_folder = temp_folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
let dxvk_version = dxvk_version.clone();
|
// Prepare DXVK downloader
|
||||||
let progress_bar = progress_bar.clone();
|
match Installer::new(&dxvk_version.uri) {
|
||||||
|
Ok(mut installer) => {
|
||||||
let this = this.clone();
|
if let Some(temp_folder) = config.launcher.temp {
|
||||||
|
installer.temp_folder = temp_folder;
|
||||||
// Download DXVK
|
|
||||||
installer.install(&config.game.dxvk.builds, move |state| {
|
|
||||||
match progress_bar.update_from_state(state) {
|
|
||||||
ProgressUpdateResult::Updated => (),
|
|
||||||
ProgressUpdateResult::Error(_, _) => todo!(),
|
|
||||||
|
|
||||||
ProgressUpdateResult::Finished => {
|
|
||||||
let mut config = config::get().unwrap();
|
|
||||||
|
|
||||||
// Apply DXVK
|
|
||||||
match dxvk_version.apply(&config.game.dxvk.builds, &config.game.wine.prefix) {
|
|
||||||
Ok(output) => {
|
|
||||||
println!("Applied DXVK:\n\n{}", String::from_utf8_lossy(&output.stdout));
|
|
||||||
|
|
||||||
// Update dxvk config
|
|
||||||
config.game.dxvk.selected = Some(dxvk_version.name.clone());
|
|
||||||
|
|
||||||
config::update_raw(config.clone()).unwrap();
|
|
||||||
|
|
||||||
// Remove .first-run file
|
|
||||||
let launcher_dir = crate::lib::consts::launcher_dir().unwrap();
|
|
||||||
|
|
||||||
std::fs::remove_file(format!("{}/.first-run", launcher_dir)).unwrap();
|
|
||||||
|
|
||||||
// Show next page
|
|
||||||
this.update(Actions::DownloadComponentsContinue).unwrap();
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
this.update(Actions::Toast(Rc::new((
|
|
||||||
String::from("Failed to apply DXVK"), err.to_string()
|
|
||||||
)))).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
// Download DXVK
|
||||||
Err(err) => {
|
#[allow(unused_must_use)]
|
||||||
this.update(Actions::Toast(Rc::new((
|
installer.install(&config.game.dxvk.builds, move |state| {
|
||||||
String::from("Failed to init DXVK downloader"), err.to_string()
|
sender_dxvk.send(state);
|
||||||
)))).unwrap();
|
});
|
||||||
|
},
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
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();
|
||||||
|
|
||||||
|
receiver_dxvk.attach(None, move |state| {
|
||||||
|
match progress_bar.update_from_state(state) {
|
||||||
|
ProgressUpdateResult::Updated => (),
|
||||||
|
|
||||||
|
ProgressUpdateResult::Error(msg, err) => {
|
||||||
|
this.toast(msg, err);
|
||||||
|
},
|
||||||
|
|
||||||
|
ProgressUpdateResult::Finished => {
|
||||||
|
let mut config = config::get().unwrap();
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
Ok(output) => {
|
||||||
|
println!("Applied DXVK:\n\n{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
|
||||||
|
// Update dxvk config
|
||||||
|
config.game.dxvk.selected = Some(dxvk_version.name.clone());
|
||||||
|
|
||||||
|
config::update_raw(config.clone()).unwrap();
|
||||||
|
|
||||||
|
// Remove .first-run file
|
||||||
|
let launcher_dir = crate::lib::consts::launcher_dir().unwrap();
|
||||||
|
|
||||||
|
std::fs::remove_file(format!("{}/.first-run", launcher_dir)).unwrap();
|
||||||
|
|
||||||
|
// Show next page
|
||||||
|
this.update(Actions::DownloadComponentsContinue).unwrap();
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
this.update(Actions::Toast(Rc::new((
|
||||||
|
String::from("Failed to apply DXVK"), err.to_string()
|
||||||
|
)))).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return glib::Continue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue