summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-12-21 11:38:56 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-12-21 11:38:56 +0100
commit2300a0a871ad8e2de528bfcd4d53d1df812fd5d9 (patch)
tree5ce32bb1c94a39ebaac55f2c4ec0b0dee35dd49d
parent5a86b1e44467f1d5439fe6f447c55f33c35f564f (diff)
Add saving of profile state
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--gui/src/app/message.rs4
-rw-r--r--gui/src/app/mod.rs20
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()