@@ -37,7 +37,7 @@ use futures::stream::{FuturesUnordered, StreamExt as _};
37
37
use tokio:: process:: Command ;
38
38
use tokio:: sync:: { Notify , mpsc} ;
39
39
40
- use crate :: blocks:: { BlockAction , BlockError , CommonApi } ;
40
+ use crate :: blocks:: { BlockAction , BlockError , CommonApi , RESTART_BLOCK_BTN } ;
41
41
use crate :: click:: { ClickHandler , MouseButton } ;
42
42
use crate :: config:: { BlockConfigEntry , Config , SharedConfig } ;
43
43
use crate :: errors:: * ;
@@ -131,7 +131,7 @@ struct Request {
131
131
enum RequestCmd {
132
132
SetWidget ( Widget ) ,
133
133
UnsetWidget ,
134
- SetError ( Error ) ,
134
+ SetError { error : Error , restartable : bool } ,
135
135
SetDefaultActions ( & ' static [ ( MouseButton , Option < & ' static str > , & ' static str ) ] ) ,
136
136
SubscribeToActions ( mpsc:: UnboundedSender < BlockAction > ) ,
137
137
}
@@ -186,6 +186,10 @@ impl Block {
186
186
}
187
187
188
188
fn set_error ( & mut self , fullscreen : bool , error : Error ) {
189
+ self . set_error_with_restartable ( fullscreen, false , error) ;
190
+ }
191
+
192
+ fn set_error_with_restartable ( & mut self , fullscreen : bool , restartable : bool , error : Error ) {
189
193
let error = BlockError {
190
194
block_id : self . id ,
191
195
block_name : self . name ,
@@ -202,6 +206,7 @@ impl Block {
202
206
widget. set_values ( map ! {
203
207
"full_error_message" => Value :: text( error. to_string( ) ) ,
204
208
[ if let Some ( v) = & error. error. message] "short_error_message" => Value :: text( v. to_string( ) ) ,
209
+ [ if restartable] "restart_block_icon" => Value :: icon( "refresh" ) . with_instance( RESTART_BLOCK_BTN ) ,
205
210
} ) ;
206
211
self . state = BlockState :: Error { widget } ;
207
212
}
@@ -326,8 +331,12 @@ impl BarState {
326
331
self . fullscreen_block = None ;
327
332
}
328
333
}
329
- RequestCmd :: SetError ( error) => {
330
- block. set_error ( self . fullscreen_block == Some ( request. block_id ) , error) ;
334
+ RequestCmd :: SetError { error, restartable } => {
335
+ block. set_error_with_restartable (
336
+ self . fullscreen_block == Some ( request. block_id ) ,
337
+ restartable,
338
+ error,
339
+ ) ;
331
340
}
332
341
RequestCmd :: SetDefaultActions ( actions) => {
333
342
block. default_actions = actions;
@@ -415,16 +424,22 @@ impl BarState {
415
424
}
416
425
}
417
426
BlockState :: Error { widget } => {
418
- if self . fullscreen_block == Some ( event. id) {
419
- self . fullscreen_block = None ;
420
- widget. set_format( block. error_format. clone( ) ) ;
427
+ if let Some ( ( _, _, action) ) = block. default_actions
428
+ . iter( )
429
+ . find( |( btn, widget, _) | * btn == event. button && * widget == event. instance. as_deref( ) ) {
430
+ block. send_action( Cow :: Borrowed ( action) ) ;
421
431
} else {
422
- self . fullscreen_block = Some ( event. id) ;
423
- widget. set_format( block. error_fullscreen_format. clone( ) ) ;
432
+ if self . fullscreen_block == Some ( event. id) {
433
+ self . fullscreen_block = None ;
434
+ widget. set_format( block. error_format. clone( ) ) ;
435
+ } else {
436
+ self . fullscreen_block = Some ( event. id) ;
437
+ widget. set_format( block. error_fullscreen_format. clone( ) ) ;
438
+ }
439
+ block. notify_intervals( & self . widget_updates_sender) ;
440
+ self . render_block( event. id) ?;
441
+ self . render( ) ;
424
442
}
425
- block. notify_intervals( & self . widget_updates_sender) ;
426
- self . render_block( event. id) ?;
427
- self . render( ) ;
428
443
}
429
444
}
430
445
}
0 commit comments