Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wo52616111 opened this issue Apr 18, 2022 · 12 comments · Fixed by #5399
Closed

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

wo52616111 opened this issue Apr 18, 2022 · 12 comments · Fixed by #5399
Labels
status: backlog Issue is ready and we can work on it type: feature request

Comments

@wo52616111
Copy link

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

@JonasKruckenberg
Copy link
Contributor

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.

@wo52616111
Copy link
Author

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:

output.mp4

@lucasfernog
Copy link
Member

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.

@wo52616111
Copy link
Author

@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?

@lucasfernog
Copy link
Member

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

@lucasfernog lucasfernog reopened this Apr 18, 2022
@lucasfernog
Copy link
Member

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.

@goenning
Copy link
Contributor

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

@aliscie
Copy link

aliscie commented Oct 8, 2022

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();
}

@FabianLars
Copy link
Sponsor Member

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

@amrbashir amrbashir added the status: backlog Issue is ready and we can work on it label Oct 8, 2022
@aliscie
Copy link

aliscie commented Oct 8, 2022

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.

@FabianLars
Copy link
Sponsor Member

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)

@caesar
Copy link
Contributor

caesar commented Oct 8, 2022

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);
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: backlog Issue is ready and we can work on it type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants