Repository: tauri-apps/tauri
File: core/tauri/src/window/mod.rs (Rust)

Code before:
      let window = app_manager.window.attach_window(
        self.manager.app_handle().clone(),
        detached_window.clone(),
        #[cfg(desktop)]
        window_menu,
      );

      if let Some(webview) = detached_window.webview {
        app_manager.webview.attach_webview(window.clone(), webview);
      }

      window
    })?;

    #[cfg(desktop)]
    if let Some(handler) = self.on_menu_event {
      window.on_menu_event(handler);
    }

    if let Some(effects) = self.window_effects {
      crate::vibrancy::set_window_effects(&window, Some(effects))?;
    }

    let app_manager = self.manager.manager_owned();
    let window_label = window.label().to_string();
    // run on the main thread to fix deadlock on webview.eval
    let _ = window.run_on_main_thread(move || {
      let _ = app_manager.webview.eval_script_all(format!(
        "window.__TAURI_INTERNALS__.metadata.windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
        window_labels_array = serde_json::to_string(&app_manager.window.labels()).unwrap(),
      ));

      let _ = app_manager.emit(
        "tauri://window-created",
        Some(crate::webview::CreatedEvent {
          label: window_label,
        }),
      );
    });

    Ok(window)
  }
}

/// Desktop APIs.
#[cfg(desktop)]
#[cfg_attr(not(feature = "unstable"), allow(dead_code))]
impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M> {
  /// Sets the menu for the window.
  #[must_use]
  pub fn menu(mut self, menu: Menu<R>) -> Self {

Review comment (bug):
```suggestion
    // run on the main thread to fix a deadlock on webview.eval if the tracing feature is enabled
```

Code after:
      let window = app_manager.window.attach_window(
        self.manager.app_handle().clone(),
        detached_window.clone(),
        #[cfg(desktop)]
        window_menu,
      );

      if let Some(webview) = detached_window.webview {
        app_manager.webview.attach_webview(window.clone(), webview);
      }

      window
    })?;

    #[cfg(desktop)]
    if let Some(handler) = self.on_menu_event {
      window.on_menu_event(handler);
    }

    if let Some(effects) = self.window_effects {
      crate::vibrancy::set_window_effects(&window, Some(effects))?;
    }

    let app_manager = self.manager.manager_owned();
    let window_label = window.label().to_string();
    // run on the main thread to fix a deadlock on webview.eval if the tracing feature is enabled
    let _ = window.run_on_main_thread(move || {
      let _ = app_manager.webview.eval_script_all(format!(
        "window.__TAURI_INTERNALS__.metadata.windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
        window_labels_array = serde_json::to_string(&app_manager.window.labels()).unwrap(),
      ));

      let _ = app_manager.emit(
        "tauri://window-created",
        Some(crate::webview::CreatedEvent {
          label: window_label,
        }),
      );
    });

    Ok(window)
  }
}

/// Desktop APIs.
#[cfg(desktop)]
#[cfg_attr(not(feature = "unstable"), allow(dead_code))]
impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M> {
  /// Sets the menu for the window.
  #[must_use]
  pub fn menu(mut self, menu: Menu<R>) -> Self {