Skip to content

Commit 153e412

Browse files
Update docs for WebviewWindowBuilder::from_config
The documentation for `WebviewWindowBuilder::from_config` mentions changing the label of the new `WebviewWindowBuilder`, which is not possible. Instead, the label must be changed in the `WindowConfig` that is passed into `WebviewWindowBuilder::from_config`. This change fixes that description and adds an example code snippet for this use-case.
1 parent 208f4bc commit 153e412

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

crates/tauri/src/webview/webview_window.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
110110

111111
/// Initializes a webview window builder from a [`WindowConfig`] from tauri.conf.json.
112112
/// Keep in mind that you can't create 2 windows with the same `label` so make sure
113-
/// that the initial window was closed or change the label of the new [`WebviewWindowBuilder`].
113+
/// that the initial window was closed or change the label of the cloned [`WindowConfig`].
114114
///
115115
/// # Known issues
116116
///
@@ -124,7 +124,22 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
124124
/// ```
125125
/// #[tauri::command]
126126
/// async fn reopen_window(app: tauri::AppHandle) {
127-
/// let webview_window = tauri::WebviewWindowBuilder::from_config(&app, &app.config().app.windows.get(0).unwrap().clone())
127+
/// let webview_window = tauri::WebviewWindowBuilder::from_config(&app, &app.config().app.windows.get(0).unwrap())
128+
/// .unwrap()
129+
/// .build()
130+
/// .unwrap();
131+
/// }
132+
/// ```
133+
///
134+
/// - Create a window in a command from a config with a specific label, and change its label so multiple instances can exist:
135+
///
136+
/// ```
137+
/// #[tauri::command]
138+
/// async fn open_window_multiple(app: tauri::AppHandle) {
139+
/// let mut conf = &app.config().app.windows.iter().find(|c| c.label == "template-for-multiwindow").unwrap().clone();
140+
/// // This should be a unique label for all windows. For example, we can use a random UUID:
141+
/// conf.label = format!("my-multiwindow-{}", uuid::Uuid::new_v4());
142+
/// let webview_window = tauri::WebviewWindowBuilder::from_config(&app, conf)
128143
/// .unwrap()
129144
/// .build()
130145
/// .unwrap();

0 commit comments

Comments
 (0)