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

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

Open randall-coding opened this issue 2 years ago • 0 comments

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?

randall-coding avatar Jul 14 '22 00:07 randall-coding