Skip to content

Commit

Permalink
Fix UI version hanging on image download (#40)
Browse files Browse the repository at this point in the history
Done by using task::spawn_blocking and blockon
  • Loading branch information
PhilipK authored Mar 13, 2022
1 parent 1729562 commit 7f93ba6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 40 deletions.
99 changes: 69 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ steam_shortcuts_util = "^1.1.4"
steamgriddb_api = "^0.2,0"
serde = { version = "^1.0.130", features = ["derive"] }
serde_json = "^1.0.68"
tokio = { version = "^1.11.0", features = ["full"] }
tokio = { version = "^1.17.0", features = ["full"] }
reqwest = { version = "^0.11.4", default_features = false }
config = "^0.11.0"
failure = "^0.1.8"
Expand Down
4 changes: 1 addition & 3 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use config::{Config, ConfigError, Environment, File};
use serde::{Deserialize, Serialize};
use std::env;

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Settings {
pub debug: bool,
pub epic_games: EpicGamesLauncherSettings,
Expand Down Expand Up @@ -50,8 +50,6 @@ impl Settings {

sanitize_auth_key(&mut result);



result
}

Expand Down
2 changes: 1 addition & 1 deletion src/steamgriddb/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize,Clone)]
pub struct SteamGridDbSettings {
pub enabled: bool,
pub auth_key: Option<String>,
Expand Down
19 changes: 14 additions & 5 deletions src/ui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ pub async fn run_ui() -> Result<(), Box<dyn Error>> {
let synch_ui = ui.clone();
let sync_settings = settings.clone();
synch_bytton.set_callback(move |cb| {
update_settings_with_ui_values(&mut sync_settings.borrow_mut(), &synch_ui);
match block_on(run_sync(&sync_settings.borrow())) {
let mut settings_clone = sync_settings.borrow().clone();
update_settings_with_ui_values(&mut settings_clone, &synch_ui);
use tokio::task;
let task = task::spawn_blocking(move || {
let setting_ref = settings_clone.clone();
let synchro_task = run_sync(&setting_ref);
match block_on(synchro_task) {
Ok(_) => println!("Finished sync"),
Err(e) => println!("{}", e),
}
});
match block_on(task){
Ok(_) => cb.set_label("Synched"),
Err(e) => println!("{}", e),
Err(_) => cb.set_label("Error Synching"),
}
});
}
Expand Down Expand Up @@ -78,7 +88,6 @@ fn update_settings_with_ui_values(settings: &mut Settings, ui: &UserInterface) {
settings.gog.location = empty_or_whitespace(ui.gog_folder_input.value());
settings.gog.wine_c_drive = empty_or_whitespace(ui.gog_winedrive_input.value());


// Uplay
settings.uplay.enabled = ui.enable_uplay_checkbox.value();
}
Expand Down Expand Up @@ -184,6 +193,6 @@ fn update_ui_with_settings(ui: &mut UserInterface, settings: &Settings) {
{
ui.gog_winedrive_input.hide();
}

ui.enable_uplay_checkbox.set_value(settings.uplay.enabled);
}

0 comments on commit 7f93ba6

Please sign in to comment.