feat: add `clipboard` flag to `WebviewAttributes` [TRI-032] (#12)

This commit is contained in:
Lucas Fernandes Nogueira 2021-10-23 10:05:38 -03:00 committed by Lucas Nogueira
parent 7920ff14e6
commit d42ccfb34f
No known key found for this signature in database
GPG Key ID: 2714B66BCFB01F7F
3 changed files with 23 additions and 11 deletions

View File

@ -0,0 +1,6 @@
---
"tauri": patch
"tauri-runtime": patch
---
Added `clipboard` field on the `WebviewAttributes` struct, which must be set to `true` to enable clipboard access on the webview.

View File

@ -3149,6 +3149,11 @@ fn create_webview(
vacant.insert(web_context)
}
};
if webview_attributes.clipboard {
webview_builder.webview.clipboard = true;
}
let webview = webview_builder
.with_web_context(web_context)
.build()

View File

@ -18,22 +18,13 @@ use windows::Win32::Foundation::HWND;
use std::{fmt, path::PathBuf};
/// The attributes used to create an webview.
#[derive(Debug)]
pub struct WebviewAttributes {
pub url: WindowUrl,
pub initialization_scripts: Vec<String>,
pub data_directory: Option<PathBuf>,
pub file_drop_handler_enabled: bool,
}
impl fmt::Debug for WebviewAttributes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WebviewAttributes")
.field("url", &self.url)
.field("initialization_scripts", &self.initialization_scripts)
.field("data_directory", &self.data_directory)
.field("file_drop_handler_enabled", &self.file_drop_handler_enabled)
.finish()
}
pub clipboard: bool,
}
impl WebviewAttributes {
@ -44,6 +35,7 @@ impl WebviewAttributes {
initialization_scripts: Vec::new(),
data_directory: None,
file_drop_handler_enabled: true,
clipboard: false,
}
}
@ -64,6 +56,15 @@ impl WebviewAttributes {
self.file_drop_handler_enabled = false;
self
}
/// Enables clipboard access for the page rendered on **Linux** and **Windows**.
///
/// **macOS** doesn't provide such method and is always enabled by default,
/// but you still need to add menu item accelerators to use shortcuts.
pub fn enable_clipboard_access(mut self) -> Self {
self.clipboard = true;
self
}
}
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).