From aa326e69b18a4390ffbc97268eaec4793761f083 Mon Sep 17 00:00:00 2001 From: "1992414357@qq.com" <1992414357@qq.com> Date: Wed, 11 Jun 2025 18:32:48 +0800 Subject: . --- console/src/bin/padc.rs | 132 +++++++++++++++----------------------- console/src/gui/controller_app.rs | 38 ----------- console/src/gui/mod.rs | 1 - console/src/lib.rs | 3 +- 4 files changed, 51 insertions(+), 123 deletions(-) delete mode 100644 console/src/gui/controller_app.rs delete mode 100644 console/src/gui/mod.rs (limited to 'console/src') diff --git a/console/src/bin/padc.rs b/console/src/bin/padc.rs index 3fc875a..a60559f 100644 --- a/console/src/bin/padc.rs +++ b/console/src/bin/padc.rs @@ -18,12 +18,11 @@ use std::sync::atomic::Ordering::SeqCst; use std::time::Duration; use clap_complete::{generate, Shell}; use log::{info, LevelFilter}; -use tokio::select; +use tokio::{select, spawn}; use tokio::signal::ctrl_c; use tokio::time::sleep; use nogamepads::entry_mutex; use nogamepads::logger_utils::logger_build; -use nogamepads_console::gui::controller_app::MyApp; use nogamepads_core::data::controller::cli::cli_command::{process_controller_cli, ControllerCli}; use nogamepads_core::data::controller::structs::ControllerData; use nogamepads_core::data::game::cli::cli_command::{process_game_cli, GameCli}; @@ -32,6 +31,7 @@ use nogamepads_core::service::service_runner::{NoGamepadsService, ServiceRunner} use nogamepads_core::service::tcp_network::DEFAULT_PORT; use nogamepads_core::service::tcp_network::pad_client::structs::PadClientNetwork; use nogamepads_core::service::tcp_network::pad_server::structs::PadServerNetwork; +use nogamepads_core::service::tcp_network::utils::tokio_utils::build_tokio_runtime; #[derive(Parser, Debug)] #[command(version, color = ColorChoice::Auto)] @@ -213,9 +213,6 @@ struct ConnectArgs { #[arg(long)] cmd: bool, - #[arg(long)] - gui: bool, - #[arg(long)] debug: bool, } @@ -232,9 +229,6 @@ struct ListenArgs { #[arg(long)] cmd: bool, - #[arg(long)] - gui: bool, - #[arg(long)] tcp: bool, @@ -425,8 +419,10 @@ fn connect(data: &mut LocalData, args: ConnectArgs) { let method = args.method.unwrap_or("tcp".to_string()); let mut entry: Option = None; - match method.as_str() { + + match method.trim().to_lowercase().as_str() { "tcp" => { + println!("Using TCP connection."); let mut client = PadClientNetwork::build(Arc::clone(&runtime)); let addr = args.tcp_addr.unwrap_or(format!("127.0.0.1:{}", DEFAULT_PORT)); client.bind_addr(SocketAddr::from_str(&addr).unwrap_or( @@ -437,15 +433,17 @@ fn connect(data: &mut LocalData, args: ConnectArgs) { }, "bluetooth" => { + println!("Using Bluetooth connection."); // TODO :: BLUETOOTH METHOD }, "usb" => { + println!("Using USB connection."); // TODO :: USB METHOD }, _ => { - eprintln!("Unknown connection method: {}", method); + eprintln!("Unknown connection method: \"{}\"", method); exit(1); } } @@ -455,32 +453,33 @@ fn connect(data: &mut LocalData, args: ConnectArgs) { services.push(entry); if args.cmd { + println!("Enable command line."); + services.push(RuntimeConsole::build( - ControllerCli::command(), - "ControllerCli".to_string(), - Arc::clone(&runtime), + ControllerCli::command(), "ControllerCli".to_string(), Arc::clone(&runtime), + + // Process command line |runtime, cmd| { process_controller_cli(runtime, cmd) - } - ).build_entry()); + }, - // Ctrl + C - services.push( - build_ctrl_c_entry( - Arc::clone(&runtime), - |rt| { - let mut close = false; - entry_mutex!(rt, |guard| { - close = guard.close.load(SeqCst); - }); - close - } - ) - ); - } + // Check close + |runtime| { + let mut close = false; + entry_mutex!(runtime, |guard| { + close = guard.close.load(SeqCst); + }); + close + }, - if args.gui { + // Close + |runtime| { + entry_mutex!(runtime, |guard| { + guard.close(); + }); + }, + ).build_entry()); } if args.debug { @@ -529,31 +528,30 @@ fn listen(data: &mut LocalData, args: ListenArgs) -> Option String { let g = ((g + m) * 255.0).round() as u8; let b = ((b + m) * 255.0).round() as u8; format!("#{:02X}{:02X}{:02X}", r, g, b) -} - -fn build_ctrl_c_entry(rt: Arc>, check_close: fn(rt: Arc>) -> bool) -> NoGamepadsService { - let shutdown = async move { - let mut count = 3; - loop { - if count < 0 { - exit(0); - } - - select! { - _ = sleep(Duration::from_secs(1)) => { - if check_close(rt.clone()) { - break; - } - } - - _ = ctrl_c() => { - if count >= 3 { - info!("Please use the close command instead of Ctrl + C. "); - info!("To forcibly close the process, press Ctrl + C {} times consecutively.", count); - } else if count > 0 { - info!("Press Ctrl + C {} times to force close.", count); - } - count -= 1; - } - } - } - }; - Box::pin(shutdown) } \ No newline at end of file diff --git a/console/src/gui/controller_app.rs b/console/src/gui/controller_app.rs deleted file mode 100644 index d8325b1..0000000 --- a/console/src/gui/controller_app.rs +++ /dev/null @@ -1,38 +0,0 @@ -pub struct MyApp { - show_hello: bool, // 控制是否显示 "Hello World!" -} - -impl Default for MyApp { - fn default() -> Self { - Self { show_hello: false } - } -} - -impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - egui::CentralPanel::default().show(ctx, |ui| { - // 添加一个按钮 - if ui.button("Click me!").clicked() { - self.show_hello = !self.show_hello; // 切换状态 - } - - // 如果按钮被点击过,显示 "Hello World!" - if self.show_hello { - ui.label("Hello World!"); - } - }); - } -} - -impl MyApp { - pub fn start () { - let options = eframe::NativeOptions::default(); - let _ = eframe::run_native( - "My egui App", - options, - Box::new(|_cc| { - Ok(Box::::default()) - }), - ); - } -} \ No newline at end of file diff --git a/console/src/gui/mod.rs b/console/src/gui/mod.rs deleted file mode 100644 index 5e7124a..0000000 --- a/console/src/gui/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod controller_app; \ No newline at end of file diff --git a/console/src/lib.rs b/console/src/lib.rs index 3e25a58..fab870e 100644 --- a/console/src/lib.rs +++ b/console/src/lib.rs @@ -1,2 +1 @@ -pub mod utils; -pub mod gui; \ No newline at end of file +pub mod utils; \ No newline at end of file -- cgit