web-view icon indicating copy to clipboard operation
web-view copied to clipboard

how to create handler?

Open ShaoDaTao opened this issue 1 year ago • 0 comments

I used web-view,, want to show the small window with notice words in it, and automatically disappear after 2 seconds. so create the handler and use it to exit the window, but how to create the handler?

web_view: 0.7.3

use web_view::*;

fn main() {
    let html = "Hello world!";

    let handle = web_view::Handle::current().unwrap();

    std::thread::spawn(move || {
        std::thread::sleep(std::time::Duration::from_secs(2));
        handle.dispatch(move |webview| {
            webview.terminate();
            Ok(())
        }).unwrap();
    });

    web_view::builder()
        .title("")
        .content(Content::Html(html))
        .size(250, 20)
        .resizable(false)
        .frameless(true)
        .user_data(handle.clone())
        .invoke_handler(|_webview, _arg| Ok(()))
        .run()
        .unwrap();
}

how to create the handler? let handle = web_view::Handle::current().unwrap(); # it's wrong way.

ShaoDaTao avatar Mar 31 '23 13:03 ShaoDaTao