Skip to content

How to use AppHandle in function that is in another runtime? #10784

Answered by lcdss
pan-grayza asked this question in Q&A
Discussion options

You must be logged in to vote

If your implementation of setup_file_watcher doesn't spawn more threads, you may not need Arc or even a Mutex. In my case I needed a way to access the app_handle in any actix-web handler, so I racked my brain for a few days to make it to work, as I had just started using tauri and rust. I tried with Box and Mutex at first, following this post, but it didn't work (compiled) for me. So after making some changes and later on, simplifying a little more, it worked with as little as this:

#[cfg(target_os = "linux")]
pub fn run() {
    use std::thread;

    tauri::Builder::default()
        .plugin(tauri_plugin_shell::init())
        .setup(|app| {
            let app_handle = app.handle().clone();

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pan-grayza
Comment options

Answer selected by pan-grayza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants