#access window in another thread

5 messages · Page 1 of 1 (latest)

pastel scarab
#

Hey im searching a way to access current window in another thread cause im using a while and its blocking main thread

tauri::Builder::default()
        .setup(|app| {
            let rx = hookmap_core::install_hook();

            while let Ok((event, native_handler)) = rx.recv() {
                match event {
                    Event::Button(event) => {
                        native_handler.dispatch();
                        if let Some(window) = app.get_focused_window() {
                            let cur_keybind = u8_to_button(*CUR_KEYBIND.lock().unwrap().deref());
                            if cur_keybind == event.target {
                                let _ = window.emit("keybind_pressed", "".to_string());
                                println!("test")
                            }
                        }
                    }
                    _ => {}
                }
            }
            Ok(())
        })
opal marsh
#

you can use try_recv no?

opal marsh
#
let handle = app.app_handle();

std::thread::spawn(move || {
    while let Ok((event, native_handler)) = rx.recv() {
        match event {
            Event::Button(event) => {
                if let Some(window) = &handle.get_focused_window() {

                }

                // window.emit("keybind_pressed", "");
            }
            _ => {}
        }
    }
});

If you still want to use .recv this should work

pastel scarab
#

im gonna try thx

celest lake
#

That looks way over complicated