Skip to content

Commit

Permalink
IRC: unify disconnect logic and return an error when server shuts down (
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick authored Apr 9, 2024
1 parent 95ea9ce commit 82d68e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions src/core/irc/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl IRCActor {
.unwrap();
*irc_stream_sender.lock().unwrap() = Some(clt.sender());

let mut disconnected_by_user = false;
let mut stream = clt.stream().unwrap();
loop {
let (lock, cv) = &*arc;
Expand All @@ -130,10 +131,7 @@ impl IRCActor {
if *g {
*g = false;
clt.send_quit("").unwrap();
tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected { by_user: true },
))
.unwrap();
disconnected_by_user = true;
break;
}
}
Expand All @@ -148,25 +146,28 @@ impl IRCActor {
)),
))
.unwrap();
tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected { by_user: false },
))
.unwrap();
break;
}
Ok(msg) => {
event_handler::dispatch_message(&tx, msg, &own_username);
}
},
None => {
tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected { by_user: false },
))
tx.blocking_send(AppMessageIn::ChatError(IRCError::FatalError(
"remote server has closed the connection, probably because it went offline".to_owned(),
)))
.unwrap();
break;
}
}
}

tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected {
by_user: disconnected_by_user,
},
))
.unwrap();
}
}
}));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Menu {
ConnectionStatus::InProgress => ("connecting...".to_owned(), false),
ConnectionStatus::Scheduled(when) => {
let action = format!(
"reconnecting ({}s)",
"reconnect (or wait {}s)",
(when - chrono::Local::now()).num_seconds()
);
(action, true)
Expand Down

0 comments on commit 82d68e6

Please sign in to comment.