修复了关闭UI后实际没结束软件等BUG

This commit is contained in:
Yakumo Hokori 2025-09-02 23:05:52 +08:00
parent db336184c3
commit ed83c882cd
3 changed files with 22 additions and 0 deletions

1
Cargo.lock generated
View File

@ -553,6 +553,7 @@ name = "ftphack"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"glib",
"gtk", "gtk",
"libunftp", "libunftp",
"tokio", "tokio",

View File

@ -9,3 +9,4 @@ libunftp = "0.21.0"
tokio = { version = "1.47.1", features = ["rt-multi-thread"] } tokio = { version = "1.47.1", features = ["rt-multi-thread"] }
unftp-sbe-fs = "0.3.0" unftp-sbe-fs = "0.3.0"
async-trait = "0.1.50" async-trait = "0.1.50"
glib = "0.18.5"

View File

@ -6,6 +6,7 @@ use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use std::cell::RefCell; use std::cell::RefCell;
use gtk::prelude::*; use gtk::prelude::*;
use glib::Propagation;
fn main() { fn main() {
let rt = tokio::runtime::Builder::new_multi_thread() let rt = tokio::runtime::Builder::new_multi_thread()
@ -101,6 +102,25 @@ fn main() {
dialog.close(); 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 // Show window
ui.window.show_all(); ui.window.show_all();