From 2300a0a871ad8e2de528bfcd4d53d1df812fd5d9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 21 Dec 2021 11:38:56 +0100 Subject: Add saving of profile state Signed-off-by: Matthias Beyer --- gui/src/app/message.rs | 4 ++++ gui/src/app/mod.rs | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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>), 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() -- cgit v1.2.3