@@ -45,6 +45,8 @@ use crate::geolocator::{Geolocator, IPAddressInfo};
4545use crate :: widget:: Widget ;
4646use crate :: { BoxedFuture , Request , RequestCmd } ;
4747
48+ pub ( super ) const RESTART_BLOCK_BTN : & str = "restart_block_btn" ;
49+
4850macro_rules! define_blocks {
4951 {
5052 $(
@@ -90,20 +92,32 @@ macro_rules! define_blocks {
9092 Self :: $block( config) => futures. push( async move {
9193 let mut error_count: u8 = 0 ;
9294 while let Err ( mut err) = $block:: run( & config, & api) . await {
95+ let Ok ( mut actions) = api. get_actions( ) else { return } ;
96+ if api. set_default_actions( & [
97+ ( MouseButton :: Left , Some ( RESTART_BLOCK_BTN ) , "error_count_reset" ) ,
98+ ] ) . is_err( ) {
99+ return ;
100+ }
93101 let should_retry = api
94102 . max_retries
95103 . map_or( true , |max_retries| error_count < max_retries) ;
96104 if !should_retry {
97105 err = Error {
98- message: Some ( "Block failed too many times, giving up " . into( ) ) ,
106+ message: Some ( "Block terminated " . into( ) ) ,
99107 cause: Some ( Arc :: new( err) ) ,
100108 } ;
101109 }
102- if api. set_error ( err) . is_err( ) {
110+ if api. set_error_with_restartable ( err, !should_retry ) . is_err( ) {
103111 return ;
104112 }
105113 tokio:: select! {
106114 _ = tokio:: time:: sleep( api. error_interval) , if should_retry => ( ) ,
115+ Some ( action) = actions. recv( ) , if !should_retry => match action. as_ref( ) {
116+ "error_count_reset" => {
117+ error_count = 0 ;
118+ } ,
119+ _ => ( ) ,
120+ } ,
107121 _ = api. wait_for_update_request( ) => ( ) ,
108122 }
109123 error_count = error_count. saturating_add( 1 ) ;
@@ -246,12 +260,17 @@ impl CommonApi {
246260 . error ( "Failed to send Request" )
247261 }
248262
249- /// Sends the error to be displayed.
263+ /// Sends the error to be displayed, no restart button will be shown .
250264 pub fn set_error ( & self , error : Error ) -> Result < ( ) > {
265+ self . set_error_with_restartable ( error, false )
266+ }
267+
268+ /// Sends the error to be displayed.
269+ pub fn set_error_with_restartable ( & self , error : Error , restartable : bool ) -> Result < ( ) > {
251270 self . request_sender
252271 . send ( Request {
253272 block_id : self . id ,
254- cmd : RequestCmd :: SetError ( error) ,
273+ cmd : RequestCmd :: SetError { error, restartable } ,
255274 } )
256275 . error ( "Failed to send Request" )
257276 }
0 commit comments