Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to create handler? #324

Open
ShaoDaTao opened this issue Mar 31, 2023 · 1 comment
Open

how to create handler? #324

ShaoDaTao opened this issue Mar 31, 2023 · 1 comment

Comments

@ShaoDaTao
Copy link

ShaoDaTao commented Mar 31, 2023

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.

@AtomicGamer9523
Copy link

@ShaoDaTao

Last lines:

let wv = web_view::builder()
    // Builder code
    .build().unwrap() // Don't do .run()
let handle = wv.handle();
// thread spawn code
wv.run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants