Fix UI not updating when connecting to room fails

This commit is contained in:
Joscha 2022-08-20 23:18:07 +02:00
parent 6c637390e4
commit 2201e04e15

View file

@ -30,6 +30,7 @@ pub enum EuphRoomEvent {
Connected, Connected,
Disconnected, Disconnected,
Packet(Box<ParsedPacket>), Packet(Box<ParsedPacket>),
Stopped,
} }
#[derive(Debug)] #[derive(Debug)]
@ -77,6 +78,11 @@ impl State {
if let Err(e) = result { if let Err(e) = result {
error!("e&{name}: {}", e); error!("e&{name}: {}", e);
} }
// Ensure that whoever is using this room knows that it's gone.
// Otherwise, the users of the Room may be left in an inconsistent or
// outdated state, and the UI may not update correctly.
let _ = euph_room_event_tx.send(EuphRoomEvent::Stopped);
} }
async fn reconnect( async fn reconnect(
@ -98,6 +104,7 @@ impl State {
event_tx.send(Event::Disconnected)?; event_tx.send(Event::Disconnected)?;
} else { } else {
info!("e&{}: could not connect", name); info!("e&{}: could not connect", name);
event_tx.send(Event::Disconnected)?;
} }
tokio::time::sleep(Duration::from_secs(5)).await; // TODO Make configurable tokio::time::sleep(Duration::from_secs(5)).await; // TODO Make configurable
} }