aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-01 07:03:22 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-01 07:03:22 +0000
commit18e907386d629966236d0b6a30501f492133d2f6 (patch)
tree629aa1fdb781f082a02b307a111c1a73fa0e181c
parenta938d39dc5b21298f0d1c7829a87dbc8331917b6 (diff)
downloadmacaw-18e907386d629966236d0b6a30501f492133d2f6.tar.gz
macaw-18e907386d629966236d0b6a30501f492133d2f6.tar.bz2
macaw-18e907386d629966236d0b6a30501f492133d2f6.zip
implement config with auto-connect option
-rw-r--r--src/main.rs69
1 files changed, 49 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs
index 8e38e7b..558c608 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -113,7 +113,7 @@ impl Deref for Client {
async fn main() -> iced::Result {
tracing_subscriber::fmt::init();
- let cfg = confy::load("macaw", None).unwrap();
+ let cfg: Config = confy::load("macaw", None).unwrap();
let entry = Entry::new("macaw", "macaw");
let mut client_creation_error: Option<Error> = None;
let mut creds: Option<Creds> = None;
@@ -167,6 +167,13 @@ async fn main() -> iced::Result {
if let Some((jid, luz_handle, update_recv)) = client {
let stream = ReceiverStream::new(update_recv);
let stream = stream.map(|message| Message::Luz(message));
+ let task = {
+ if cfg.auto_connect {
+ Task::batch([Task::stream(stream), Task::done(Message::Connect)])
+ } else {
+ Task::stream(stream)
+ }
+ };
iced::application("Macaw", Macaw::update, Macaw::view).run_with(|| {
(
Macaw::new(
@@ -179,7 +186,7 @@ async fn main() -> iced::Result {
cfg,
),
// TODO: autoconnect config
- Task::stream(stream),
+ task,
)
})
} else {
@@ -322,24 +329,46 @@ impl Macaw {
self.client = Account::LoggedIn(client.clone());
let client1 = client.clone();
let client2 = client.clone();
- Task::batch([
- Task::perform(async move { client1.client.get_roster().await }, |result| {
- let roster = result.unwrap();
- let mut macaw_roster = HashMap::new();
- for contact in roster {
- macaw_roster.insert(contact.user_jid.clone(), contact);
- }
- Message::Roster(macaw_roster)
- }),
- Task::perform(async move { client2.client.get_chats().await }, |chats| {
- let chats = chats.unwrap();
- // let chats: HashMap<JID, (Chat, IndexMap<Uuid, ChatMessage>)> = chats
- // .into_iter()
- // .map(|chat| (chat.correspondent.clone(), (chat, IndexMap::new())))
- // .collect();
- Message::GotChats(chats)
- }),
- ])
+ if self.config.auto_connect {
+ Task::batch([
+ Task::perform(async move { client1.client.get_roster().await }, |result| {
+ let roster = result.unwrap();
+ let mut macaw_roster = HashMap::new();
+ for contact in roster {
+ macaw_roster.insert(contact.user_jid.clone(), contact);
+ }
+ Message::Roster(macaw_roster)
+ }),
+ Task::perform(async move { client2.client.get_chats().await }, |chats| {
+ let chats = chats.unwrap();
+ // let chats: HashMap<JID, (Chat, IndexMap<Uuid, ChatMessage>)> = chats
+ // .into_iter()
+ // .map(|chat| (chat.correspondent.clone(), (chat, IndexMap::new())))
+ // .collect();
+ Message::GotChats(chats)
+ }),
+ Task::done(Message::Connect),
+ ])
+ } else {
+ Task::batch([
+ Task::perform(async move { client1.client.get_roster().await }, |result| {
+ let roster = result.unwrap();
+ let mut macaw_roster = HashMap::new();
+ for contact in roster {
+ macaw_roster.insert(contact.user_jid.clone(), contact);
+ }
+ Message::Roster(macaw_roster)
+ }),
+ Task::perform(async move { client2.client.get_chats().await }, |chats| {
+ let chats = chats.unwrap();
+ // let chats: HashMap<JID, (Chat, IndexMap<Uuid, ChatMessage>)> = chats
+ // .into_iter()
+ // .map(|chat| (chat.correspondent.clone(), (chat, IndexMap::new())))
+ // .collect();
+ Message::GotChats(chats)
+ }),
+ ])
+ }
}
Message::Roster(hash_map) => {
self.roster = hash_map;