@@ -265,38 +265,40 @@ impl NotifyApplication {
265265 // `Invalid client serial` and it's broken.
266266 // Until https://github.com/flatpak/xdg-dbus-proxy/issues/46 is solved, I have to handle these things
267267 // in the main thread. Uff.
268- let ( tx, rx) = glib:: MainContext :: channel ( Default :: default ( ) ) ;
268+
269+ let ( s, r) = async_channel:: unbounded :: < models:: Notification > ( ) ;
270+
269271 let app = self . clone ( ) ;
270- rx. attach ( None , move |n : models:: Notification | {
271- let gio_notif = gio:: Notification :: new ( & n. title ) ;
272- gio_notif. set_body ( Some ( & n. body ) ) ;
273-
274- let action_name = |a| {
275- let json = serde_json:: to_string ( a) . unwrap ( ) ;
276- gio:: Action :: print_detailed_name ( "app.message-action" , Some ( & json. into ( ) ) )
277- } ;
278- for a in n. actions . iter ( ) {
279- match a {
280- models:: Action :: View { label, .. } => {
281- gio_notif. add_button ( & label, & action_name ( a) )
282- }
283- models:: Action :: Http { label, .. } => {
284- gio_notif. add_button ( & label, & action_name ( a) )
272+ glib:: MainContext :: ref_thread_default ( ) . spawn_local ( async move {
273+ while let Ok ( n) = r. recv ( ) . await {
274+ let gio_notif = gio:: Notification :: new ( & n. title ) ;
275+ gio_notif. set_body ( Some ( & n. body ) ) ;
276+
277+ let action_name = |a| {
278+ let json = serde_json:: to_string ( a) . unwrap ( ) ;
279+ gio:: Action :: print_detailed_name ( "app.message-action" , Some ( & json. into ( ) ) )
280+ } ;
281+ for a in n. actions . iter ( ) {
282+ match a {
283+ models:: Action :: View { label, .. } => {
284+ gio_notif. add_button ( & label, & action_name ( a) )
285+ }
286+ models:: Action :: Http { label, .. } => {
287+ gio_notif. add_button ( & label, & action_name ( a) )
288+ }
289+ _ => { }
285290 }
286- _ => { }
287291 }
288- }
289292
290- app. send_notification ( None , & gio_notif) ;
291- glib :: ControlFlow :: Continue
293+ app. send_notification ( None , & gio_notif) ;
294+ }
292295 } ) ;
293-
294296 struct Proxies {
295- notification : glib :: Sender < models:: Notification > ,
297+ notification : async_channel :: Sender < models:: Notification > ,
296298 }
297299 impl models:: NotificationProxy for Proxies {
298300 fn send ( & self , n : models:: Notification ) -> anyhow:: Result < ( ) > {
299- self . notification . send ( n) ?;
301+ self . notification . send_blocking ( n) ?;
300302 Ok ( ( ) )
301303 }
302304 }
@@ -317,7 +319,7 @@ impl NotifyApplication {
317319 Box :: pin ( rx)
318320 }
319321 }
320- let proxies = std:: sync:: Arc :: new ( Proxies { notification : tx } ) ;
322+ let proxies = std:: sync:: Arc :: new ( Proxies { notification : s } ) ;
321323 ntfy_daemon:: system_client:: start (
322324 socket_path. to_owned ( ) ,
323325 dbpath. to_str ( ) . unwrap ( ) ,
0 commit comments