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

Is there a way to open two webview windows without crashing? #317

Open
randall-coding opened this issue Jul 14, 2022 · 1 comment
Open

Comments

@randall-coding
Copy link

randall-coding commented Jul 14, 2022

My system
Ubuntu 21.04

What I'm trying to do
I actually don't need two open simultaneously, but that would also work. I want to be able to close the first webview window (clicking the "x" icon), then I am opening another window to provide a message to the user. However this results in an error every time with

Aborted (core dumped)

My code
Here is an example of what produces that error. I start up the window, and during the 6 second sleep I close that first window.

let (popup_stopper, popup_receiver) = oneshot::channel::<String>();
let wait_popup_future = tokio::spawn(wait_popup::show("Waiting on upload & download jobs to finish".to_string(),popup_receiver));
sleep(Duration::from_secs(6)).await; //DEBUG!!    
let (popup_stopper2, popup_receiver2) = oneshot::channel::<String>();
let wait_popup_future2 = tokio::spawn(wait_popup::show("This represents the normal app webview".to_string(),popup_receiver2)); 

And within each wait_popup::show() function I call webview like so:

let mut webview = web_view::builder()
        .title("Waiting on process")
        .content(Content::Html(html))
        .size(500, 80)
        .resizable(false)
        .debug(false)
        .user_data(json!({"message": message}))
        .visible(true)
        .invoke_handler(|webview, arg| {
            use Cmd::*;
            println!("cmd in rust {:?}",arg);
            let cmd: Cmd = serde_json::from_str(arg).unwrap();
            let cmd_copy = cmd.clone();
            
            // clear errors / success messages
            let data = webview.user_data_mut();
            if cmd.will_render(){
                data["errors"] = json!(null); //clear errors
                data["success"] = json!(null); //clear success messages                
                webview.eval("shared_data.errors = null;");
                webview.eval("shared_data.success = null;");
            }
            
            match cmd {
                Init => {
                    println!("Inside Init()");                   
                },
                ... //more code
                WaitPopupStopReceiver => {
                    match stop_receiver.try_recv() {
                        Ok(msg) => {
                            println!("Quitting popup");
                            webview.exit();
                        },
                        _ => {}
                    };
                }
                _ => {},            
            }
            ... //more code
        })
        .build()
        .unwrap();

My question

I've searched other github issues here which seem to imply opening multiple windows is expected to work with this crate? If so can anyone show me how I might do that?

@gitgit3
Copy link

gitgit3 commented Jun 18, 2024

If you have the crate installed, you should find an example at:
web-view-0.7.3/examples/multi_window.rs

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