@@ -117,7 +117,7 @@ impl FileDialogResult for DesktopFileDialogResult {
117
117
pub struct DesktopUiBackend {
118
118
window : Rc < Window > ,
119
119
cursor_visible : bool ,
120
- clipboard : Clipboard ,
120
+ clipboard : Option < Clipboard > ,
121
121
preferences : GlobalPreferences ,
122
122
preferred_cursor : MouseCursor ,
123
123
open_url_mode : OpenURLMode ,
@@ -136,7 +136,7 @@ impl DesktopUiBackend {
136
136
Ok ( Self {
137
137
window,
138
138
cursor_visible : true ,
139
- clipboard : Clipboard :: new ( ) . context ( "Couldn't get platform clipboard" ) ? ,
139
+ clipboard : Clipboard :: new ( ) . ok ( ) ,
140
140
preferences,
141
141
preferred_cursor : MouseCursor :: Arrow ,
142
142
open_url_mode,
@@ -175,12 +175,18 @@ impl UiBackend for DesktopUiBackend {
175
175
}
176
176
177
177
fn clipboard_content ( & mut self ) -> String {
178
- self . clipboard . get_text ( ) . unwrap_or_default ( )
178
+ if let Some ( ref mut clipboard) = self . clipboard {
179
+ clipboard. get_text ( ) . unwrap_or_default ( )
180
+ } else {
181
+ "" . to_string ( )
182
+ }
179
183
}
180
184
181
185
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) ;
186
+ if let Some ( ref mut clipboard) = self . clipboard {
187
+ if let Err ( e) = clipboard. set_text ( content) {
188
+ error ! ( "Couldn't set clipboard contents: {:?}" , e) ;
189
+ }
184
190
}
185
191
}
186
192
0 commit comments