Repository: tauri-apps/tauri
File: core/tauri-runtime-wry/src/lib.rs (Rust)

Code before:
    target_os = "ios",
    target_os = "android"
  )))]
  let builder = {
    use wry::WebViewBuilderExtUnix;
    let vbox = window.default_vbox().unwrap();
    WebViewBuilder::new_gtk(vbox)
  };

  let mut webview_builder = builder
    .with_focused(focused)
    .with_url(&url)
    .unwrap() // safe to unwrap because we validate the URL beforehand
    .with_transparent(is_window_transparent)
    .with_accept_first_mouse(webview_attributes.accept_first_mouse);

  if webview_attributes.file_drop_handler_enabled {
    let proxy = proxy.clone();
    let window_event_listeners = window_event_listeners.clone();
    webview_builder = webview_builder.with_file_drop_handler(move |event| {
      let event: FileDropEvent = FileDropEventWrapper(event).into();
      let _ = proxy.send_event(Message::Webview(
        window_id,
        WebviewMessage::WebviewEvent(WebviewEvent::FileDrop(event)),
      ));
      let has_listeners = !window_event_listeners.lock().unwrap().is_empty();
      has_listeners
    });
  }

  if let Some(navigation_handler) = pending.navigation_handler {
    webview_builder = webview_builder.with_navigation_handler(move |url| {
      Url::parse(&url)
        .map(|url| navigation_handler(&url))
        .unwrap_or(true)
    });
  }

  if let Some(page_load_handler) = pending.on_page_load_handler {
    webview_builder = webview_builder.with_on_page_load_handler(move |event, url| {
      let _ = Url::parse(&url).map(|url| {
        page_load_handler(
          url,
          match event {
            wry::PageLoadEvent::Started => tauri_runtime::window::PageLoadEvent::Started,
            wry::PageLoadEvent::Finished => tauri_runtime::window::PageLoadEvent::Finished,
          },
        )
      });
    });
  }

Review comment (bug):
I think we should always return true now, we can't know for sure if the event was handled or not (that was the case with the previous implementation too - which is also wrong on v1)

Code after:
    target_os = "ios",
    target_os = "android"
  )))]
  let builder = {
    use wry::WebViewBuilderExtUnix;
    let vbox = window.default_vbox().unwrap();
    WebViewBuilder::new_gtk(vbox)
  };

  let mut webview_builder = builder
    .with_focused(focused)
    .with_url(&url)
    .unwrap() // safe to unwrap because we validate the URL beforehand
    .with_transparent(is_window_transparent)
    .with_accept_first_mouse(webview_attributes.accept_first_mouse);

  if webview_attributes.file_drop_handler_enabled {
    let proxy = proxy.clone();
    webview_builder = webview_builder.with_file_drop_handler(move |event| {
      let event: FileDropEvent = FileDropEventWrapper(event).into();
      let _ = proxy.send_event(Message::Webview(
        window_id,
        WebviewMessage::WebviewEvent(WebviewEvent::FileDrop(event)),
      ));
      true
    });
  }

  if let Some(navigation_handler) = pending.navigation_handler {
    webview_builder = webview_builder.with_navigation_handler(move |url| {
      Url::parse(&url)
        .map(|url| navigation_handler(&url))
        .unwrap_or(true)
    });
  }

  if let Some(page_load_handler) = pending.on_page_load_handler {
    webview_builder = webview_builder.with_on_page_load_handler(move |event, url| {
      let _ = Url::parse(&url).map(|url| {
        page_load_handler(
          url,
          match event {
            wry::PageLoadEvent::Started => tauri_runtime::window::PageLoadEvent::Started,
            wry::PageLoadEvent::Finished => tauri_runtime::window::PageLoadEvent::Finished,
          },
        )
      });
    });
  }

  if let Some(user_agent) = webview_attributes.user_agent {