core: Add clipboard_content getter

This commit is contained in:
jmckiern 2023-05-09 01:01:32 -05:00 committed by Nathan Adams
parent 95b0b29310
commit 67d74047a9
3 changed files with 18 additions and 0 deletions

View File

@ -15,6 +15,9 @@ pub trait UiBackend {
/// Changes the mouse cursor image. /// Changes the mouse cursor image.
fn set_mouse_cursor(&mut self, cursor: MouseCursor); fn set_mouse_cursor(&mut self, cursor: MouseCursor);
/// Get the clipboard content
fn clipboard_content(&mut self) -> String;
/// Sets the clipboard to the given content. /// Sets the clipboard to the given content.
fn set_clipboard_content(&mut self, content: String); fn set_clipboard_content(&mut self, content: String);
@ -145,6 +148,10 @@ impl UiBackend for NullUiBackend {
fn set_mouse_cursor(&mut self, _cursor: MouseCursor) {} fn set_mouse_cursor(&mut self, _cursor: MouseCursor) {}
fn clipboard_content(&mut self) -> String {
"".to_string()
}
fn set_clipboard_content(&mut self, _content: String) {} fn set_clipboard_content(&mut self, _content: String) {}
fn set_fullscreen(&mut self, _is_full: bool) -> Result<(), FullscreenError> { fn set_fullscreen(&mut self, _is_full: bool) -> Result<(), FullscreenError> {

View File

@ -62,6 +62,12 @@ impl UiBackend for DesktopUiBackend {
self.window.set_cursor_icon(icon); self.window.set_cursor_icon(icon);
} }
fn clipboard_content(&mut self) -> String {
self.clipboard
.get_text()
.unwrap_or_else(|_| "".to_string())
}
fn set_clipboard_content(&mut self, content: String) { fn set_clipboard_content(&mut self, content: String) {
if let Err(e) = self.clipboard.set_text(content) { if let Err(e) = self.clipboard.set_text(content) {
error!("Couldn't set clipboard contents: {:?}", e); error!("Couldn't set clipboard contents: {:?}", e);

View File

@ -65,6 +65,11 @@ impl UiBackend for WebUiBackend {
self.update_mouse_cursor(); self.update_mouse_cursor();
} }
fn clipboard_content(&mut self) -> String {
tracing::warn!("get clipboard not implemented");
"".to_string()
}
fn set_clipboard_content(&mut self, content: String) { fn set_clipboard_content(&mut self, content: String) {
// We use `document.execCommand("copy")` as `navigator.clipboard.writeText("string")` // We use `document.execCommand("copy")` as `navigator.clipboard.writeText("string")`
// is available only in secure contexts (HTTPS). // is available only in secure contexts (HTTPS).