Skip to content

Commit

Permalink
feat(core): add app > windows > create option to disable window cre…
Browse files Browse the repository at this point in the history
…ation 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>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent ddf6915 commit ad294d2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changes/window-config-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": "patch:feat"
"tauri-utils": "patch:feat"
---

Add `app > windows > create` option to choose whether to create this window at app startup or not.
2 changes: 1 addition & 1 deletion crates/tauri-bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ pub fn build_wix_app_installer(
data.insert("upgrade_code", to_json(upgrade_code.as_str()));
let product_code = Uuid::new_v5(
&Uuid::NAMESPACE_DNS,
&settings.bundle_identifier().as_bytes(),
settings.bundle_identifier().as_bytes(),
)
.to_string();
data.insert("product_code", to_json(product_code.as_str()));
Expand Down
7 changes: 6 additions & 1 deletion crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"type": "object",
"properties": {
"windows": {
"description": "The windows configuration.",
"description": "The app windows configuration.",
"default": [],
"type": "array",
"items": {
Expand Down Expand Up @@ -225,6 +225,11 @@
"default": "main",
"type": "string"
},
"create": {
"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).",
"default": true,
"type": "boolean"
},
"url": {
"description": "The window webview URL.",
"default": "index.html",
Expand Down
7 changes: 6 additions & 1 deletion crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"type": "object",
"properties": {
"windows": {
"description": "The windows configuration.",
"description": "The app windows configuration.",
"default": [],
"type": "array",
"items": {
Expand Down Expand Up @@ -225,6 +225,11 @@
"default": "main",
"type": "string"
},
"create": {
"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).",
"default": true,
"type": "boolean"
},
"url": {
"description": "The window webview URL.",
"default": "index.html",
Expand Down
11 changes: 10 additions & 1 deletion crates/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,12 @@ pub struct WindowConfig {
/// The window identifier. It must be alphanumeric.
#[serde(default = "default_window_label")]
pub label: String,
/// Whether Tauri should create this window at app startup or not.
///
/// When this is set to `false` you must manually grab the config object via `app.config().app.windows`
/// and create it with [`WebviewWindowBuilder::from_config`](https://docs.rs/tauri/2.0.0-rc/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).
#[serde(default = "default_true")]
pub create: bool,
/// The window webview URL.
#[serde(default)]
pub url: WebviewUrl,
Expand Down Expand Up @@ -1455,6 +1461,7 @@ impl Default for WindowConfig {
Self {
label: default_window_label(),
url: WebviewUrl::default(),
create: true,
user_agent: None,
drag_drop_enabled: true,
center: false,
Expand Down Expand Up @@ -1835,7 +1842,7 @@ impl Default for PatternKind {
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct AppConfig {
/// The windows configuration.
/// The app windows configuration.
#[serde(default)]
pub windows: Vec<WindowConfig>,
/// Security configuration.
Expand Down Expand Up @@ -2423,6 +2430,7 @@ mod build {
impl ToTokens for WindowConfig {
fn to_tokens(&self, tokens: &mut TokenStream) {
let label = str_lit(&self.label);
let create = &self.create;
let url = &self.url;
let user_agent = opt_str_lit(self.user_agent.as_ref());
let drag_drop_enabled = self.drag_drop_enabled;
Expand Down Expand Up @@ -2469,6 +2477,7 @@ mod build {
::tauri::utils::config::WindowConfig,
label,
url,
create,
user_agent,
drag_drop_enabled,
center,
Expand Down
4 changes: 2 additions & 2 deletions crates/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,8 +2014,8 @@ impl<R: Runtime> HasDisplayHandle for App<R> {
fn setup<R: Runtime>(app: &mut App<R>) -> crate::Result<()> {
app.ran_setup = true;

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

app.manager.assets.setup(app);
Expand Down

0 comments on commit ad294d2

Please sign in to comment.