-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[feat] Allow for windows to spawn manually #10950
Comments
Having recently run into this same problem, there is We can imagine adding a boolean field to the window config definition, like let webview_window = tauri::WebviewWindowBuilder::from_config(&app, &app.config().app.windows.get(0).unwrap().clone())
.unwrap()
.build()
.unwrap(); Setting aside the rather noisy call, relative to the simplicity of the task, the crucial part here that defines which window is created is To pursue that point:
It's not clear how the "initial window" gets its label—I'm assuming Tauri just sets it to (Is there a reason that the config file defines window definitions in an array, instead of a dict keyed to each window's label? That seems like it would be an improvement in a few regards.) Overall, there's a bit of a mess in store for anyone who wants to launch the initial window(s) from their own Rust code while still using a JSON file to define the window configuration. I just caved and redefined everything again in code, even though this isn't ideal. |
I think creating a window manually instead of defining it in the conf file. That's how I implemented it for my app. My |
@martpie Yeah, that's the most straightforward alternative, currently. But if we accept that using a config file has readability benefits enough to merit having window definitions in Tauri's config file to start with (I certainly prefer it, for declarative properties), then it would be nice if it worked for all the basic ways in which one might want to create a window, including from code. But you can't actually define a window in Tauri's config unless you want Tauri to create that window immediately, with no way to tell Tauri to not do this that I can see, except to remove the window definition from the config file entirely. But then you lose the benefits of defining a window that way. |
That's exactly what I am suggesting. Although I would not call the property
I agree. Ideally,
Yes, the default label is
I'm not sure why you wrote that. I have already expressed why this approach is not feasible for the use-case. |
I added
I don't think we need to add any APIs for this as |
Describe the problem
I'm frustrated that windows configured in
tauri.conf.json
spawn automatically during setup phase. TheWindowConfig
allows to hide the window by settingvisible: false
, but that still spawns a hidden window and runs any code that is defined in the page loaded by the webview. In my use-case that is not acceptable, because the main window loads its content from the database and should only run if the database exists and has no pending migrations. Instead, the user should be shown a specific page (e.g.,/error
) that holds the error message.This may seemingly be worked around by manually spawning a window during the setup phase, but this requires to pass any of the over 40
WindowConfig
properties in rust code which worsens readability in my opinion, instead of keeping them in the configuration.Describe the solution you'd like
I would like to have a way of manually spawning windows from the
WindowConfig
. This would also require a newWindowConfig
properties to prevent auto-spawning during the setup phase.Alternatives considered
tauri::WebviewWindowBuilder::new(app, "foo", tauri::WebviewUrl::App("/foo".into())).build()?;
This is not the best workaround as described above.
/error
), but was advised not to do that because it is possible that Tauri loads/
and runs its code, and shows it to the user before I could then navigate to/error
in the setup phase.Additional context
No response
The text was updated successfully, but these errors were encountered: