@@ -11,41 +11,10 @@ use tracing::warn;
1111
1212use crate :: application:: NotifyApplication ;
1313use crate :: config:: { APP_ID , PROFILE } ;
14+ use crate :: error:: * ;
1415use crate :: subscription:: Subscription ;
1516use crate :: widgets:: * ;
1617
17- pub trait SpawnWithToast {
18- fn spawn_with_near_toast < T , R : std:: fmt:: Display > (
19- & self ,
20- f : impl Future < Output = Result < T , R > > + ' static ,
21- ) ;
22- }
23-
24- impl < W : IsA < gtk:: Widget > > SpawnWithToast for W {
25- fn spawn_with_near_toast < T , R : std:: fmt:: Display > (
26- & self ,
27- f : impl Future < Output = Result < T , R > > + ' static ,
28- ) {
29- let toast_overlay: Option < adw:: ToastOverlay > = self
30- . ancestor ( adw:: ToastOverlay :: static_type ( ) )
31- . and_downcast ( ) ;
32- let win: Option < NotifyWindow > = self . ancestor ( NotifyWindow :: static_type ( ) ) . and_downcast ( ) ;
33- glib:: MainContext :: ref_thread_default ( ) . spawn_local_with_priority (
34- glib:: Priority :: DEFAULT_IDLE ,
35- async move {
36- if let Err ( e) = f. await {
37- if let Some ( o) = toast_overlay
38- . as_ref ( )
39- . or_else ( || win. as_ref ( ) . map ( |win| win. imp ( ) . toast_overlay . as_ref ( ) ) )
40- {
41- o. add_toast ( adw:: Toast :: builder ( ) . title ( & e. to_string ( ) ) . build ( ) )
42- }
43- }
44- } ,
45- ) ;
46- }
47- }
48-
4918mod imp {
5019 use super :: * ;
5120
@@ -169,7 +138,7 @@ mod imp {
169138 } ) ;
170139 klass. install_action ( "win.clear-notifications" , None , |this, _, _| {
171140 this. selected_subscription ( ) . map ( |sub| {
172- this. spawn_with_near_toast ( sub. clear_notifications ( ) ) ;
141+ this. error_boundary ( ) . spawn ( sub. clear_notifications ( ) ) ;
173142 } ) ;
174143 } ) ;
175144 //klass.bind_template_instance_callbacks();
@@ -252,7 +221,10 @@ impl NotifyWindow {
252221 ..models:: Message :: default ( )
253222 } ) ;
254223
255- entry. spawn_with_near_toast ( async move { p. await } ) ;
224+ entry. error_boundary ( ) . spawn ( async move {
225+ p. await ?;
226+ Ok ( ( ) )
227+ } ) ;
256228 } ;
257229 let publishc = publish. clone ( ) ;
258230 imp. entry . connect_activate ( move |_| publishc ( ) ) ;
@@ -294,7 +266,7 @@ impl NotifyWindow {
294266 req. get ( ) . set_topic ( sub. topic . as_str ( ) . into ( ) ) ;
295267 let res = req. send ( ) ;
296268 let this = self . clone ( ) ;
297- self . spawn_with_near_toast ( async move {
269+ self . error_boundary ( ) . spawn ( async move {
298270 let imp = this. imp ( ) ;
299271
300272 // Subscription::new will use the pipelined client to retrieve info about the subscription
@@ -306,7 +278,7 @@ impl NotifyWindow {
306278 let i = imp. subscription_list_model . n_items ( ) - 1 ;
307279 let row = imp. subscription_list . row_at_index ( i as i32 ) ;
308280 imp. subscription_list . select_row ( row. as_ref ( ) ) ;
309- Ok :: < ( ) , capnp :: Error > ( ( ) )
281+ Ok ( ( ) )
310282 } ) ;
311283 }
312284
@@ -320,14 +292,14 @@ impl NotifyWindow {
320292 let res = req. send ( ) ;
321293 let this = self . clone ( ) ;
322294
323- self . spawn_with_near_toast ( async move {
295+ self . error_boundary ( ) . spawn ( async move {
324296 let imp = this. imp ( ) ;
325297 res. promise . await ?;
326298
327299 if let Some ( i) = imp. subscription_list_model . find ( & sub) {
328300 imp. subscription_list_model . remove ( i) ;
329301 }
330- Ok :: < ( ) , capnp :: Error > ( ( ) )
302+ Ok ( ( ) )
331303 } ) ;
332304 }
333305 fn notifier ( & self ) -> & system_notifier:: Client {
@@ -358,14 +330,14 @@ impl NotifyWindow {
358330 let this = self . clone ( ) ;
359331 let req = self . notifier ( ) . list_subscriptions_request ( ) ;
360332 let res = req. send ( ) ;
361- self . spawn_with_near_toast ( async move {
333+ self . error_boundary ( ) . spawn ( async move {
362334 let list = res. promise . await ?;
363335 let list = list. get ( ) ?. get_list ( ) ?;
364336 let imp = this. imp ( ) ;
365337 for sub in list {
366338 imp. subscription_list_model . append ( & Subscription :: new ( sub?) ) ;
367339 }
368- Ok :: < ( ) , capnp :: Error > ( ( ) )
340+ Ok ( ( ) )
369341 } ) ;
370342 }
371343 fn update_banner ( & self , sub : Option < & Subscription > ) {
@@ -429,7 +401,8 @@ impl NotifyWindow {
429401 || ( ( vadj. page_size ( ) + vadj. value ( ) - vadj. upper ( ) ) . abs ( ) <= 1.0 )
430402 {
431403 self . selected_subscription ( ) . map ( |sub| {
432- self . spawn_with_near_toast ( sub. flag_all_as_read ( ) ) ;
404+ self . error_boundary ( )
405+ . spawn ( sub. flag_all_as_read ( ) . map_err ( |e| e. into ( ) ) ) ;
433406 } ) ;
434407 }
435408 }
0 commit comments