rdw: fix run-time panic because we are not on MainContext

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2023-01-17 18:26:35 +04:00
parent 3712905ec1
commit 544a407561

View File

@ -99,8 +99,8 @@ impl ClipboardHandler for InnerHandler {
selection: ClipboardSelection,
mimes: Vec<String>,
) -> qemu_display::Result<(String, Vec<u8>)> {
// we have to spawn a local future, because clipboard is not Send
let (sender, receiver) = futures::channel::oneshot::channel();
glib::MainContext::default().invoke(move || {
glib::MainContext::default().spawn_local(async move {
let res = if let Some((clipboard, _)) = clipboard_from_selection(selection) {
let m: Vec<_> = mimes.iter().map(|s| s.as_str()).collect();
@ -134,6 +134,8 @@ impl ClipboardHandler for InnerHandler {
};
sender.send(res).unwrap()
});
});
match receiver.await {
Ok(res) => res,
Err(e) => Err(qemu_display::Error::Failed(format!(