Skip to content

Commit 2aaa801

Browse files
Improve documentation of app > windows (#14058)
1 parent 5349984 commit 2aaa801

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

crates/tauri-cli/config.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"type": "object",
165165
"properties": {
166166
"windows": {
167-
"description": "The app windows configuration.",
167+
"description": "The app windows configuration.\n\n ## Example:\n\n To create a window at app startup\n\n ```json\n {\n \"app\": {\n \"windows\": [\n { \"width\": 800, \"height\": 600 }\n ]\n }\n }\n ```\n\n If not specified, the window's label (its identifier) defaults to \"main\",\n you can use this label to get the window through\n `app.get_webview_window` in Rust or `WebviewWindow.getByLabel` in JavaScript\n\n When working with multiple windows, each window will need an unique label\n\n ```json\n {\n \"app\": {\n \"windows\": [\n { \"label\": \"main\", \"width\": 800, \"height\": 600 },\n { \"label\": \"secondary\", \"width\": 800, \"height\": 600 }\n ]\n }\n }\n ```\n\n You can also set `create` to false and use this config through the Rust APIs\n\n ```json\n {\n \"app\": {\n \"windows\": [\n { \"create\": false, \"width\": 800, \"height\": 600 }\n ]\n }\n }\n ```\n\n and use it like this\n\n ```rust\n tauri::Builder::default()\n .setup(|app| {\n tauri::WebviewWindowBuilder::from_config(app.handle(), app.config().app.windows[0])?.build()?;\n Ok(())\n });\n ```",
168168
"default": [],
169169
"type": "array",
170170
"items": {
@@ -230,7 +230,7 @@
230230
"type": "string"
231231
},
232232
"create": {
233-
"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/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).",
233+
"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/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).\n\n ## Example:\n\n ```rust\n tauri::Builder::default()\n .setup(|app| {\n tauri::WebviewWindowBuilder::from_config(app.handle(), app.config().app.windows[0])?.build()?;\n Ok(())\n });\n ```",
234234
"default": true,
235235
"type": "boolean"
236236
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"type": "object",
165165
"properties": {
166166
"windows": {
167-
"description": "The app windows configuration.",
167+
"description": "The app windows configuration.\n\n ## Example:\n\n To create a window at app startup\n\n ```json\n {\n \"app\": {\n \"windows\": [\n { \"width\": 800, \"height\": 600 }\n ]\n }\n }\n ```\n\n If not specified, the window's label (its identifier) defaults to \"main\",\n you can use this label to get the window through\n `app.get_webview_window` in Rust or `WebviewWindow.getByLabel` in JavaScript\n\n When working with multiple windows, each window will need an unique label\n\n ```json\n {\n \"app\": {\n \"windows\": [\n { \"label\": \"main\", \"width\": 800, \"height\": 600 },\n { \"label\": \"secondary\", \"width\": 800, \"height\": 600 }\n ]\n }\n }\n ```\n\n You can also set `create` to false and use this config through the Rust APIs\n\n ```json\n {\n \"app\": {\n \"windows\": [\n { \"create\": false, \"width\": 800, \"height\": 600 }\n ]\n }\n }\n ```\n\n and use it like this\n\n ```rust\n tauri::Builder::default()\n .setup(|app| {\n tauri::WebviewWindowBuilder::from_config(app.handle(), app.config().app.windows[0])?.build()?;\n Ok(())\n });\n ```",
168168
"default": [],
169169
"type": "array",
170170
"items": {
@@ -230,7 +230,7 @@
230230
"type": "string"
231231
},
232232
"create": {
233-
"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/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).",
233+
"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/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).\n\n ## Example:\n\n ```rust\n tauri::Builder::default()\n .setup(|app| {\n tauri::WebviewWindowBuilder::from_config(app.handle(), app.config().app.windows[0])?.build()?;\n Ok(())\n });\n ```",
234234
"default": true,
235235
"type": "boolean"
236236
},

crates/tauri-utils/src/config.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,16 @@ pub struct WindowConfig {
15591559
///
15601560
/// When this is set to `false` you must manually grab the config object via `app.config().app.windows`
15611561
/// and create it with [`WebviewWindowBuilder::from_config`](https://docs.rs/tauri/2/tauri/webview/struct.WebviewWindowBuilder.html#method.from_config).
1562+
///
1563+
/// ## Example:
1564+
///
1565+
/// ```rust
1566+
/// tauri::Builder::default()
1567+
/// .setup(|app| {
1568+
/// tauri::WebviewWindowBuilder::from_config(app.handle(), app.config().app.windows[0])?.build()?;
1569+
/// Ok(())
1570+
/// });
1571+
/// ```
15621572
#[serde(default = "default_true")]
15631573
pub create: bool,
15641574
/// The window webview URL.
@@ -2557,6 +2567,59 @@ impl Default for PatternKind {
25572567
#[serde(rename_all = "camelCase", deny_unknown_fields)]
25582568
pub struct AppConfig {
25592569
/// The app windows configuration.
2570+
///
2571+
/// ## Example:
2572+
///
2573+
/// To create a window at app startup
2574+
///
2575+
/// ```json
2576+
/// {
2577+
/// "app": {
2578+
/// "windows": [
2579+
/// { "width": 800, "height": 600 }
2580+
/// ]
2581+
/// }
2582+
/// }
2583+
/// ```
2584+
///
2585+
/// If not specified, the window's label (its identifier) defaults to "main",
2586+
/// you can use this label to get the window through
2587+
/// `app.get_webview_window` in Rust or `WebviewWindow.getByLabel` in JavaScript
2588+
///
2589+
/// When working with multiple windows, each window will need an unique label
2590+
///
2591+
/// ```json
2592+
/// {
2593+
/// "app": {
2594+
/// "windows": [
2595+
/// { "label": "main", "width": 800, "height": 600 },
2596+
/// { "label": "secondary", "width": 800, "height": 600 }
2597+
/// ]
2598+
/// }
2599+
/// }
2600+
/// ```
2601+
///
2602+
/// You can also set `create` to false and use this config through the Rust APIs
2603+
///
2604+
/// ```json
2605+
/// {
2606+
/// "app": {
2607+
/// "windows": [
2608+
/// { "create": false, "width": 800, "height": 600 }
2609+
/// ]
2610+
/// }
2611+
/// }
2612+
/// ```
2613+
///
2614+
/// and use it like this
2615+
///
2616+
/// ```rust
2617+
/// tauri::Builder::default()
2618+
/// .setup(|app| {
2619+
/// tauri::WebviewWindowBuilder::from_config(app.handle(), app.config().app.windows[0])?.build()?;
2620+
/// Ok(())
2621+
/// });
2622+
/// ```
25602623
#[serde(default)]
25612624
pub windows: Vec<WindowConfig>,
25622625
/// Security configuration.

0 commit comments

Comments
 (0)