mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-11-29 18:38:48 +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();
|
||||
|
||||
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();
|
||||
|
||||
|
@ -252,7 +253,7 @@ impl App {
|
|||
let wine_version_copy = wine_version.clone();
|
||||
let this_copy = this.clone();
|
||||
|
||||
// Download wine
|
||||
// Prepare wine downloader
|
||||
std::thread::spawn(move || {
|
||||
let config = config::get().unwrap();
|
||||
|
||||
|
@ -262,8 +263,10 @@ impl App {
|
|||
installer.temp_folder = temp_folder;
|
||||
}
|
||||
|
||||
// Download wine
|
||||
#[allow(unused_must_use)]
|
||||
installer.install(&config.game.wine.builds, move |state| {
|
||||
sender.send(state).unwrap();
|
||||
sender_wine.send(state);
|
||||
});
|
||||
},
|
||||
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)
|
||||
receiver.attach(None, move |state| {
|
||||
match progress_bar.update_from_state(state) {
|
||||
let this_copy = this.clone();
|
||||
|
||||
receiver_wine.attach(None, move |state| {
|
||||
match progress_bar_copy.update_from_state(state) {
|
||||
ProgressUpdateResult::Updated => (),
|
||||
|
||||
ProgressUpdateResult::Error(msg, err) => {
|
||||
this.update(Actions::Toast(Rc::new((msg, err.to_string())))).unwrap();
|
||||
this_copy.toast(msg, err);
|
||||
},
|
||||
|
||||
ProgressUpdateResult::Finished => {
|
||||
|
@ -295,6 +301,12 @@ impl App {
|
|||
config::update_raw(config.clone()).unwrap();
|
||||
|
||||
// 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()) {
|
||||
Ok(output) => {
|
||||
println!("Wine prefix created:\n\n{}", String::from_utf8_lossy(&output.stdout));
|
||||
|
@ -306,21 +318,53 @@ impl App {
|
|||
installer.temp_folder = temp_folder;
|
||||
}
|
||||
|
||||
let dxvk_version = dxvk_version.clone();
|
||||
let progress_bar = progress_bar.clone();
|
||||
// Download DXVK
|
||||
#[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();
|
||||
|
||||
// Download DXVK
|
||||
installer.install(&config.game.dxvk.builds, move |state| {
|
||||
receiver_dxvk.attach(None, move |state| {
|
||||
match progress_bar.update_from_state(state) {
|
||||
ProgressUpdateResult::Updated => (),
|
||||
ProgressUpdateResult::Error(_, _) => todo!(),
|
||||
|
||||
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));
|
||||
|
@ -344,23 +388,9 @@ impl App {
|
|||
)))).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();
|
||||
}
|
||||
}
|
||||
|
||||
return glib::Continue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue