Fixed no carrier message & dialog. - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
 (HTM) git clone https://git.drkhsh.at/icy_draw.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 64217f1675229d51e44cb15e9d468f4764d40f1d
 (DIR) parent 7ea9ca15d972c016ddc92f0c087732fc7867346b
 (HTM) Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Mon, 27 May 2024 17:45:43 +0200
       
       Fixed no carrier message & dialog.
       
       Diffstat:
         M crates/icy_engine/src/buffers.rs    |       1 -
         M crates/icy_term/src/ui/app.rs       |       9 +++++----
         M crates/icy_term/src/ui/dialogs/sho… |      12 +-----------
         M crates/icy_term/src/ui/mod.rs       |      41 +++++++++++++++++--------------
         M crates/icy_term/src/ui/terminal_th… |       9 +++++++--
         M crates/icy_term/src/ui/terminal_wi… |      26 +++++++++++++-------------
       
       6 files changed, 48 insertions(+), 50 deletions(-)
       ---
 (DIR) diff --git a/crates/icy_engine/src/buffers.rs b/crates/icy_engine/src/buffers.rs
       @@ -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);
 (DIR) diff --git a/crates/icy_term/src/ui/app.rs b/crates/icy_term/src/ui/app.rs
       @@ -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,
       @@ -122,6 +122,7 @@ impl MainWindow {
                    use_rip: false,
                    buffer_parser,
                    title: String::new(),
       +            show_disconnect: false,
                };
        
                #[cfg(not(target_arch = "wasm32"))]
       @@ -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);
       @@ -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);
                        }
                    }
 (DIR) diff --git a/crates/icy_term/src/ui/dialogs/show_iemsi.rs b/crates/icy_term/src/ui/dialogs/show_iemsi.rs
       @@ -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)
 (DIR) diff --git a/crates/icy_term/src/ui/mod.rs b/crates/icy_term/src/ui/mod.rs
       @@ -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>,
        
       @@ -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")]
       @@ -157,7 +158,7 @@ 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);
       @@ -165,7 +166,7 @@ impl MainWindow {
            }
        
            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);
       @@ -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));
       @@ -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));
       @@ -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();
       @@ -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()));
       @@ -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);
            }
        
       @@ -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;
       @@ -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",
       @@ -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");
                    }
       @@ -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));
 (DIR) diff --git a/crates/icy_term/src/ui/terminal_thread.rs b/crates/icy_term/src/ui/terminal_thread.rs
       @@ -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;
                                }
                            };
       @@ -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) => {
 (DIR) diff --git a/crates/icy_term/src/ui/terminal_window.rs b/crates/icy_term/src/ui/terminal_window.rs
       @@ -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());
       @@ -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"))));
       @@ -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"),
       @@ -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 {
       @@ -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}");
       @@ -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;
                                    }
       @@ -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;
       @@ -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 {