feat: expose the setAutoResize API for webviews in @tauri-apps/api (#13318) (#13319)

This commit is contained in:
Kingsword
2025-04-27 10:27:23 +08:00
committed by GitHub
parent 568efb4568
commit 50ebddaa2d
6 changed files with 54 additions and 1 deletions

View File

@@ -0,0 +1,7 @@
---
"tauri": "minor:feat"
"@tauri-apps/api": "minor:feat"
---
Expose the `setAutoResize` API for webviews in `@tauri-apps/api`.

View File

@@ -135,6 +135,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
("set_webview_size", false),
("set_webview_position", false),
("set_webview_focus", false),
("set_webview_auto_resize", false),
("set_webview_zoom", false),
("webview_hide", false),
("webview_show", false),

View File

@@ -203,6 +203,32 @@ Denies the reparent command without any pre-configured scope.
<tr>
<td>
`core:webview:allow-set-webview-auto-resize`
</td>
<td>
Enables the set_webview_auto_resize command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`core:webview:deny-set-webview-auto-resize`
</td>
<td>
Denies the set_webview_auto_resize command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`core:webview:allow-set-webview-background-color`
</td>

File diff suppressed because one or more lines are too long

View File

@@ -220,6 +220,7 @@ mod desktop_commands {
setter!(set_webview_size, set_size, Size);
setter!(set_webview_position, set_position, Position);
setter!(set_webview_focus, set_focus);
setter!(set_webview_auto_resize, set_auto_resize, bool);
setter!(webview_hide, hide);
setter!(webview_show, show);
setter!(set_webview_zoom, set_zoom, f64);
@@ -310,6 +311,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
desktop_commands::set_webview_size,
desktop_commands::set_webview_position,
desktop_commands::set_webview_focus,
desktop_commands::set_webview_auto_resize,
desktop_commands::set_webview_background_color,
desktop_commands::set_webview_zoom,
desktop_commands::webview_hide,

View File

@@ -490,6 +490,23 @@ class Webview {
})
}
/**
* Sets whether the webview should automatically grow and shrink its size and position when the parent window resizes.
* @example
* ```typescript
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* await getCurrentWebview().setAutoReisze(true);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setAutoResize(autoResize: boolean): Promise<void> {
return invoke('plugin:webview|set_webview_auto_resize', {
label: this.label,
value: autoResize
})
}
/**
* Hide the webview.
* @example