Skip to content

Commit ad294d2

Browse files
feat(core): add app > windows > create option to disable window creation at startup (#11032)
* feat(core): add `app > windows > create` option to disable window creation at startup closes #10950 * clippy * clippy * update docs * Update .changes/window-config-create.md --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
1 parent ddf6915 commit ad294d2

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

.changes/window-config-create.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": "patch:feat"
3+
"tauri-utils": "patch:feat"
4+
---
5+
6+
Add `app > windows > create` option to choose whether to create this window at app startup or not.

crates/tauri-bundler/src/bundle/windows/msi/wix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ pub fn build_wix_app_installer(
520520
data.insert("upgrade_code", to_json(upgrade_code.as_str()));
521521
let product_code = Uuid::new_v5(
522522
&Uuid::NAMESPACE_DNS,
523-
&settings.bundle_identifier().as_bytes(),
523+
settings.bundle_identifier().as_bytes(),
524524
)
525525
.to_string();
526526
data.insert("product_code", to_json(product_code.as_str()));

crates/tauri-cli/config.schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"type": "object",
161161
"properties": {
162162
"windows": {
163-
"description": "The windows configuration.",
163+
"description": "The app windows configuration.",
164164
"default": [],
165165
"type": "array",
166166
"items": {
@@ -225,6 +225,11 @@
225225
"default": "main",
226226
"type": "string"
227227
},
228+
"create": {
229+
"description": "Whether Tauri should create this window at app startup or not.\n\n When this is set to `false` you must manually grab the config object via `app.config().app.windows`\n and create it with [`WebviewWindowBuilder::from_config`](https://docs.rs/tauri/2.0.0-rc/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).",
230+
"default": true,
231+
"type": "boolean"
232+
},
228233
"url": {
229234
"description": "The window webview URL.",
230235
"default": "index.html",

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"type": "object",
161161
"properties": {
162162
"windows": {
163-
"description": "The windows configuration.",
163+
"description": "The app windows configuration.",
164164
"default": [],
165165
"type": "array",
166166
"items": {
@@ -225,6 +225,11 @@
225225
"default": "main",
226226
"type": "string"
227227
},
228+
"create": {
229+
"description": "Whether Tauri should create this window at app startup or not.\n\n When this is set to `false` you must manually grab the config object via `app.config().app.windows`\n and create it with [`WebviewWindowBuilder::from_config`](https://docs.rs/tauri/2.0.0-rc/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).",
230+
"default": true,
231+
"type": "boolean"
232+
},
228233
"url": {
229234
"description": "The window webview URL.",
230235
"default": "index.html",

crates/tauri-utils/src/config.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,12 @@ pub struct WindowConfig {
12591259
/// The window identifier. It must be alphanumeric.
12601260
#[serde(default = "default_window_label")]
12611261
pub label: String,
1262+
/// Whether Tauri should create this window at app startup or not.
1263+
///
1264+
/// When this is set to `false` you must manually grab the config object via `app.config().app.windows`
1265+
/// and create it with [`WebviewWindowBuilder::from_config`](https://docs.rs/tauri/2.0.0-rc/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).
1266+
#[serde(default = "default_true")]
1267+
pub create: bool,
12621268
/// The window webview URL.
12631269
#[serde(default)]
12641270
pub url: WebviewUrl,
@@ -1455,6 +1461,7 @@ impl Default for WindowConfig {
14551461
Self {
14561462
label: default_window_label(),
14571463
url: WebviewUrl::default(),
1464+
create: true,
14581465
user_agent: None,
14591466
drag_drop_enabled: true,
14601467
center: false,
@@ -1835,7 +1842,7 @@ impl Default for PatternKind {
18351842
#[cfg_attr(feature = "schema", derive(JsonSchema))]
18361843
#[serde(rename_all = "camelCase", deny_unknown_fields)]
18371844
pub struct AppConfig {
1838-
/// The windows configuration.
1845+
/// The app windows configuration.
18391846
#[serde(default)]
18401847
pub windows: Vec<WindowConfig>,
18411848
/// Security configuration.
@@ -2423,6 +2430,7 @@ mod build {
24232430
impl ToTokens for WindowConfig {
24242431
fn to_tokens(&self, tokens: &mut TokenStream) {
24252432
let label = str_lit(&self.label);
2433+
let create = &self.create;
24262434
let url = &self.url;
24272435
let user_agent = opt_str_lit(self.user_agent.as_ref());
24282436
let drag_drop_enabled = self.drag_drop_enabled;
@@ -2469,6 +2477,7 @@ mod build {
24692477
::tauri::utils::config::WindowConfig,
24702478
label,
24712479
url,
2480+
create,
24722481
user_agent,
24732482
drag_drop_enabled,
24742483
center,

crates/tauri/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,8 +2014,8 @@ impl<R: Runtime> HasDisplayHandle for App<R> {
20142014
fn setup<R: Runtime>(app: &mut App<R>) -> crate::Result<()> {
20152015
app.ran_setup = true;
20162016

2017-
for window_config in app.config().app.windows.clone() {
2018-
WebviewWindowBuilder::from_config(app.handle(), &window_config)?.build()?;
2017+
for window_config in app.config().app.windows.iter().filter(|w| w.create) {
2018+
WebviewWindowBuilder::from_config(app.handle(), window_config)?.build()?;
20192019
}
20202020

20212021
app.manager.assets.setup(app);

0 commit comments

Comments
 (0)