This commit is contained in:
Tristan Smith 2024-07-19 23:27:17 -04:00
parent e0618889aa
commit d809448c2a

View file

@ -12,6 +12,7 @@ use std::sync::mpsc::{self};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use threadpool::ThreadPool; use threadpool::ThreadPool;
use webbrowser; use webbrowser;
use std::process;
const DESTINATION_IP: &str = "255.255.255.255"; const DESTINATION_IP: &str = "255.255.255.255";
const SOURCE_PORT: u16 = 14236; const SOURCE_PORT: u16 = 14236;
@ -23,15 +24,13 @@ struct PacketInfo {
source_mac: String, source_mac: String,
} }
// test comment
fn main() { fn main() {
let application = Application::new(Some("com.example.ip_reporter"), Default::default()); let application = Application::new(Some("com.example.ip_reporter"), Default::default());
application.connect_activate(|app| { application.connect_activate(|app| {
let window = ApplicationWindow::new(app); let window = Rc::new(RefCell::new(ApplicationWindow::new(app)));
window.set_title("IP Reporter"); window.borrow().set_title("IP Reporter");
window.set_default_size(600, 400); window.borrow().set_default_size(600, 400);
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 5); let vbox = gtk::Box::new(gtk::Orientation::Vertical, 5);
let tree_view = TreeView::new(); let tree_view = TreeView::new();
@ -50,8 +49,8 @@ fn main() {
vbox.pack_start(&export_button, false, false, 0); vbox.pack_start(&export_button, false, false, 0);
vbox.pack_start(&*status_label.borrow(), false, false, 0); vbox.pack_start(&*status_label.borrow(), false, false, 0);
window.add(&vbox); window.borrow().add(&vbox);
window.show_all(); window.borrow().show_all();
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let listening = Arc::new(Mutex::new(false)); let listening = Arc::new(Mutex::new(false));
@ -118,10 +117,11 @@ fn main() {
{ {
let status_label = Rc::clone(&status_label); let status_label = Rc::clone(&status_label);
let window = Rc::clone(&window);
export_button.connect_clicked(move |_| { export_button.connect_clicked(move |_| {
let dialog = FileChooserDialog::with_buttons( let dialog = FileChooserDialog::with_buttons(
Some("Save File"), Some("Save File"),
Some(&window), Some(&*window.borrow()),
FileChooserAction::Save, FileChooserAction::Save,
&[("Cancel", ResponseType::Cancel), ("Save", ResponseType::Ok)], &[("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(); application.run();