🔨 Refactor terminal route and connection logic

- Improved terminal experience by handling 'Close' messages and reloading the page
- Added logic to send a Close message to the websocket when EOF is reached
- Changed the `terminal` function to a reactive declaration and added a `setupTerminal` function call
This commit is contained in:
Kiril Videlov 2023-04-17 23:55:57 +02:00 committed by Kiril Videlov
parent f7a447ef61
commit 5d7064a6a1
3 changed files with 15 additions and 2 deletions

View File

@ -115,6 +115,16 @@ pub async fn accept_connection(
Ok(0) => {
// EOF
log::info!("0 bytes read from pty. EOF.");
if let Err(e) = ws_sender
.send(tokio_tungstenite::tungstenite::Message::Close(None))
.await
{
log::error!(
"{}: error sending data to websocket: {:#}",
shared_project_id,
e
);
}
break;
}
Ok(n) => {

View File

@ -17,7 +17,7 @@
const handleTerminalResize = debounce(() => term?.resize(), 5);
const runCommand = (command: string) => term?.run(command);
const terminal = (target: HTMLElement, params: { project: Project }) => {
$: terminal = (target: HTMLElement, params: { project: Project }) => {
let setupPromise = setupTerminal(params);
setupPromise.then((terminal) => (term = terminal));
setupPromise.then((terminal) => terminal.bind(target));

View File

@ -81,7 +81,10 @@ const newSession = async (params: { project: Project }) => {
});
conn.addListener((message) => {
message.type === 'Close' && term.dispose();
if (message.type === 'Close') {
term.dispose();
location.reload();
}
});
return {