From d809448c2aa8d8f208d90ebea3da2ab615dc7357 Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Fri, 19 Jul 2024 23:27:17 -0400 Subject: [PATCH] fix bug #1 --- src/main.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index f543793..02379de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::sync::mpsc::{self}; use std::sync::{Arc, Mutex}; use threadpool::ThreadPool; use webbrowser; +use std::process; const DESTINATION_IP: &str = "255.255.255.255"; const SOURCE_PORT: u16 = 14236; @@ -23,15 +24,13 @@ struct PacketInfo { source_mac: String, } -// test comment - fn main() { let application = Application::new(Some("com.example.ip_reporter"), Default::default()); application.connect_activate(|app| { - let window = ApplicationWindow::new(app); - window.set_title("IP Reporter"); - window.set_default_size(600, 400); + let window = Rc::new(RefCell::new(ApplicationWindow::new(app))); + window.borrow().set_title("IP Reporter"); + window.borrow().set_default_size(600, 400); let vbox = gtk::Box::new(gtk::Orientation::Vertical, 5); let tree_view = TreeView::new(); @@ -50,8 +49,8 @@ fn main() { vbox.pack_start(&export_button, false, false, 0); vbox.pack_start(&*status_label.borrow(), false, false, 0); - window.add(&vbox); - window.show_all(); + window.borrow().add(&vbox); + window.borrow().show_all(); let (tx, rx) = mpsc::channel(); let listening = Arc::new(Mutex::new(false)); @@ -118,10 +117,11 @@ fn main() { { let status_label = Rc::clone(&status_label); + let window = Rc::clone(&window); export_button.connect_clicked(move |_| { let dialog = FileChooserDialog::with_buttons( Some("Save File"), - Some(&window), + Some(&*window.borrow()), FileChooserAction::Save, &[("Cancel", ResponseType::Cancel), ("Save", ResponseType::Ok)], ); @@ -157,6 +157,13 @@ fn main() { } } }); + + window.borrow().connect_delete_event(move |_, _| { + // Clean up resources here + let mut is_listening = listening.lock().unwrap(); + *is_listening = false; + process::exit(0); + }); }); application.run();