#Red macOS close button not closing the window (secondary window)

4 messages · Page 1 of 1 (latest)

blazing adder
#

I open additional windows with

  const w = await WebviewWindow.getByLabel(url);
  if (w) return w.setFocus();

  const webview = new WebviewWindow(url, {

I have some listeners

  webview.once("tauri://created", async (event) => {
    console.log("created", event);
    await webview.setEffects({
      effects: [Effect.HeaderView],
      radius: 12,
    });
  });
  webview.once("tauri://error", (e) => console.log("error", e));
  webview.once("tauri://close-requested", async (e) => {
    console.log("close-requested", e);
    webview.close();
    onClose?.();
    const w = getCurrentWebview();
    w.show(); // focus the spawning window, once the popup is closed
  });
  webview.once("tauri://destroyed", () => {
    console.log("destroyed");
    onClose?.();
  });

But sometimes (often) the window then isn't closeable. I doesn't respond to the red close button on macOS. It doesn't respond to cmd+w. It doesn't respond to manually doing window.close in the console.

trace logs

[2025-02-20][09:35:10][tao::platform_impl::platform::window_delegate][TRACE] Triggered `windowDidResignKey:`
[2025-02-20][09:35:10][tao::platform_impl::platform::window_delegate][TRACE] Completed `windowDidResignKey:`

Any ideas?

stiff magnet
#

you need to handle the exit/close so that it aloss closes any other windows while exiting

#

here is my code that works

use tauri::WindowEvent;

// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(tauri::generate_handler![greet])
        .setup(|_app| {
            Ok(())
        })
        .on_window_event(|_window, event| {
            match event {
                WindowEvent::CloseRequested { api, .. } => {
                    api.prevent_close();
                    std::process::exit(0);
                }
                _ => {}
            }
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
#

my code is on windows but it should be similar