@@ -175,12 +175,26 @@ pub enum SelectedView {
175175 Help ,
176176}
177177
178+ #[ derive( PartialEq ) ]
179+ pub enum ListenStatus {
180+ Connected ,
181+ Listening ,
182+ Refusing ,
183+ }
184+
185+ impl ListenStatus {
186+ pub fn is_connected ( & self ) -> bool {
187+ * self == ListenStatus :: Connected
188+ }
189+
190+ }
191+
178192pub struct App {
179193 receiver : Receiver < AppEvent > ,
180194 quit : bool ,
181195 sender : Sender < AppEvent > ,
182196
183- pub is_connected : bool ,
197+ pub listening_status : ListenStatus ,
184198 pub notification : Notification ,
185199 pub config : Config ,
186200
@@ -212,7 +226,7 @@ impl App {
212226 pub fn new ( config : Config , receiver : Receiver < AppEvent > , sender : Sender < AppEvent > ) -> App {
213227 let client = Arc :: new ( Mutex :: new ( DbgpClient :: new ( None ) ) ) ;
214228 App {
215- is_connected : false ,
229+ listening_status : ListenStatus :: Listening ,
216230 config,
217231 input_plurality : vec ! [ ] ,
218232 notification : Notification :: none ( ) ,
@@ -346,7 +360,7 @@ impl App {
346360 AppEvent :: HistoryNext => {
347361 for _ in 0 ..self . take_motion ( ) {
348362 self . history . next ( ) ;
349- if self . history . is_current ( ) && self . is_connected {
363+ if self . history . is_current ( ) && ( self . listening_status == ListenStatus :: Connected ) {
350364 self . sender
351365 . send ( AppEvent :: ChangeSessionViewMode ( SessionViewMode :: Current ) )
352366 . await ?;
@@ -358,26 +372,36 @@ impl App {
358372 self . history . previous ( ) ;
359373 }
360374 }
375+ AppEvent :: Listen => {
376+ self . listening_status = ListenStatus :: Listening ;
377+ self . view_current = SelectedView :: Listen ;
378+ self . session_view . mode = SessionViewMode :: Current ;
379+ self . notification = Notification :: info ( "listening for next connection" . to_string ( ) )
380+ } ,
361381 AppEvent :: ClientConnected ( s) => {
362- let filepath = {
363- let mut client = self . client . lock ( ) . await ;
364- let response = client. deref_mut ( ) . connect ( s) . await ?;
365- for ( feature, value) in [
366- ( "max_depth" , self . context_depth . to_string ( ) . as_str ( ) ) ,
367- ( "extended_properties" , "1" ) ,
368- ] {
369- info ! ( "setting feature {} to {:?}" , feature, value) ;
370- client. feature_set ( feature, value) . await ?;
371- }
372- response. fileuri . clone ( )
373- } ;
374- self . is_connected = true ;
375- self . reset ( ) ;
376-
377- let source = self . workspace . open ( filepath. clone ( ) ) . await ;
378- self . history = History :: default ( ) ;
379- self . history
380- . push ( HistoryEntry :: initial ( filepath. clone ( ) , source. text . clone ( ) ) ) ;
382+ if self . listening_status != ListenStatus :: Listening {
383+ self . notification = Notification :: warning ( "refused incoming connection" . to_string ( ) ) ;
384+ } else {
385+ let filepath = {
386+ let mut client = self . client . lock ( ) . await ;
387+ let response = client. deref_mut ( ) . connect ( s) . await ?;
388+ for ( feature, value) in [
389+ ( "max_depth" , self . context_depth . to_string ( ) . as_str ( ) ) ,
390+ ( "extended_properties" , "1" ) ,
391+ ] {
392+ info ! ( "setting feature {} to {:?}" , feature, value) ;
393+ client. feature_set ( feature, value) . await ?;
394+ }
395+ response. fileuri . clone ( )
396+ } ;
397+ self . listening_status = ListenStatus :: Connected ;
398+ self . reset ( ) ;
399+
400+ let source = self . workspace . open ( filepath. clone ( ) ) . await ;
401+ self . history = History :: default ( ) ;
402+ self . history
403+ . push ( HistoryEntry :: initial ( filepath. clone ( ) , source. text . clone ( ) ) ) ;
404+ }
381405 }
382406 AppEvent :: Snapshot ( ) => {
383407 self . snapshot ( ) . await ?;
@@ -445,7 +469,7 @@ impl App {
445469 }
446470 AppEvent :: Disconnect => {
447471 let _ = self . client . lock ( ) . await . deref_mut ( ) . disonnect ( ) . await ;
448- self . is_connected = false ;
472+ self . listening_status = ListenStatus :: Refusing ;
449473 self . sender
450474 . send ( AppEvent :: ChangeSessionViewMode ( SessionViewMode :: History ) )
451475 . await ?;
@@ -575,7 +599,7 @@ impl App {
575599 let line_no = frame. line ;
576600 let context = {
577601 match ( level as u16 ) < self . stack_max_context_fetch {
578- true => Some ( self . client . lock ( ) . await . deref_mut ( ) . context_get ( level as u16 ) . await . unwrap ( ) ) ,
602+ true => Some ( self . client . lock ( ) . await . deref_mut ( ) . context_get ( level as u16 ) . await ? ) ,
579603 false => None ,
580604 }
581605 } ;
0 commit comments