tauri icon indicating copy to clipboard operation
tauri copied to clipboard

How to create multiple separate windows, instead of "tabs"?

Open wo52616111 opened this issue 2 years ago • 12 comments

Windows created by App::create_window() are just like tabs, sharing a same window, but I want they each had a separate window, can tauri do this? If so, how?

Sorry if I've missed anything, but i've been googling for a long time, checked the docs and issues of tauri and tao, got nothing at all.

multiple windows sharing a window like tabs

wo52616111 avatar Apr 18 '22 09:04 wo52616111

Could you please fill out the rest of the information required like tauri info? This is definitely not the default behavior at all so it'd be good to know which platform you're on.

JonasKruckenberg avatar Apr 18 '22 11:04 JonasKruckenberg

Sorry for for the lack of information. This is what I output under the tauri project:

Environment
  › OS: Mac OS 12.3.0 X64
  › Node.js: 16.13.2
  › npm: 8.1.2
  › pnpm: Not installed!
  › yarn: 1.22.17
  › rustup: 1.24.3
  › rustc: 1.59.0
  › cargo: 1.59.0
  › Rust toolchain: stable-aarch64-apple-darwin 

Packages
  › @tauri-apps/cli [NPM]: 1.0.0-rc.7
  › @tauri-apps/api [NPM]: Not installed!
  › tauri [RUST]: no manifest (no lockfile),
  › tauri-build [RUST]: no manifest (no lockfile),
  › tao [RUST]: no manifest (no lockfile),
  › wry [RUST]: no manifest (no lockfile),

App
  › build-type: bundle
  › CSP: default-src 'self'
  › distDir: ["index.html"]
  › devPath: ["index.html"]

App directory structure
  ├─ .husky
  ├─ tooling
  ├─ core
  ├─ audits
  ├─ target
  ├─ node_modules
  ├─ .changes
  ├─ .scripts
  ├─ examples
  ├─ .github
  └─ .git

This is me running the "multiwindow" example (with some irrelevant js code commented out) of this project, I found that all windows created by rust become tabs of a window, and all windows created by js are in another window:

https://user-images.githubusercontent.com/12783466/163813075-30b928af-ce5c-43b4-9eba-464b3aa7f7bb.mp4

wo52616111 avatar Apr 18 '22 13:04 wo52616111

This behavior is a configuration option in your macOS System Preferences. Open the System Preferences app, click on General, and change Prefer tabs to in fullscreen or never.

lucasfernog avatar Apr 18 '22 13:04 lucasfernog

@lucasfernog Thanks for pointing out, but I think the problem is only partially solved, why the first click of the create window button in my case above ignoring my system settings and open a new window? That's exactly what I want, to make sure a new window opens, regardless of the system settings. This system setting never affects my results when I click on the New Window option in, say, vscode, does it?

Let me change the question to, how do I make sure that I can create multiple separate windows when I want to?

wo52616111 avatar Apr 18 '22 16:04 wo52616111

I don't think we're doing anything special in this case, but i'll reopen so we can track it.

lucasfernog avatar Apr 18 '22 16:04 lucasfernog

Looks like we can use NSWindow::setAllowsAutomaticWindowTabbing_(ns_window, NO); to force the tab option, but we might need to wait for v1 to be released.

lucasfernog avatar Apr 18 '22 23:04 lucasfernog

Now that v1 was released, is this now available/achievable?

goenning avatar Jul 24 '22 20:07 goenning

any code example pls?? I was trying this but my code is incomplete

#[allow(dead_code)]
#[tauri::command]
async fn open_docs() {
    let handle: tauri::AppHandle = tauri::AppHandle();
    let docs_window = tauri::WindowBuilder::new(
        &handle,
        "external", /* the unique window label */
        tauri::WindowUrl::External("https://tauri.app/".parse().unwrap()),
    ).build().unwrap();
}

aliscie avatar Oct 08 '22 10:10 aliscie

@aliscie inject the app handle like this and it should work: https://tauri.app/v1/guides/features/command#accessing-an-apphandle-in-commands

FabianLars avatar Oct 08 '22 10:10 FabianLars

https://tauri.app/v1/guides/features/command#accessing-an-apphandle-in-commands

in the frontend how can I run this? like this?

//my rust frontend
let app_handle = somthing_that_i_dont_know

spawn_local(async move {
invoke_async("my_custom_command",(app_handle,)).await
    });

My tasks is very simple, i just have a button and I need to open new dinow when i click it.

aliscie avatar Oct 08 '22 10:10 aliscie

i don't know anything about rust frontends tbh, but you don't need to inject the app_handle yourself, Tauri injects it for you (in that regard rust frontends are the same as js frontends)

FabianLars avatar Oct 08 '22 10:10 FabianLars

any code example pls??

This is what I have in the setup hook in my app:

#[cfg(target_os = "macos")]
{
	// Disable the automatic creation of "Show Tab Bar" etc menu items on macOS
	let window = app.get_window("main").unwrap();
	unsafe {
		let ns_window = window.ns_window().unwrap() as cocoa::base::id;
		NSWindow::setAllowsAutomaticWindowTabbing_(ns_window, cocoa::base::NO);
	}
}

caesar avatar Oct 08 '22 15:10 caesar