@@ -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,9 @@ 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 ( )
140
+ . context ( "Couldn't get platform clipboard" )
141
+ . ok ( ) ,
140
142
preferences,
141
143
preferred_cursor : MouseCursor :: Arrow ,
142
144
open_url_mode,
@@ -175,12 +177,18 @@ impl UiBackend for DesktopUiBackend {
175
177
}
176
178
177
179
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
+ }
179
185
}
180
186
181
187
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
+ }
184
192
}
185
193
}
186
194
0 commit comments