From ed83c882cd847273f39fa4e6bc5e62e01b904b19 Mon Sep 17 00:00:00 2001 From: Yakumo Hokori Date: Tue, 2 Sep 2025 23:05:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=85=B3=E9=97=ADUI?= =?UTF-8?q?=E5=90=8E=E5=AE=9E=E9=99=85=E6=B2=A1=E7=BB=93=E6=9D=9F=E8=BD=AF?= =?UTF-8?q?=E4=BB=B6=E7=AD=89BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index da49006..5556b31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -553,6 +553,7 @@ name = "ftphack" version = "0.1.0" dependencies = [ "async-trait", + "glib", "gtk", "libunftp", "tokio", diff --git a/Cargo.toml b/Cargo.toml index e818338..9c8aebe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ libunftp = "0.21.0" tokio = { version = "1.47.1", features = ["rt-multi-thread"] } unftp-sbe-fs = "0.3.0" async-trait = "0.1.50" +glib = "0.18.5" diff --git a/src/main.rs b/src/main.rs index b477308..55f8f3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use std::rc::Rc; use std::cell::RefCell; use gtk::prelude::*; +use glib::Propagation; fn main() { let rt = tokio::runtime::Builder::new_multi_thread() @@ -101,6 +102,25 @@ fn main() { dialog.close(); }); + // Handle window close event + let server_clone3 = server.clone(); + ui.window.connect_delete_event(move |_, _| { + // Stop the server if it's running + let mut server_ref = server_clone3.borrow_mut(); + if let Some(mut srv) = server_ref.take() { + srv.stop(); + } + + // Quit the GTK main loop + gtk::main_quit(); + + // Quit the GTK main loop + gtk::main_quit(); + + // Return Propagation::Proceed to allow the window to close + Propagation::Proceed + }); + // Show window ui.window.show_all();