From 83f8c2407ea80fe97ecb4d8d8435b795f4243c1c Mon Sep 17 00:00:00 2001 From: ranfdev Date: Wed, 15 Nov 2023 12:11:39 +0100 Subject: [PATCH] spawn with idle priority --- src/widgets/window.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/widgets/window.rs b/src/widgets/window.rs index 1889b5a..d45ace0 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -30,16 +30,19 @@ impl> SpawnWithToast for W { .ancestor(adw::ToastOverlay::static_type()) .and_downcast(); let win: Option = self.ancestor(NotifyWindow::static_type()).and_downcast(); - glib::MainContext::default().spawn_local(async move { - if let Err(e) = f.await { - if let Some(o) = toast_overlay - .as_ref() - .or_else(|| win.as_ref().map(|win| win.imp().toast_overlay.as_ref())) - { - o.add_toast(adw::Toast::builder().title(&e.to_string()).build()) + glib::MainContext::ref_thread_default().spawn_local_with_priority( + glib::Priority::DEFAULT_IDLE, + async move { + if let Err(e) = f.await { + if let Some(o) = toast_overlay + .as_ref() + .or_else(|| win.as_ref().map(|win| win.imp().toast_overlay.as_ref())) + { + o.add_toast(adw::Toast::builder().title(&e.to_string()).build()) + } } - } - }); + }, + ); } }