Skip to content

Commit

Permalink
Fixed no carrier message & dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed May 27, 2024
1 parent 7ea9ca1 commit 64217f1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 50 deletions.
1 change: 0 additions & 1 deletion crates/icy_engine/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ impl Buffer {
}

pub fn reset_terminal(&mut self) {
println!("RESET TERM!");
if self.is_terminal_buffer {
let fixed = self.terminal_state.fixed_size;
self.terminal_state = TerminalState::from(self.original_size);
Expand Down
9 changes: 5 additions & 4 deletions crates/icy_term/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ impl MainWindow {
dialing_directory_dialog: dialogs::dialing_directory_dialog::DialogState::new(addresses),
drag_start: None,
last_pos: Position::default(),
buffer_update_thread,
update_thread_handle: Some(update_thread_handle),
terminal_thread: buffer_update_thread,
terminal_thread_handle: Some(update_thread_handle),
tx,
rx,
show_find_dialog: false,
Expand All @@ -122,6 +122,7 @@ impl MainWindow {
use_rip: false,
buffer_parser,
title: String::new(),
show_disconnect: false,
};

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -197,7 +198,7 @@ impl eframe::App for MainWindow {

MainWindowMode::FileTransfer(download) => {
self.update_terminal_window(ctx, frame, false);
let state = self.buffer_update_thread.lock().current_transfer.clone();
let state = self.terminal_thread.lock().current_transfer.clone();
// auto close uploads.
if !download && state.is_finished {
self.set_mode(ctx, MainWindowMode::ShowTerminal);
Expand All @@ -216,7 +217,7 @@ impl eframe::App for MainWindow {
}
MainWindowMode::ShowCaptureDialog => {
self.update_terminal_window(ctx, frame, false);
if !self.buffer_update_thread.lock().capture_dialog.show_caputure_dialog(ctx) {
if !self.terminal_thread.lock().capture_dialog.show_caputure_dialog(ctx) {
self.set_mode(ctx, MainWindowMode::ShowTerminal);
}
}
Expand Down
12 changes: 1 addition & 11 deletions crates/icy_term/src/ui/dialogs/show_iemsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ pub fn show_iemsi(window: &mut MainWindow, ctx: &egui::Context) {
open = false;
}
let window_frame = Frame::window(&ctx.style());
let iemsi = window
.buffer_update_thread
.lock()
.auto_login
.as_ref()
.unwrap()
.iemsi
.isi
.as_ref()
.unwrap()
.clone();
let iemsi = window.terminal_thread.lock().auto_login.as_ref().unwrap().iemsi.isi.as_ref().unwrap().clone();

egui::Window::new("")
.open(&mut open)
Expand Down
41 changes: 22 additions & 19 deletions crates/icy_term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub struct MainWindow {
shift_pressed_during_selection: bool,
use_rip: bool,

buffer_update_thread: Arc<egui::mutex::Mutex<TerminalThread>>,
update_thread_handle: Option<JoinHandle<()>>,
terminal_thread: Arc<egui::mutex::Mutex<TerminalThread>>,
terminal_thread_handle: Option<JoinHandle<()>>,
pub tx: mpsc::Sender<SendData>,
pub rx: mpsc::Receiver<SendData>,

Expand All @@ -123,6 +123,7 @@ pub struct MainWindow {

pub show_find_dialog: bool,
pub find_dialog: dialogs::find_dialog::DialogState,
show_disconnect: bool,
title: String,
buffer_parser: Box<dyn BufferParser>,
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -157,15 +158,15 @@ impl MainWindow {

pub fn output_char(&mut self, ch: char) {
let translated_char = self.buffer_view.lock().get_unicode_converter().convert_from_unicode(ch, 0);
if self.buffer_update_thread.lock().is_connected {
if self.terminal_thread.lock().is_connected {
self.send_vec(vec![translated_char as u8]);
} else {
self.print_char(translated_char as u8);
}
}

pub fn output_string(&mut self, str: &str) {
if self.buffer_update_thread.lock().is_connected {
if self.terminal_thread.lock().is_connected {
let mut v = Vec::new();
for ch in str.chars() {
let translated_char = self.buffer_view.lock().get_unicode_converter().convert_from_unicode(ch, 0);
Expand Down Expand Up @@ -198,7 +199,7 @@ impl MainWindow {
#[cfg(not(target_arch = "wasm32"))]
fn upload(&mut self, ctx: &egui::Context, protocol_type: TransferProtocolType, files: Vec<PathBuf>) {
use icy_net::protocol::TransferState;
self.buffer_update_thread.lock().current_transfer = TransferState::new(String::new());
self.terminal_thread.lock().current_transfer = TransferState::new(String::new());

self.set_mode(ctx, MainWindowMode::FileTransfer(false));
self.send_data(SendData::Upload(protocol_type, files));
Expand All @@ -208,7 +209,7 @@ impl MainWindow {

fn download(&mut self, ctx: &egui::Context, protocol_type: TransferProtocolType, file_name: Option<String>) {
use icy_net::protocol::TransferState;
self.buffer_update_thread.lock().current_transfer = TransferState::new(String::new());
self.terminal_thread.lock().current_transfer = TransferState::new(String::new());

self.set_mode(ctx, MainWindowMode::FileTransfer(true));
self.send_data(SendData::Download(protocol_type, file_name));
Expand Down Expand Up @@ -265,18 +266,18 @@ impl MainWindow {
(address.user_name.clone(), address.password.clone())
};

self.buffer_update_thread.lock().auto_login = if user_name.is_empty() || password.is_empty() {
self.terminal_thread.lock().auto_login = if user_name.is_empty() || password.is_empty() {
None
} else {
Some(AutoLogin::new(&cloned_addr.auto_login, user_name, password))
};

if let Some(rip_cache) = address.get_rip_cache() {
self.buffer_update_thread.lock().cache_directory = rip_cache;
self.terminal_thread.lock().cache_directory = rip_cache;
}

self.use_rip = matches!(address.terminal_type, TerminalEmulation::Rip);
self.buffer_update_thread.lock().terminal_type = Some((address.terminal_type, address.ansi_music));
self.terminal_thread.lock().terminal_type = Some((address.terminal_type, address.ansi_music));
self.buffer_view.lock().clear_reference_image();
self.buffer_view.lock().get_buffer_mut().layers[0].clear();
self.buffer_view.lock().get_buffer_mut().stop_sixel_threads();
Expand All @@ -302,12 +303,12 @@ impl MainWindow {

let data = OpenConnectionData::from(&cloned_addr, timeout, window_size, Some(self.get_options().modem.clone()));

if let Some(_handle) = self.update_thread_handle.take() {
if let Some(_handle) = self.terminal_thread_handle.take() {
self.send_data(SendData::Disconnect);
}
self.buffer_parser = get_parser(&data.term_caps.terminal, data.use_ansi_music, PathBuf::new());
let (update_thread_handle, tx, rx) = crate::ui::terminal_thread::start_update_thread(ctx, data, self.buffer_update_thread.clone());
self.update_thread_handle = Some(update_thread_handle);
let (update_thread_handle, tx, rx) = crate::ui::terminal_thread::start_update_thread(ctx, data, self.terminal_thread.clone());
self.terminal_thread_handle = Some(update_thread_handle);
self.tx = tx;
self.rx = rx;
self.send_data(SendData::SetBaudRate(cloned_addr.baud_emulation.get_baud_rate()));
Expand All @@ -322,8 +323,8 @@ impl MainWindow {

pub fn hangup(&mut self, ctx: &egui::Context) {
self.send_data(SendData::Disconnect);
self.update_thread_handle = None;
self.buffer_update_thread.lock().sound_thread.lock().clear();
self.terminal_thread_handle = None;
self.terminal_thread.lock().sound_thread.lock().clear();
self.set_mode(ctx, MainWindowMode::ShowDialingDirectory);
}

Expand Down Expand Up @@ -364,8 +365,7 @@ impl MainWindow {
let title = if let MainWindowMode::ShowDialingDirectory = self.get_mode() {
crate::DEFAULT_TITLE.to_string()
} else {
let show_disconnect = false;
let d = Instant::now().duration_since(self.buffer_update_thread.lock().connection_time);
let d = Instant::now().duration_since(self.terminal_thread.lock().connection_time);
let sec = d.as_secs();
let minutes = sec / 60;
let hours = minutes / 60;
Expand All @@ -377,7 +377,9 @@ impl MainWindow {
cur.system_name.clone()
};

let title = if self.buffer_update_thread.lock().is_connected {
let is_connected = self.terminal_thread.lock().is_connected;
let title = if is_connected {
self.show_disconnect = true;
fl!(
crate::LANGUAGE_LOADER,
"title-connected",
Expand All @@ -388,7 +390,8 @@ impl MainWindow {
} else {
fl!(crate::LANGUAGE_LOADER, "title-offline", version = crate::VERSION.to_string())
};
if show_disconnect {
if self.show_disconnect && !is_connected {
self.show_disconnect = false;
self.set_mode(ctx, MainWindowMode::ShowDisconnectedMessage(system_name.clone(), connection_time.clone()));
self.output_string("\nNO CARRIER\n");
}
Expand Down Expand Up @@ -457,7 +460,7 @@ impl MainWindow {
}

fn send_vec(&mut self, to_vec: Vec<u8>) {
if !self.buffer_update_thread.lock().is_connected {
if !self.terminal_thread.lock().is_connected {
return;
}
self.send_data(SendData::Data(to_vec));
Expand Down
9 changes: 7 additions & 2 deletions crates/icy_term/src/ui/terminal_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,15 @@ pub fn start_update_thread(
let com: Box<dyn Connection> = match open_connection(&connection_data).await {
Ok(com) => com,
Err(err) => {
println!("111");
update_thread.lock().is_connected = false;
println!("112");
let _ = tx.send(SendData::Disconnect);
println!("113");
log::error!("run_update_thread::open_connection: {err}");
println!("114");
println(&update_thread, &mut buffer_parser, &format!("\n{err}\n"));
update_thread.lock().is_connected = false;
println!("115");
return;
}
};
Expand All @@ -196,9 +201,9 @@ pub fn start_update_thread(
read_data = connection.com.read(&mut data) => {
match read_data {
Err(err) => {
update_thread.lock().is_connected = false;
println(&update_thread, &mut buffer_parser, &format!("\n{err}\n"));
log::error!("run_update_thread::read_data: {err}");
update_thread.lock().is_connected = false;
break;
}
Ok(size) => {
Expand Down
26 changes: 13 additions & 13 deletions crates/icy_term/src/ui/terminal_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl MainWindow {
self.set_mode(ctx, MainWindowMode::SelectProtocol(true));
}
let mut send_login = false;
if let Some(auto_login) = &mut self.buffer_update_thread.lock().auto_login {
if let Some(auto_login) = &mut self.terminal_thread.lock().auto_login {
if !auto_login.logged_in {
let r = ui.add(ImageButton::new(KEY.clone().tint(crate::ui::button_tint(ui)))).on_hover_ui(|ui| {
ui.label(RichText::new(fl!(crate::LANGUAGE_LOADER, "terminal-autologin")).small());
Expand All @@ -76,7 +76,7 @@ impl MainWindow {
}

let mut mode = None;
if let Some(auto_login) = &mut self.buffer_update_thread.lock().auto_login {
if let Some(auto_login) = &mut self.terminal_thread.lock().auto_login {
if auto_login.iemsi.isi.is_some() {
if self.get_mode() == MainWindowMode::ShowIEMSI {
let r: egui::Response = ui.add(egui::Button::new(RichText::new(fl!(crate::LANGUAGE_LOADER, "toolbar-hide-iemsi"))));
Expand All @@ -98,8 +98,8 @@ impl MainWindow {
self.set_mode(ctx, mode);
}

if self.buffer_update_thread.lock().sound_thread.lock().is_playing() {
let button_text = match self.buffer_update_thread.lock().sound_thread.lock().stop_button {
if self.terminal_thread.lock().sound_thread.lock().is_playing() {
let button_text = match self.terminal_thread.lock().sound_thread.lock().stop_button {
0 => fl!(crate::LANGUAGE_LOADER, "toolbar-stop-playing1"),
1 => fl!(crate::LANGUAGE_LOADER, "toolbar-stop-playing2"),
2 => fl!(crate::LANGUAGE_LOADER, "toolbar-stop-playing3"),
Expand All @@ -110,15 +110,15 @@ impl MainWindow {

let r: egui::Response = ui.add(egui::Button::new(RichText::new(button_text)));
if r.clicked() {
self.buffer_update_thread.lock().sound_thread.lock().clear();
self.terminal_thread.lock().sound_thread.lock().clear();
}
}

if self.buffer_update_thread.lock().capture_dialog.capture_session {
if self.terminal_thread.lock().capture_dialog.capture_session {
let r: egui::Response = ui.add(egui::Button::new(RichText::new(fl!(crate::LANGUAGE_LOADER, "toolbar-stop-capture"))));

if r.clicked() {
self.buffer_update_thread.lock().capture_dialog.capture_session = false;
self.terminal_thread.lock().capture_dialog.capture_session = false;
}
}
if *VERSION < *LATEST_VERSION {
Expand Down Expand Up @@ -218,13 +218,13 @@ impl MainWindow {
dialogs::dialing_directory_dialog::view_dialing_directory(self, ctx);
}

let take = self.buffer_update_thread.lock().auto_transfer.take();
let take = self.terminal_thread.lock().auto_transfer.take();
if let Some((protocol_type, download, file_name)) = take {
self.initiate_file_transfer(ctx, protocol_type, download, file_name);
}

if self.update_thread_handle.is_some() && self.update_thread_handle.as_ref().unwrap().is_finished() {
let handle = self.update_thread_handle.take().unwrap();
if self.terminal_thread_handle.is_some() && self.terminal_thread_handle.as_ref().unwrap().is_finished() {
let handle = self.terminal_thread_handle.take().unwrap();
if let Err(err) = handle.join() {
let err = format!("Error update thread crashed: {:?}", err.downcast_ref::<&str>());
log::error!("{err}");
Expand Down Expand Up @@ -411,7 +411,7 @@ impl MainWindow {
let x = (mouse_pos.x / calc.buffer_rect.width() * 640.0) as i32;
let y = (mouse_pos.y / calc.buffer_rect.height() * 350.0) as i32;
let mut found_field = None;
for mouse_field in &self.buffer_update_thread.lock().mouse_field {
for mouse_field in &self.terminal_thread.lock().mouse_field {
if !mouse_field.style.is_mouse_button() {
continue;
}
Expand Down Expand Up @@ -447,7 +447,7 @@ impl MainWindow {

let x = (hover_pos.x / calc.buffer_rect.width() * 640.0) as i32;
let y = (hover_pos.y / calc.buffer_rect.height() * 350.0) as i32;
let fields = &self.buffer_update_thread.lock().mouse_field;
let fields = &self.terminal_thread.lock().mouse_field;
for mouse_field in fields {
if !mouse_field.style.is_mouse_button() {
continue;
Expand Down Expand Up @@ -578,7 +578,7 @@ impl MainWindow {
}
for (k, m) in key_map {
if *k == key_code {
if self.buffer_update_thread.lock().is_connected {
if self.terminal_thread.lock().is_connected {
self.send_vec(m.to_vec());
} else {
for c in *m {
Expand Down

0 comments on commit 64217f1

Please sign in to comment.