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

Code before:
  }
}

fn on_window_close(window_id: WebviewId, windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>) {
  if let Some(window_wrapper) = windows.borrow_mut().get_mut(&window_id) {
    window_wrapper.inner = None;
  }
}

pub fn center_window(window: &Window, window_size: TaoPhysicalSize<u32>) -> Result<()> {
  if let Some(monitor) = window.current_monitor() {
    let screen_size = monitor.size();
    let monitor_pos = monitor.position();
    let x = (screen_size.width as i32 - window_size.width as i32) / 2;
    let y = (screen_size.height as i32 - window_size.height as i32) / 2;
    window.set_outer_position(TaoPhysicalPosition::new(
      monitor_pos.x + x,
      monitor_pos.y + y,
    ));
    Ok(())
  } else {
    Err(Error::FailedToGetMonitor)
  }
}

fn parse_proxy(url: &Url) -> Result<ProxyConfig> {
  let host = url.host().map(|h| h.to_string()).unwrap_or_default();
  let port = url.port().map(|p| p.to_string()).unwrap_or_default();

  if url.scheme() == "http" {
    let config = ProxyConfig::Http(ProxyEndpoint { host, port });

    Ok(config)
  } else if url.scheme() == "socks5" {
    let config = ProxyConfig::Socks5(ProxyEndpoint { host, port });

    Ok(config)
  } else {
    Err(Error::InvalidProxyUrl)
  }
}

fn create_webview<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
  window_id: WebviewId,
  event_loop: &EventLoopWindowTarget<Message<T>>,
  web_context_store: &WebContextStore,
  context: Context<T>,
  pending: PendingWindow<T, Wry<T>>,
  before_webview_creation: Option<F>,
) -> Result<WindowWrapper> {
  #[allow(unused_mut)]

Review comment (suggestion):
```suggestion
fn parse_proxy_url(url: &Url) -> Result<ProxyConfig> {
```

Code after:
            bounds.width = size.width;
            bounds.height = size.height;

            if let Some(b) = &webview.bounds {
              let window_size = window.inner_size();
              let mut bounds = b.lock().unwrap();
              bounds.width_rate = size.width as f32 / window_size.width as f32;
              bounds.height_rate = size.height as f32 / window_size.height as f32;
            }

            webview.set_bounds(bounds);
          }
          WebviewMessage::SetPosition(position) => {
            let mut bounds = webview.bounds();
            let position = position.to_logical(window.scale_factor());
            bounds.x = position.x;
            bounds.y = position.y;

            if let Some(b) = &webview.bounds {
              let window_size = window.inner_size();
              let mut bounds = b.lock().unwrap();
              bounds.width_rate = position.x as f32 / window_size.width as f32;
              bounds.height_rate = position.y as f32 / window_size.height as f32;
            }

            webview.set_bounds(bounds);
          }
          WebviewMessage::SetFocus => {
            webview.focus();
          }
          WebviewMessage::WebviewEvent(_event) => { /* already handled */ }
          WebviewMessage::WithWebview(f) => {
            #[cfg(any(
              target_os = "linux",
              target_os = "dragonfly",
              target_os = "freebsd",
              target_os = "netbsd",
              target_os = "openbsd"
            ))]
            {
              f(webview.webview());
            }
            #[cfg(target_os = "macos")]
            {
              use wry::WebViewExtMacOS;
              f(Webview {
                webview: webview.webview(),
                manager: webview.manager(),
                ns_window: webview.ns_window(),
              });
            }