From bec0d21d206212c6d17c8ba3618c25f672d4d017 Mon Sep 17 00:00:00 2001 From: iorebuild Date: Thu, 7 Aug 2025 21:13:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E8=B5=B7=E6=9D=A5tfto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- src/main.rs | 35 +++++++++++++++-------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80c06ef..ee5f4c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "1.0.0" edition = "2024" [dependencies] -smol = "1" # or any other runtime/executor +tokio = "1.47.1" async-tftp = "0.3.6" slint = "1.12.1" rfd = "0.15.4" diff --git a/src/main.rs b/src/main.rs index 99c3bb9..9c9940f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,18 @@ -// use async_tftp::server::TftpServerBuilder; -// use async_tftp::Result; +use async_tftp::server::TftpServerBuilder; +use async_tftp::Result; use rfd::FileDialog; use slint::SharedString; +use std::error::Error; +// ?use smol::{prelude::*}; + slint::include_modules!(); -// fn main() -> Result<()> { -// smol::block_on(async { -// let tftpd = TftpServerBuilder::with_dir_ro("C:/Users/anonymous/Desktop/Rust/VoiletTftp/target/debug")?.build().await?; -// tftpd.serve().await?; -// Ok(()) -// }) -// } + +async fn StartTftpServer(Dir: &str) -> Result<()> { + println!("Start Tftp Server Dir With:{Dir}"); + let tftpd = TftpServerBuilder::with_dir_ro(Dir)?.build().await?; + tftpd.serve().await?; + Ok(()) +} fn main() { let ui = MainWindow::new().unwrap(); @@ -26,19 +29,11 @@ fn main() { }); //启动按钮的回调函数 ui.on_StartTftp(move || { - println!("Start Tftp Dir:"); + // smol::spawn(StartTftpServer("C:/Users/anonymous/Desktop/Rust/VoiletTftp/target/release/")).detach(); }); //停止按钮的回调函数 ui.on_StopTftp(move || { - println!("Stop Tftp Dir:"); }); ui.run().unwrap(); - // // 实现 Slint 中定义的 select_path 函数 - // ui.global::().invoke_select_path(move || { - // // 使用 rfd 库打开文件选择对话框 - // if let Some(path) = FileDialog::new().pick_folder() { - // // 将选择的路径设置到 Slint 的 selected_path 属性中 - // ui.global::().set_selected_path(path.to_str().unwrap_or("")); - // } - // }); -} \ No newline at end of file +} +//启动一个TFTP服务器帮我改写 \ No newline at end of file