Added working wine downloading with unpacking progress bar

This commit is contained in:
Observer KRypt0n_ 2022-07-14 22:34:01 +02:00
parent c3413cef12
commit 8de240d5a0
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
4 changed files with 34 additions and 10 deletions

View file

@ -18,3 +18,4 @@ serde_json = "1.0"
dirs = "4.0.0" dirs = "4.0.0"
tokio = { version = "1.19.2", features = ["rt", "rt-multi-thread", "macros"] } tokio = { version = "1.19.2", features = ["rt", "rt-multi-thread", "macros"] }
wait_not_await = "0.2.1"

@ -1 +1 @@
Subproject commit 527a8d12e6e9fcea7bb696254657c937cb2e7f86 Subproject commit 8a0dd62b38a0e1c0847a2665fe49961d4ed2a25d

View file

@ -7,9 +7,17 @@ use gtk::Align;
use std::path::Path; use std::path::Path;
use anime_game_core::prelude::*; use anime_game_core::prelude::*;
use wait_not_await::Await;
use crate::lib::wine::Version; use crate::lib::wine::Version;
#[derive(Debug)]
pub enum DownloadingResult {
DownloadingError(std::io::Error),
UnpackingError,
Done
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct WineRow { pub struct WineRow {
pub version: Version, pub version: Version,
@ -69,13 +77,15 @@ impl WineRow {
/// Download wine /// Download wine
/// ///
/// This method doesn't update components states, so you need to call `update_state` method manually /// This method doesn't update components states, so you need to call `update_state` method manually
pub fn download<T: ToString>(&self, runners_folder: T) -> Result<(), std::io::Error> { pub fn download<T: ToString>(&self, runners_folder: T) -> Result<Await<DownloadingResult>, std::io::Error> {
let (sender, receiver) = glib::MainContext::channel::<InstallerUpdate>(glib::PRIORITY_DEFAULT); let (sender, receiver) = glib::MainContext::channel::<InstallerUpdate>(glib::PRIORITY_DEFAULT);
let this = self.clone(); let this = self.clone();
this.progress_bar.set_visible(true); this.progress_bar.set_visible(true);
this.button.set_visible(false); this.button.set_visible(false);
let (downl_send, downl_recv) = std::sync::mpsc::channel();
receiver.attach(None, move |state| { receiver.attach(None, move |state| {
match state { match state {
InstallerUpdate::DownloadingStarted(_) => (), InstallerUpdate::DownloadingStarted(_) => (),
@ -99,11 +109,17 @@ impl WineRow {
InstallerUpdate::UnpackingFinished => { InstallerUpdate::UnpackingFinished => {
this.progress_bar.set_visible(false); this.progress_bar.set_visible(false);
this.button.set_visible(true); this.button.set_visible(true);
downl_send.send(DownloadingResult::Done);
}, },
// TODO: proper handling InstallerUpdate::DownloadingError(err) => {
InstallerUpdate::DownloadingError(err) => panic!("Failed to download wine: {}", err), downl_send.send(DownloadingResult::DownloadingError(err.into()));
InstallerUpdate::UnpackingError => panic!("Failed to unpack wine") },
InstallerUpdate::UnpackingError => {
downl_send.send(DownloadingResult::UnpackingError);
}
} }
glib::Continue(true) glib::Continue(true)
@ -124,6 +140,11 @@ impl WineRow {
}); });
}); });
Ok(()) Ok(Await::new(move || {
downl_recv.recv().unwrap()
}))
} }
} }
unsafe impl Send for WineRow {}
unsafe impl Sync for WineRow {}

View file

@ -241,12 +241,14 @@ impl App {
Actions::DownloadWine(version) => { Actions::DownloadWine(version) => {
let config = config::get().expect("Failed to load config"); let config = config::get().expect("Failed to load config");
let component = &this.widgets let component = this.widgets
.wine_components[version.0] .wine_components[version.0]
.version_components[version.1]; .version_components[version.1].clone();
if let Ok(_) = component.download(&config.game.wine.builds) { if let Ok(awaiter) = component.download(&config.game.wine.builds) {
component.update_state(&config.game.wine.builds); awaiter.then(move |_| {
component.update_state(&config.game.wine.builds);
});
} }
} }
} }