Does anybody know what Tauri is doing internally when it is setting up a message pump

87 Views Asked by At

So I've been trying to use the winrt APIs in my tauri app. Currently I'm trying to write an event handler for clipboard updates, and I've been getting some pretty inconsistent results.

So basically I'm building my app in main.rs, creating an event handler and then running the app manually:

fn main() {
    let mut app = tauri::Builder
        ::default()
        .manage(AppState::default())
        .setup(|app| {
            ...
        })
        .invoke_handler(
            generate_handler![
                ...
            ]
        )
        .build(tauri::generate_context!())
        .expect("error while running tauri application");

    Clipboard::ContentChanged(
        &EventHandler::new(move |_sender, _e| {
            println!("Clip update");

            Ok(())
        })
    ).expect("Failed to add clipboard content changed listener");

    loop {
        let iteration = app.run_iteration();

        if iteration.window_count == 0 {
            break;
        }

        thread::yield_now();
    }
}

At the moment that code actually works. My problem is that I can't use the event handler anywhere else. I can't call that ContentChanged event handler function before I build my app, I can't call it in my setup function, and I can't call it when I'm initialising my app state (which I'm aiming to do since then I can use it in my ClipboardHandler struct).

I've been doing some reading and it seems that for winrt events to work, my app needs to "pump messages". Now, there's the winit EventLoop struct in winit that will do that for me if I'm implementing this for just an empty project, except tauri (which uses tao) clearly already does this for me. I've looked through the .build() fn which calls the setup hook right before the end, so I don't quite get why setting up the EventHandler in my setup hook wouldn't hook since it's being ran after everything else is ready and set up.

0

There are 0 best solutions below