diff options
-rw-r--r-- | gui/src/app/message.rs | 4 | ||||
-rw-r--r-- | gui/src/app/mod.rs | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/gui/src/app/message.rs b/gui/src/app/message.rs index 68c95d5..f19a2dd 100644 --- a/gui/src/app/message.rs +++ b/gui/src/app/message.rs @@ -13,6 +13,8 @@ use crate::gossip::GossipRecipe; pub enum Message { Loaded(Arc<RwLock<Profile>>), FailedToLoad(String), + ProfileStateSaved, + ProfileStateSavingFailed(String), ToggleLog, @@ -40,6 +42,8 @@ impl Message { match self { Message::Loaded(_) => "Loaded", Message::FailedToLoad(_) => "FailedToLoad", + Message::ProfileStateSaved => "ProfileStateSaved", + Message::ProfileStateSavingFailed(_) => "ProfileStateSavingFailed", Message::ToggleLog => "ToggleLog", diff --git a/gui/src/app/mod.rs b/gui/src/app/mod.rs index f51581b..a1428cd 100644 --- a/gui/src/app/mod.rs +++ b/gui/src/app/mod.rs @@ -136,9 +136,27 @@ impl Application for Distrox { Message::PostCreated(cid) => { *input_value = String::new(); log::info!("Post created: {}", cid); - iced::Command::none() + + let profile = profile.clone(); + iced::Command::perform(async move { + if let Err(e) = profile.read().await.save().await { + Message::ProfileStateSavingFailed(e.to_string()) + } else { + Message::ProfileStateSaved + } + }, |m: Message| -> Message { m }) } + Message::ProfileStateSaved => { + log::info!("Profile state saved"); + iced::Command::none() + }, + + Message::ProfileStateSavingFailed(e) => { + log::error!("Saving profile failed: {}", e); + iced::Command::none() + }, + Message::PostCreationFailed(err) => { log::error!("Post creation failed: {}", err); iced::Command::none() |