Skip to content

Commit d42ccfb

Browse files
committed
feat: add clipboard flag to WebviewAttributes [TRI-032] (#12)
1 parent 7920ff1 commit d42ccfb

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime": patch
4+
---
5+
6+
Added `clipboard` field on the `WebviewAttributes` struct, which must be set to `true` to enable clipboard access on the webview.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,11 @@ fn create_webview(
31493149
vacant.insert(web_context)
31503150
}
31513151
};
3152+
3153+
if webview_attributes.clipboard {
3154+
webview_builder.webview.clipboard = true;
3155+
}
3156+
31523157
let webview = webview_builder
31533158
.with_web_context(web_context)
31543159
.build()

core/tauri-runtime/src/webview.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,13 @@ use windows::Win32::Foundation::HWND;
1818
use std::{fmt, path::PathBuf};
1919

2020
/// The attributes used to create an webview.
21+
#[derive(Debug)]
2122
pub struct WebviewAttributes {
2223
pub url: WindowUrl,
2324
pub initialization_scripts: Vec<String>,
2425
pub data_directory: Option<PathBuf>,
2526
pub file_drop_handler_enabled: bool,
26-
}
27-
28-
impl fmt::Debug for WebviewAttributes {
29-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30-
f.debug_struct("WebviewAttributes")
31-
.field("url", &self.url)
32-
.field("initialization_scripts", &self.initialization_scripts)
33-
.field("data_directory", &self.data_directory)
34-
.field("file_drop_handler_enabled", &self.file_drop_handler_enabled)
35-
.finish()
36-
}
27+
pub clipboard: bool,
3728
}
3829

3930
impl WebviewAttributes {
@@ -44,6 +35,7 @@ impl WebviewAttributes {
4435
initialization_scripts: Vec::new(),
4536
data_directory: None,
4637
file_drop_handler_enabled: true,
38+
clipboard: false,
4739
}
4840
}
4941

@@ -64,6 +56,15 @@ impl WebviewAttributes {
6456
self.file_drop_handler_enabled = false;
6557
self
6658
}
59+
60+
/// Enables clipboard access for the page rendered on **Linux** and **Windows**.
61+
///
62+
/// **macOS** doesn't provide such method and is always enabled by default,
63+
/// but you still need to add menu item accelerators to use shortcuts.
64+
pub fn enable_clipboard_access(mut self) -> Self {
65+
self.clipboard = true;
66+
self
67+
}
6768
}
6869

6970
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).

0 commit comments

Comments
 (0)