Fix UI version hanging on image download (#40)

Done by using task::spawn_blocking and blockon
This commit is contained in:
Philip Kristoffersen
2022-03-13 22:30:33 +01:00
committed by GitHub
parent 1729562885
commit 7f93ba6acd
5 changed files with 86 additions and 40 deletions
+1 -3
View File
@@ -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,
@@ -50,8 +50,6 @@ impl Settings {
sanitize_auth_key(&mut result);
result
}
+1 -1
View File
@@ -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>,
+14 -5
View File
@@ -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"),
}
});
}
@@ -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();
}
@@ -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);
}