From 68474e65c27323da62aad223cea7fb22356b0df6 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Tue, 13 Jan 2026 11:25:35 +0800 Subject: feat: Added version control functionality and integrated Tokio and Reqwest to support asynchronous operations --- src/ui/mod.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 778eeee..3ee1e6a 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,7 +1,12 @@ use gtk::prelude::*; use gtk::{Button, Window, WindowType}; +use tokio::sync::mpsc::Sender; -pub fn init() { +pub enum UiEvent { + StartGame, +} + +pub fn init(tx: Sender) { if gtk::init().is_err() { println!("Failed to initialize GTK."); return; @@ -12,8 +17,13 @@ pub fn init() { window.set_default_size(350, 70); let button = Button::with_label("开始游戏"); - button.connect_clicked(|_| { + let tx_clone = tx.clone(); + button.connect_clicked(move |_| { println!("开始游戏按钮被点击"); + // Use blocking_send because we are in a synchronous callback + if let Err(e) = tx_clone.blocking_send(UiEvent::StartGame) { + eprintln!("Failed to send event: {}", e); + } }); window.add(&button); @@ -26,4 +36,4 @@ pub fn init() { window.show_all(); gtk::main(); -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2