Skip to content

Commit 50ebdda

Browse files
authored
feat: expose the setAutoResize API for webviews in @tauri-apps/api (#13318) (#13319)
1 parent 568efb4 commit 50ebdda

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": "minor:feat"
3+
"@tauri-apps/api": "minor:feat"
4+
---
5+
6+
Expose the `setAutoResize` API for webviews in `@tauri-apps/api`.
7+

crates/tauri/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
135135
("set_webview_size", false),
136136
("set_webview_position", false),
137137
("set_webview_focus", false),
138+
("set_webview_auto_resize", false),
138139
("set_webview_zoom", false),
139140
("webview_hide", false),
140141
("webview_show", false),

crates/tauri/permissions/webview/autogenerated/reference.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,32 @@ Denies the reparent command without any pre-configured scope.
203203
<tr>
204204
<td>
205205

206+
`core:webview:allow-set-webview-auto-resize`
207+
208+
</td>
209+
<td>
210+
211+
Enables the set_webview_auto_resize command without any pre-configured scope.
212+
213+
</td>
214+
</tr>
215+
216+
<tr>
217+
<td>
218+
219+
`core:webview:deny-set-webview-auto-resize`
220+
221+
</td>
222+
<td>
223+
224+
Denies the set_webview_auto_resize command without any pre-configured scope.
225+
226+
</td>
227+
</tr>
228+
229+
<tr>
230+
<td>
231+
206232
`core:webview:allow-set-webview-background-color`
207233

208234
</td>

crates/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri/src/webview/plugin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ mod desktop_commands {
220220
setter!(set_webview_size, set_size, Size);
221221
setter!(set_webview_position, set_position, Position);
222222
setter!(set_webview_focus, set_focus);
223+
setter!(set_webview_auto_resize, set_auto_resize, bool);
223224
setter!(webview_hide, hide);
224225
setter!(webview_show, show);
225226
setter!(set_webview_zoom, set_zoom, f64);
@@ -310,6 +311,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
310311
desktop_commands::set_webview_size,
311312
desktop_commands::set_webview_position,
312313
desktop_commands::set_webview_focus,
314+
desktop_commands::set_webview_auto_resize,
313315
desktop_commands::set_webview_background_color,
314316
desktop_commands::set_webview_zoom,
315317
desktop_commands::webview_hide,

packages/api/src/webview.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,23 @@ class Webview {
490490
})
491491
}
492492

493+
/**
494+
* Sets whether the webview should automatically grow and shrink its size and position when the parent window resizes.
495+
* @example
496+
* ```typescript
497+
* import { getCurrentWebview } from '@tauri-apps/api/webview';
498+
* await getCurrentWebview().setAutoReisze(true);
499+
* ```
500+
*
501+
* @returns A promise indicating the success or failure of the operation.
502+
*/
503+
async setAutoResize(autoResize: boolean): Promise<void> {
504+
return invoke('plugin:webview|set_webview_auto_resize', {
505+
label: this.label,
506+
value: autoResize
507+
})
508+
}
509+
493510
/**
494511
* Hide the webview.
495512
* @example

0 commit comments

Comments
 (0)