tauri-apps / tauri-apps/tauri-docs

[request] Add a guide on how to properly handle (closing with) multiple windows

Open
#3,585 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss enhancement
Dominant language
MDX
Stars
1.1k
Forks
887
Avg merge
2d 8h
Merged PRs (30d)
48

Description

Question you want answered

How should multiple windows be handled correctly when closing the main window?

Where did you look for an answer?

I searched using the documentation search input; then checked the References (Window;WebviewWindow) section; and finally looked through Guides > Learn.

I expected a page such as Guides > Learn > Handling Multiple Windows that explains recommended patterns for managing and closing multiple windows.

Page URL

No response

Additional context

I have an application with two windows: The normal main window and a secondary, undecorated, non-closable window.
I want the secondary window to automatically close when the main window is closed. I couldn’t find any official guidance for this scenario, so I came up with the following solution inside the frontend code of the secondary window:

import { getCurrentWindow, Window } from "@tauri-apps/api/window";

const mainWindow = await Window.getByLabel("main");
await mainWindow.listen("tauri://destroyed", async () => {
  const currentWindow = getCurrentWindow();
  await currentWindow.destroy();
});

This works, but it feels fragile. E.g. if the secondary window is missing the core:window:allow-destroy permission or if the listener registration fails or the code doesn't event reach that point.
I assume there's a more robust Rust-side approach for closing non-main windows when the main window exits.

I'd be happy to help draft such a guide, but I’m not proficient in Rust and don’t know which APIs or lifecycle hooks would be best to use.
I'm open to feedback or further questions if that helps clarify the use case or shape the guides content.
btw, I really appreciate the project and the documentation so far.

Are you willing to work on this yourself?
  • I want to work on this myself

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the References > Window and WebviewWindow pages and the Guides > Learn section, then investigate the documented window lifecycle and permission behavior described in the issue. Done means adding a guide that explains recommended patterns for handling and closing multiple windows, including the main-window and secondary-window case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
desktop, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.