Skip to content

Commit cffa815

Browse files
committed
desktop: Make clipboard support optional
On wayland ruffle only supports `wlr-data-control-unstable-v1` which is not intended to be supported by all compositors.
1 parent a71e8c1 commit cffa815

File tree

1 file changed

+13
-5
lines changed
  • desktop/src/backends

1 file changed

+13
-5
lines changed

desktop/src/backends/ui.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl FileDialogResult for DesktopFileDialogResult {
117117
pub struct DesktopUiBackend {
118118
window: Rc<Window>,
119119
cursor_visible: bool,
120-
clipboard: Clipboard,
120+
clipboard: Option<Clipboard>,
121121
preferences: GlobalPreferences,
122122
preferred_cursor: MouseCursor,
123123
open_url_mode: OpenURLMode,
@@ -136,7 +136,9 @@ impl DesktopUiBackend {
136136
Ok(Self {
137137
window,
138138
cursor_visible: true,
139-
clipboard: Clipboard::new().context("Couldn't get platform clipboard")?,
139+
clipboard: Clipboard::new()
140+
.context("Couldn't get platform clipboard")
141+
.ok(),
140142
preferences,
141143
preferred_cursor: MouseCursor::Arrow,
142144
open_url_mode,
@@ -175,12 +177,18 @@ impl UiBackend for DesktopUiBackend {
175177
}
176178

177179
fn clipboard_content(&mut self) -> String {
178-
self.clipboard.get_text().unwrap_or_default()
180+
if let Some(ref mut clipboard) = self.clipboard {
181+
clipboard.get_text().unwrap_or_default()
182+
} else {
183+
"".to_string()
184+
}
179185
}
180186

181187
fn set_clipboard_content(&mut self, content: String) {
182-
if let Err(e) = self.clipboard.set_text(content) {
183-
error!("Couldn't set clipboard contents: {:?}", e);
188+
if let Some(ref mut clipboard) = self.clipboard {
189+
if let Err(e) = clipboard.set_text(content) {
190+
error!("Couldn't set clipboard contents: {:?}", e);
191+
}
184192
}
185193
}
186194

0 commit comments

Comments
 (0)