implement config with auto-connect option
This commit is contained in:
parent
a938d39dc5
commit
18e907386d
69
src/main.rs
69
src/main.rs
|
@ -113,7 +113,7 @@ impl Deref for Client {
|
||||||
async fn main() -> iced::Result {
|
async fn main() -> iced::Result {
|
||||||
tracing_subscriber::fmt::init();
|
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 entry = Entry::new("macaw", "macaw");
|
||||||
let mut client_creation_error: Option<Error> = None;
|
let mut client_creation_error: Option<Error> = None;
|
||||||
let mut creds: Option<Creds> = 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 {
|
if let Some((jid, luz_handle, update_recv)) = client {
|
||||||
let stream = ReceiverStream::new(update_recv);
|
let stream = ReceiverStream::new(update_recv);
|
||||||
let stream = stream.map(|message| Message::Luz(message));
|
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(|| {
|
iced::application("Macaw", Macaw::update, Macaw::view).run_with(|| {
|
||||||
(
|
(
|
||||||
Macaw::new(
|
Macaw::new(
|
||||||
|
@ -179,7 +186,7 @@ async fn main() -> iced::Result {
|
||||||
cfg,
|
cfg,
|
||||||
),
|
),
|
||||||
// TODO: autoconnect config
|
// TODO: autoconnect config
|
||||||
Task::stream(stream),
|
task,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -322,24 +329,46 @@ impl Macaw {
|
||||||
self.client = Account::LoggedIn(client.clone());
|
self.client = Account::LoggedIn(client.clone());
|
||||||
let client1 = client.clone();
|
let client1 = client.clone();
|
||||||
let client2 = client.clone();
|
let client2 = client.clone();
|
||||||
Task::batch([
|
if self.config.auto_connect {
|
||||||
Task::perform(async move { client1.client.get_roster().await }, |result| {
|
Task::batch([
|
||||||
let roster = result.unwrap();
|
Task::perform(async move { client1.client.get_roster().await }, |result| {
|
||||||
let mut macaw_roster = HashMap::new();
|
let roster = result.unwrap();
|
||||||
for contact in roster {
|
let mut macaw_roster = HashMap::new();
|
||||||
macaw_roster.insert(contact.user_jid.clone(), contact);
|
for contact in roster {
|
||||||
}
|
macaw_roster.insert(contact.user_jid.clone(), contact);
|
||||||
Message::Roster(macaw_roster)
|
}
|
||||||
}),
|
Message::Roster(macaw_roster)
|
||||||
Task::perform(async move { client2.client.get_chats().await }, |chats| {
|
}),
|
||||||
let chats = chats.unwrap();
|
Task::perform(async move { client2.client.get_chats().await }, |chats| {
|
||||||
// let chats: HashMap<JID, (Chat, IndexMap<Uuid, ChatMessage>)> = chats
|
let chats = chats.unwrap();
|
||||||
// .into_iter()
|
// let chats: HashMap<JID, (Chat, IndexMap<Uuid, ChatMessage>)> = chats
|
||||||
// .map(|chat| (chat.correspondent.clone(), (chat, IndexMap::new())))
|
// .into_iter()
|
||||||
// .collect();
|
// .map(|chat| (chat.correspondent.clone(), (chat, IndexMap::new())))
|
||||||
Message::GotChats(chats)
|
// .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) => {
|
Message::Roster(hash_map) => {
|
||||||
self.roster = hash_map;
|
self.roster = hash_map;
|
||||||
|
|
Loading…
Reference in New Issue