这是indexloc提供的服务,不要输入任何密码
Skip to content

tauri dev crashes whenever a key is pressed #165

@jagzmz

Description

@jagzmz
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_opener::init())
        .setup(|app| {

            // Start the input handler using our improved grabber
            let app_handle = app.handle().clone();

            let (tx, rx) = mpsc::channel();

            std::thread::spawn(move || {
                listen(move |event| {
                    tx.send(event).unwrap();
                })
                .unwrap();
            });

            std::thread::spawn(move || {
                let mut meta_pressed = false;
                
                while let Ok(event) = rx.recv() {
                    println!("Event: {:?}", event);
                    match event.event_type {
                        EventType::KeyPress(Key::MetaLeft) | EventType::KeyPress(Key::MetaRight) => {
                            meta_pressed = true;
                            println!("Meta key pressed");
                        }
                        EventType::KeyRelease(Key::MetaLeft) | EventType::KeyRelease(Key::MetaRight) => {
                            meta_pressed = false;
                            println!("Meta key released");
                        }
                        EventType::KeyPress(Key::KeyV) => {
                            println!("V key pressed");
                            if meta_pressed {
                                println!("Meta+V detected");
                                let window = app_handle.get_webview_window("main").unwrap();
                                let is_visible = window.is_visible().unwrap();
                                if is_visible {
                                    println!("Hiding window");
                                    window.hide().unwrap();
                                } else {
                                    println!("Showing window");
                                    window.show().unwrap();
                                    window.set_focus().unwrap();
                                }
                            }
                        }
                        _ => {}
                    }
                }
            });
            
            // println!("Initializing input handler...");
            
            // Now we directly use the grabber
            // input_handler::start_grabbing(app_handle);
            
            // Small delay to let the input thread initialize
            // std::thread::sleep(std::time::Duration::from_millis(500));
            // println!("Continuing with app startup after input thread initialized");

            Ok(())
        })
        .invoke_handler(tauri::generate_handler![greet, set_window_listening_state])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

As soon as i press any key on my MacOS keyboard, it exits with code 0 @Narsil , i am using latest from git url rdev = { git = "https://github.com/Narsil/rdev", branch = "main" }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions